Lines Matching +full:motor +full:- +full:driver
1 // SPDX-License-Identifier: GPL-2.0-only
6 * Portions of this driver are based on code contributed by Brad Pepers
9 * - now no bugs(?) any more for both HD & DD
10 * - added support for 40 Track 5.25" drives, 80-track hopefully behaves
11 * like 3.5" dd (no way to test - are there any 5.25" drives out there
13 * - wrote formatting routine (maybe dirty, but works)
15 * june/july 1995 added ms-dos support by Joerg Dorchain
17 * - currently only 9 and 18 sector disks
19 * - fixed a bug with the internal trackbuffer when using multiple
21 * - made formatting a bit safer
22 * - added command line and machine based default for "silent" df0
25 * - works but I think it's inefficient. (look in redo_fd_request)
29 * - usage ioctl(d, RAW_TRACK, ptr); the raw track buffer (MFM-encoded data
31 * done - 30K is currently sufficient). return the actual size of the
33 * - replaced udelays() by a timer (CIAA timer B) for the waits
37 * - both got broken the first time I tampered with the driver :-(
38 * - still not safe, but better than before
41 * - Minor changes to accept the kdev_t.
42 * - Replaced some more udelays with ms_delays. Udelay is just a loop,
44 * processor :-(
45 * - The driver could use a major cleanup because of the new
51 * - Fixed Bug accessing multiple disks
52 * - some code cleanup
53 * - added trackbuffer for each drive to speed things up
54 * - fixed some race conditions (who finds the next may send it to me ;-)
67 #include <linux/blk-mq.h>
101 #define DSKMOTOR (0x1<<7) /* motor on when low */
118 /* bits 7-0 are data */
193 int track; /* current track (-1 == unknown) */
199 int disk; /* disk in drive (-1 == unknown) */
200 int motor; /* true when motor is at speed */ member
212 #define FD_ERROR -1 /* general error (seek, read, write, etc) */
216 #define FD_NOTREADY 4 /* unit is not ready (motor not on/no disk) */
227 #define FD_DD_3 0xffffffff /* double-density 3.5" (880K) drive */
228 #define FD_HD_3 0x55555555 /* high-density 3.5" (1760K) drive */
229 #define FD_DD_5 0xaaaaaaaa /* double-density 5.25" (440K) drive */
235 MODULE_DESCRIPTION("Amiga floppy driver");
261 { "MS-Dos", 9, dos_read, dos_write}
276 static volatile int fdc_busy = -1;
282 static volatile int selected = -1; /* currently selected drive */
300 /* MS-Dos MFM Coding tables (should go quick and easy) */
313 * max X times - some types of errors increase the errorcount by 2 or
347 ticks = MS_TICKS*ms-1; in ms_delay()
350 ciaa.crb=0x19; /*count eclock, force load, one-shoot, start */ in ms_delay()
387 fdc_nested--; in rel_fdc()
389 fdc_busy = -1; in rel_fdc()
409 if (unit[drive].motor == 1) in fd_select()
435 selected = -1; in fd_deselect()
448 if (!(ciaa.pra & DSKRDY) || --on_attempts == 0) { in motor_on_callback()
462 if (!unit[nr].motor) { in fd_motor_on()
463 unit[nr].motor = 1; in fd_motor_on()
475 on_attempts = -1; in fd_motor_on()
477 printk (KERN_ERR "motor_on failed, turning motor off\n"); in fd_motor_on()
481 …printk (KERN_WARNING "DSKRDY not set after 1.5 seconds - assuming drive is spinning notwithstandin… in fd_motor_on()
490 unsigned long drive = ((unsigned long)timer - in fd_motor_off()
497 timer->expires = jiffies + 1; in fd_motor_off()
501 unit[drive].motor = 0; in fd_motor_off()
529 for (n = unit[drive].type->tracks/2; n != 0; --n) { in fd_calibrate()
537 ms_delay(unit[drive].type->step_delay); in fd_calibrate()
539 ms_delay (unit[drive].type->settle_time); in fd_calibrate()
541 n = unit[drive].type->tracks + 20; in fd_calibrate()
548 ms_delay(unit[drive].type->step_delay + 1); in fd_calibrate()
551 if (--n == 0) { in fd_calibrate()
552 printk (KERN_ERR "fd%d: calibrate failed, turning motor off\n", drive); in fd_calibrate()
554 unit[drive].track = -1; in fd_calibrate()
560 ms_delay(unit[drive].type->settle_time); in fd_calibrate()
591 cnt = unit[drive].track/2 - track/2; in fd_seek()
597 cnt = - cnt; in fd_seek()
602 ms_delay (unit[drive].type->side_time); in fd_seek()
615 ms_delay (unit[drive].type->step_delay); in fd_seek()
616 } while (--cnt != 0); in fd_seek()
617 ms_delay (unit[drive].type->settle_time); in fd_seek()
652 id |= (ciaa.pra & DSKRDY) ? 0 : 1; /* cia regs are low-active! */ in fd_get_drive_id()
706 custom.dsklen = unit[drive].type->read_size/sizeof(short) | DSKLEN_DMAEN; in raw_read()
707 custom.dsklen = unit[drive].type->read_size/sizeof(short) | DSKLEN_DMAEN; in raw_read()
734 if ((ulong)unit[drive].track >= unit[drive].type->precomp2) in raw_write()
736 else if ((ulong)unit[drive].track >= unit[drive].type->precomp1) in raw_write()
742 custom.dsklen = unit[drive].type->write_size/sizeof(short) | DSKLEN_DMAEN|DSKLEN_WRITE; in raw_write()
743 custom.dsklen = unit[drive].type->write_size/sizeof(short) | DSKLEN_DMAEN|DSKLEN_WRITE; in raw_write()
777 * (Add other formats here ;-))
799 while (len-- > 0) in checksum()
821 } while (--len != 0); in decode()
846 end = raw + unit[drive].type->read_size; in amiga_read()
848 for (scnt = 0;scnt < unit[drive].dtype->sects * unit[drive].type->sect_mult; scnt++) { in amiga_read()
859 (char *)&hdr.hdrchk-(char *)&hdr); in amiga_read()
908 if (*(dest - 1) & 0x00000001) in encode()
938 *raw = (raw[-1]&1) ? 0x2AAAAAAA : 0xAAAAAAAA; in putsec()
945 hdr.ord = unit[disk].dtype->sects * unit[disk].type->sect_mult - cnt; in putsec()
949 (char *)&hdr.hdrchk-(char *)&hdr); in putsec()
973 for (cnt = 0; cnt < 415 * unit[disk].type->sect_mult; cnt++) in amiga_write()
977 for (cnt = 0; cnt < unit[disk].dtype->sects * unit[disk].type->sect_mult; cnt++) in amiga_write()
979 *(ushort *)ptr = (ptr[-1]&1) ? 0x2AA8 : 0xAAA8; in amiga_write()
984 unsigned char track, /* 0-80 */
985 side, /* 0-1 */
986 sec, /* 0-...*/
992 unsigned char gap1[22]; /* for longword-alignedness (0x4e) */
995 /* crc routines are borrowed from the messydos-handler */
997 /* excerpt from the messydos-device
999 ; the SYNC mark (3 * $a1) and the 'ID/DATA - Address Mark' ($fe/$fb).
1007 ; polynomials. We calculate with these polynomials in modulo-2
1009 ; exclusive-or. Now, we modify our data (a very long polynomial) in
1010 ; such a way that it becomes divisible by the CCITT-standard 16-bit
1090 /* look at the asm-code - what looks in C a bit strange is almost as good as handmade */ in dos_crc()
1099 for (i=data_d3; i>=0; i--) { in dos_crc()
1109 return dos_crc(&(hdr->track), 0xb2, 0x30, 3); /* precomputed magic */ in dos_hdr_crc()
1161 end = raw + unit[drive].type->read_size; in dos_read()
1163 for (scnt=0; scnt < unit[drive].dtype->sects * unit[drive].type->sect_mult; scnt++) { in dos_read()
1164 do { /* search for the right sync of each sec-hdr */ in dos_read()
1189 if (hdr.track != unit[drive].track/unit[drive].type->heads) { in dos_read()
1192 unit[drive].track/unit[drive].type->heads); in dos_read()
1196 if (hdr.side != unit[drive].track%unit[drive].type->heads) { in dos_read()
1199 unit[drive].track%unit[drive].type->heads); in dos_read()
1229 …raw = dos_decode((unsigned char *)(unit[drive].trackbuf + (hdr.sec - 1) * 512), (ushort *) raw, 51… in dos_read()
1231 crc = dos_data_crc(unit[drive].trackbuf + (hdr.sec - 1) * 512); in dos_read()
1238 ((ulong *)(unit[drive].trackbuf+(hdr.sec-1)*512))[0], in dos_read()
1239 ((ulong *)(unit[drive].trackbuf+(hdr.sec-1)*512))[1], in dos_read()
1240 ((ulong *)(unit[drive].trackbuf+(hdr.sec-1)*512))[2], in dos_read()
1241 ((ulong *)(unit[drive].trackbuf+(hdr.sec-1)*512))[3]); in dos_read()
1267 *dest|=((dest[-1]&1)||(*dest&0x4000))? 0: 0x8000; in dos_encode_block()
1289 hdr.track=unit[drive].track/unit[drive].type->heads; in ms_putsec()
1290 hdr.side=unit[drive].track%unit[drive].type->heads; in ms_putsec()
1311 /*data crc + jd's special gap (long words :-/) */ in ms_putsec()
1335 if (unit[disk].type->sect_mult==2) /* check for HD-Disks */ in dos_write()
1350 for(cnt = 0; cnt < unit[disk].dtype->sects * unit[disk].type->sect_mult; cnt++) in dos_write()
1363 /* FIXME: this assumes the drive is still spinning -
1368 unsigned long nr = ((unsigned long)timer - in flush_track_callback()
1381 (*unit[nr].dtype->write_fkt)(nr); in flush_track_callback()
1406 (*unit[nr].dtype->write_fkt)(nr); in non_int_flush_track()
1434 return -1; in get_track()
1444 return -1; in get_track()
1446 error = (*unit[drive].dtype->read_fkt)(drive); in get_track()
1452 unit[drive].track = -1; in get_track()
1456 return -1; in get_track()
1462 int drive = floppy - unit; in amiflop_rw_cur_segment()
1473 track = block / (floppy->dtype->sects * floppy->type->sect_mult); in amiflop_rw_cur_segment()
1474 sector = block % (floppy->dtype->sects * floppy->type->sect_mult); in amiflop_rw_cur_segment()
1475 data = bio_data(rq->bio) + 512 * cnt; in amiflop_rw_cur_segment()
1481 if (get_track(drive, track) == -1) in amiflop_rw_cur_segment()
1485 memcpy(data, floppy->trackbuf + sector * 512, 512); in amiflop_rw_cur_segment()
1487 memcpy(floppy->trackbuf + sector * 512, data, 512); in amiflop_rw_cur_segment()
1496 floppy->dirty = 1; in amiflop_rw_cur_segment()
1508 struct request *rq = bd->rq; in amiflop_queue_rq()
1509 struct amiga_floppy_struct *floppy = rq->q->disk->private_data; in amiflop_queue_rq()
1528 int drive = MINOR(bdev->bd_dev) & 3; in fd_getgeo()
1530 geo->heads = unit[drive].type->heads; in fd_getgeo()
1531 geo->sectors = unit[drive].dtype->sects * unit[drive].type->sect_mult; in fd_getgeo()
1532 geo->cylinders = unit[drive].type->tracks; in fd_getgeo()
1539 struct amiga_floppy_struct *p = bdev->bd_disk->private_data; in fd_locked_ioctl()
1540 int drive = p - unit; in fd_locked_ioctl()
1549 return -EBUSY; in fd_locked_ioctl()
1553 return -ENODEV; in fd_locked_ioctl()
1557 return -ENXIO; in fd_locked_ioctl()
1563 if (param < p->type->tracks * p->type->heads) in fd_locked_ioctl()
1567 memset(p->trackbuf, FD_FILL_BYTE, in fd_locked_ioctl()
1568 p->dtype->sects * p->type->sect_mult * 512); in fd_locked_ioctl()
1575 return -EINVAL; in fd_locked_ioctl()
1583 getprm.track=p->type->tracks; in fd_locked_ioctl()
1584 getprm.head=p->type->heads; in fd_locked_ioctl()
1585 getprm.sect=p->dtype->sects * p->type->sect_mult; in fd_locked_ioctl()
1586 getprm.size=p->blocks; in fd_locked_ioctl()
1588 return -EFAULT; in fd_locked_ioctl()
1592 return -EINVAL; in fd_locked_ioctl()
1599 if (copy_to_user(argp, raw_buf, p->type->read_size)) in fd_locked_ioctl()
1600 return -EFAULT; in fd_locked_ioctl()
1602 return p->type->read_size; in fd_locked_ioctl()
1605 return -ENOSYS; in fd_locked_ioctl()
1639 unit[drive].type = &drive_types[num_dr_types-1]; /* FD_NODRIVE */ in fd_probe()
1644 unit[drive].track = -1; in fd_probe()
1646 unit[drive].disk = -1; in fd_probe()
1647 unit[drive].motor = 0; in fd_probe()
1649 unit[drive].status = -1; in fd_probe()
1659 int drive = disk->first_minor & 3; in floppy_open()
1660 int system = (disk->first_minor & 4) >> 2; in floppy_open()
1669 return -EBUSY; in floppy_open()
1672 if (unit[drive].type->code == FD_NODRIVE) { in floppy_open()
1674 return -ENXIO; in floppy_open()
1689 return -EROFS; in floppy_open()
1699 unit[drive].blocks=unit[drive].type->heads*unit[drive].type->tracks* in floppy_open()
1700 data_types[system].sects*unit[drive].type->sect_mult; in floppy_open()
1703 printk(KERN_INFO "fd%d: accessing %s-disk with %s-layout\n",drive, in floppy_open()
1704 unit[drive].type->name, data_types[system].name); in floppy_open()
1712 struct amiga_floppy_struct *p = disk->private_data; in floppy_release()
1713 int drive = p - unit; in floppy_release()
1721 if (!fd_ref[drive]--) { in floppy_release()
1733 * here, sleep etc. Note that floppy-on tries to set current_DOR to point
1739 struct amiga_floppy_struct *p = disk->private_data; in amiga_check_events()
1740 int drive = p - unit; in amiga_check_events()
1745 changed = first_time--; in amiga_check_events()
1756 p->track = -1; in amiga_check_events()
1757 p->dirty = 0; in amiga_check_events()
1790 disk->major = FLOPPY_MAJOR; in fd_alloc_disk()
1791 disk->first_minor = drive + system; in fd_alloc_disk()
1792 disk->minors = 1; in fd_alloc_disk()
1793 disk->fops = &floppy_fops; in fd_alloc_disk()
1794 disk->flags |= GENHD_FL_NO_PART; in fd_alloc_disk()
1795 disk->events = DISK_EVENT_MEDIA_CHANGE; in fd_alloc_disk()
1797 sprintf(disk->disk_name, "fd%d_msdos", drive); in fd_alloc_disk()
1799 sprintf(disk->disk_name, "fd%d", drive); in fd_alloc_disk()
1800 disk->private_data = &unit[drive]; in fd_alloc_disk()
1837 unit[drive].type->code = FD_NODRIVE; in fd_alloc_drive()
1838 return -ENOMEM; in fd_alloc_drive()
1850 if (unit[drive].type->code == FD_NODRIVE) in fd_probe_drives()
1867 return -ENOMEM; in fd_probe_drives()
1875 return -EBUSY; in amiga_floppy_probe()
1877 ret = -ENOMEM; in amiga_floppy_probe()
1884 ret = -EBUSY; in amiga_floppy_probe()
1895 ret = -ENODEV; in amiga_floppy_probe()
1908 unit[i].track = -1; in amiga_floppy_probe()
1923 ciaa.crb = 8; /* one-shot, stop */ in amiga_floppy_probe()
1938 .driver = {
1939 .name = "amiga-floppy",
1966 MODULE_ALIAS("platform:amiga-floppy");