Lines Matching defs:fdc

264 void fd_set_motor(struct fdc_softc *fdc, int reset);
267 int fdcresult(struct fdc_softc *fdc);
268 void fdcstart(struct fdc_softc *fdc);
271 void fdcretry(struct fdc_softc *fdc);
289 * the drive). If `fdc' is not NULL, the drive was found but was not
295 fdprint(void *aux, const char *fdc)
299 if (!fdc)
307 struct fdc_softc *fdc = device_private(self);
309 mutex_enter(&fdc->sc_mtx);
310 (void)fdcintr1(fdc);
311 mutex_exit(&fdc->sc_mtx);
318 struct fdc_softc *fdc = device_private(self);
322 mutex_enter(&fdc->sc_mtx);
323 while (fdc->sc_state != DEVIDLE)
324 cv_wait(&fdc->sc_cv, &fdc->sc_mtx);
326 if ((fd = fdc->sc_fd[drive]) == NULL)
330 fd_set_motor(fdc, 0);
331 mutex_exit(&fdc->sc_mtx);
338 struct fdc_softc *fdc = device_private(self);
342 KASSERT(fdc->sc_fd[drive] == fd); /* but the kid is not my son */
343 fdc->sc_fd[drive] = NULL;
350 struct fdc_softc *fdc = device_private(self);
357 isa_dmamap_destroy(fdc->sc_ic, fdc->sc_drq);
358 isa_drq_free(fdc->sc_ic, fdc->sc_drq);
360 callout_destroy(&fdc->sc_intr_ch);
361 callout_destroy(&fdc->sc_timo_ch);
363 cv_destroy(&fdc->sc_cv);
364 mutex_destroy(&fdc->sc_mtx);
370 fdcattach(struct fdc_softc *fdc)
372 mutex_init(&fdc->sc_mtx, MUTEX_DEFAULT, IPL_BIO);
373 cv_init(&fdc->sc_cv, "fdcwake");
374 callout_init(&fdc->sc_timo_ch, 0);
375 callout_init(&fdc->sc_intr_ch, 0);
377 fdc->sc_state = DEVIDLE;
378 TAILQ_INIT(&fdc->sc_drives);
380 fdc->sc_maxiosize = isa_dmamaxsize(fdc->sc_ic, fdc->sc_drq);
382 if (isa_drq_alloc(fdc->sc_ic, fdc->sc_drq) != 0) {
383 aprint_normal_dev(fdc->sc_dev, "can't reserve drq %d\n",
384 fdc->sc_drq);
388 if (isa_dmamap_create(fdc->sc_ic, fdc->sc_drq, fdc->sc_maxiosize,
390 aprint_normal_dev(fdc->sc_dev, "can't set up ISA DMA map\n");
394 config_interrupts(fdc->sc_dev, fdcfinishattach);
396 if (!pmf_device_register(fdc->sc_dev, fdcsuspend, fdcresume)) {
397 aprint_error_dev(fdc->sc_dev,
405 struct fdc_softc *fdc = device_private(self);
406 bus_space_tag_t iot = fdc->sc_iot;
407 bus_space_handle_t ioh = fdc->sc_ioh;
422 aprint_normal_dev(fdc->sc_dev, "can't reset controller\n");
434 if (device_unit(fdc->sc_dev) == 0) {
436 fdc->sc_known = 1;
437 fdc->sc_knownfds[0] = fd_nvtotype(device_xname(fdc->sc_dev),
439 if (fdc->sc_knownfds[0] != NULL)
440 fdc->sc_present |= 1;
441 fdc->sc_knownfds[1] = fd_nvtotype(device_xname(fdc->sc_dev),
443 if (fdc->sc_knownfds[1] != NULL)
444 fdc->sc_present |= 2;
449 fdc->sc_state = PROBING;
451 if (fdc->sc_known) {
452 if (fdc->sc_present & (1 << fa.fa_drive)) {
453 fa.fa_deftype = fdc->sc_knownfds[fa.fa_drive];
454 config_found(fdc->sc_dev, (void *)&fa,
463 /* Atari also configures ISA fdc(4) as "fdcisa" */
464 config_found(fdc->sc_dev, &fa, fdprint,
472 config_found(fdc->sc_dev, &fa, fdprint,
473 CFARGS(.iattr = "fdc"));
477 fdc->sc_state = DEVIDLE;
483 struct fdc_softc *fdc = device_private(parent);
487 bus_space_tag_t iot = fdc->sc_iot;
488 bus_space_handle_t ioh = fdc->sc_ioh;
503 if (fdc->sc_known)
506 mutex_enter(&fdc->sc_mtx);
510 (void) fdcresult(fdc);
516 (void) cv_timedwait(&fdc->sc_cv, &fdc->sc_mtx, hz / 4);
521 if (cv_timedwait(&fdc->sc_cv, &fdc->sc_mtx, 2 * hz) != EWOULDBLOCK){
528 n = fdcresult(fdc);
534 printf(" %x", fdc->sc_status[i]);
540 mutex_exit(&fdc->sc_mtx);
543 if (n != 2 || (fdc->sc_status[1] != 0))
546 if (n != 2 || (fdc->sc_status[0] & 0xf8) != 0x20)
559 struct fdc_softc *fdc = device_private(parent);
582 fdc->sc_fd[drive] = fd;
652 fd_nvtotype(const char *fdc, int nvraminfo, int drive)
683 fdc, drive, type);
703 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dev));
746 mutex_enter(&fdc->sc_mtx);
753 if (fdc->sc_state == DEVIDLE) {
755 fdcstart(fdc);
759 mutex_exit(&fdc->sc_mtx);
771 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dev));
772 int active = !TAILQ_EMPTY(&fdc->sc_drives);
774 KASSERT(mutex_owned(&fdc->sc_mtx));
777 TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
781 fdcstart(fdc);
787 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dev));
798 TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
800 TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
812 fdc->sc_state = DEVIDLE;
830 fd_set_motor(struct fdc_softc *fdc, int reset)
836 if ((fd = TAILQ_FIRST(&fdc->sc_drives)) != NULL)
843 if ((fd = fdc->sc_fd[n]) && (fd->sc_flags & FD_MOTOR))
845 bus_space_write_1(fdc->sc_iot, fdc->sc_ioh, fdout, status);
852 struct fdc_softc *fdc;
854 fdc = device_private(device_parent(fd->sc_dev));
856 mutex_enter(&fdc->sc_mtx);
858 fd_set_motor(fdc, 0);
859 mutex_exit(&fdc->sc_mtx);
866 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dev));
868 mutex_enter(&fdc->sc_mtx);
870 if (TAILQ_FIRST(&fdc->sc_drives) == fd && fdc->sc_state == MOTORWAIT)
871 (void)fdcintr1(fdc);
872 mutex_exit(&fdc->sc_mtx);
876 fdcresult(struct fdc_softc *fdc)
878 bus_space_tag_t iot = fdc->sc_iot;
879 bus_space_handle_t ioh = fdc->sc_ioh;
890 if (n >= sizeof(fdc->sc_status)) {
894 fdc->sc_status[n++] =
961 fdcstart(struct fdc_softc *fdc)
964 KASSERT(mutex_owned(&fdc->sc_mtx));
966 if (!device_is_active(fdc->sc_dev))
972 if (fdc->sc_state != DEVIDLE) {
977 (void)fdcintr1(fdc);
981 fdcpstatus(int n, struct fdc_softc *fdc)
990 snprintb(bits, sizeof(bits), NE7_ST0BITS, fdc->sc_status[0]);
991 printf(" (st0 %s cyl %d)\n", bits, fdc->sc_status[1]);
994 snprintb(bits, sizeof(bits), NE7_ST0BITS, fdc->sc_status[0]);
996 snprintb(bits, sizeof(bits), NE7_ST1BITS, fdc->sc_status[1]);
998 snprintb(bits, sizeof(bits), NE7_ST2BITS, fdc->sc_status[2]);
1001 fdc->sc_status[3], fdc->sc_status[4], fdc->sc_status[5]);
1014 struct fdc_softc *fdc = device_private(device_parent(dv));
1017 out_fdc(fdc->sc_iot, fdc->sc_ioh, NE7CMD_SENSEI);
1018 (void) fdcresult(fdc);
1021 fdcpstatus(n, fdc);
1030 struct fdc_softc *fdc = arg;
1031 struct fd_softc *fd = TAILQ_FIRST(&fdc->sc_drives);
1033 mutex_enter(&fdc->sc_mtx);
1035 log(LOG_ERR, "fdctimeout: state %d\n", fdc->sc_state);
1040 fdc->sc_state++;
1042 fdc->sc_state = DEVIDLE;
1044 (void)fdcintr1(fdc);
1045 mutex_exit(&fdc->sc_mtx);
1049 fdcintr1(struct fdc_softc *fdc)
1051 #define st0 fdc->sc_status[0]
1052 #define cyl fdc->sc_status[1]
1055 bus_space_tag_t iot = fdc->sc_iot;
1056 bus_space_handle_t ioh = fdc->sc_ioh;
1061 KASSERT(mutex_owned(&fdc->sc_mtx));
1062 if (fdc->sc_state == PROBING) {
1066 fdc->sc_probe++;
1072 fd = TAILQ_FIRST(&fdc->sc_drives);
1074 fdc->sc_state = DEVIDLE;
1082 TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
1090 switch (fdc->sc_state) {
1092 fdc->sc_errors = 0;
1098 fdc->sc_state = MOTORWAIT;
1103 struct fd_softc *ofd = fdc->sc_fd[fd->sc_drive ^ 1];
1109 fd_set_motor(fdc, 0);
1110 fdc->sc_state = MOTORWAIT;
1117 fd_set_motor(fdc, 0);
1134 fdc->sc_state = SEEKWAIT;
1139 callout_reset(&fdc->sc_timo_ch, 4 * hz, fdctimeout, fdc);
1151 nblks = uimin(nblks, fdc->sc_maxiosize / FDC_BSIZE);
1171 isa_dmastart(fdc->sc_ic, fdc->sc_drq,
1174 bus_space_write_1(iot, fdc->sc_fdctlioh, 0, type->rate);
1183 fdc->sc_errors = 4;
1184 fdcretry(fdc);
1206 fdc->sc_state = IOCOMPLETE;
1211 callout_reset(&fdc->sc_timo_ch, 2 * hz, fdctimeout, fdc);
1215 callout_stop(&fdc->sc_timo_ch);
1216 fdc->sc_state = SEEKCOMPLETE;
1218 callout_reset(&fdc->sc_intr_ch, hz / 50, fdcintrcb, fdc);
1227 if (fdcresult(fdc) != 2 || (st0 & 0xf8) != 0x20 ||
1232 fdcretry(fdc);
1239 isa_dmaabort(fdc->sc_ic, fdc->sc_drq);
1244 fdcretry(fdc);
1248 callout_stop(&fdc->sc_timo_ch);
1253 if (fdcresult(fdc) != 7 || (st0 & 0xf8) != 0) {
1254 isa_dmaabort(fdc->sc_ic, fdc->sc_drq);
1261 fdcretry(fdc);
1264 isa_dmadone(fdc->sc_ic, fdc->sc_drq);
1265 if (fdc->sc_errors) {
1269 fdc->sc_errors = 0;
1283 fd_set_motor(fdc, 1);
1285 fd_set_motor(fdc, 0);
1286 fdc->sc_state = RESETCOMPLETE;
1287 callout_reset(&fdc->sc_timo_ch, hz / 2, fdctimeout, fdc);
1291 callout_stop(&fdc->sc_timo_ch);
1295 (void) fdcresult(fdc);
1302 fdc->sc_state = RECALWAIT;
1303 callout_reset(&fdc->sc_timo_ch, 5 * hz, fdctimeout, fdc);
1307 callout_stop(&fdc->sc_timo_ch);
1308 fdc->sc_state = RECALCOMPLETE;
1310 callout_reset(&fdc->sc_intr_ch, hz / 30, fdcintrcb, fdc);
1315 if (fdcresult(fdc) != 2 || (st0 & 0xf8) != 0x20 || cyl != 0) {
1319 fdcretry(fdc);
1338 cv_signal(&fdc->sc_cv);
1352 struct fdc_softc *fdc = arg;
1354 mutex_enter(&fdc->sc_mtx);
1355 rc = fdcintr1(fdc);
1356 mutex_exit(&fdc->sc_mtx);
1361 fdcretry(struct fdc_softc *fdc)
1366 fd = TAILQ_FIRST(&fdc->sc_drives);
1371 switch (fdc->sc_errors) {
1374 fdc->sc_state = DOSEEK;
1379 fdc->sc_state = DORECAL;
1384 fdc->sc_state = DORESET;
1392 fdcpstatus(7, fdc);
1398 fdc->sc_errors++;