19 #include <linux/module.h>
21 #include <linux/slab.h>
25 #include <linux/kernel.h>
31 #define CARDNAME "swim"
42 #define DRIVER_VERSION "Version 0.2 (2008-10-30)"
44 #define REG(x) unsigned char x, x ## _pad[0x200 - 1];
66 #define swim_write(base, reg, v) out_8(&(base)->write_##reg, (v))
67 #define swim_read(base, reg) in_8(&(base)->read_##reg)
90 #define iwm_write(base, reg, v) out_8(&(base)->reg, (v))
91 #define iwm_read(base, reg) in_8(&(base)->reg)
95 #define SEEK_POSITIVE 0x070
96 #define SEEK_NEGATIVE 0x074
98 #define MOTOR_ON 0x072
99 #define MOTOR_OFF 0x076
108 #define CA_MASK 0x077
112 #define READ_DATA_0 0x074
113 #define TWOMEG_DRIVE 0x075
114 #define SINGLE_SIDED 0x076
115 #define DRIVE_PRESENT 0x077
116 #define DISK_IN 0x170
117 #define WRITE_PROT 0x171
118 #define TRACK_ZERO 0x172
120 #define READ_DATA_1 0x174
121 #define MFM_MODE 0x175
122 #define SEEK_COMPLETE 0x176
123 #define ONEMEG_MEDIA 0x177
127 #define MARK_BYTE 0x01
128 #define CRC_ZERO 0x02
133 #define DAT2BYTE 0x40
134 #define DAT1BYTE 0x80
138 #define S_INV_WDATA 0x01
139 #define S_3_5_SELECT 0x02
141 #define S_FCLK_DIV2 0x08
142 #define S_ERROR_CORR 0x10
143 #define S_IBM_DRIVE 0x20
144 #define S_GCR_WRITE 0x40
145 #define S_TIMEOUT 0x80
153 #define WRITE_MODE 0x10
209 #define FD_MAX_UNIT 2
222 unsigned char *
data);
250 static inline int get_swim_mode(
struct swim __iomem *base)
272 static inline void swim_select(
struct swim __iomem *base,
int sel)
287 swim_select(base, action);
297 static inline int swim_readbit(
struct swim __iomem *base,
int bit)
301 swim_select(base, bit);
307 return (stat &
SENSE) == 0;
310 static inline void swim_drive(
struct swim __iomem *base,
322 static inline void swim_motor(
struct swim __iomem *base,
330 for (i = 0; i < 2*
HZ; i++) {
331 swim_select(base,
RELAX);
337 }
else if (action ==
OFF) {
339 swim_select(base,
RELAX);
343 static inline void swim_eject(
struct swim __iomem *base)
347 swim_action(base,
EJECT);
349 for (i = 0; i < 2*
HZ; i++) {
350 swim_select(base,
RELAX);
351 if (!swim_readbit(base,
DISK_IN))
356 swim_select(base,
RELAX);
369 static inline int swim_step(
struct swim __iomem *base)
373 swim_action(base,
STEP);
375 for (wait = 0; wait <
HZ; wait++) {
380 swim_select(base,
RELAX);
381 if (!swim_readbit(base,
STEP))
387 static inline int swim_track00(
struct swim __iomem *base)
393 for (
try = 0;
try < 100;
try++) {
395 swim_select(base,
RELAX);
420 for ( ; step > 0; step--) {
433 ret = swim_seek(base, track - fs->
track);
450 swim_motor(base,
OFF);
459 static inline int swim_read_sector(
struct floppy_state *fs,
469 swim_track(fs, track);
472 swim_head(base, side);
476 for (i = 0; i < 36; i++) {
478 if (!ret && (
header.sector == sector)) {
490 (
header.sector != sector))
497 int req_sector,
int sectors_nb,
498 unsigned char *buffer)
507 for (i = req_sector; i < req_sector + sectors_nb; i++) {
516 ret = swim_read_sector(fs, side, track, sector,
520 }
while (ret != 512);
537 fs = req->rq_disk->private_data;
545 switch (rq_data_dir(req)) {
550 err = floppy_read_sectors(fs, blk_rq_pos(req),
551 blk_rq_cur_sectors(req),
567 { 0, 0, 0, 0, 0, 0x00, 0x00, 0x00, 0x00,
NULL },
568 { 720, 9, 1, 80, 0, 0x2A, 0x02, 0xDF, 0x50,
NULL },
569 { 1440, 9, 2, 80, 0, 0x2A, 0x02, 0xDF, 0x50,
NULL },
570 { 2880, 18, 2, 80, 0, 0x1B, 0x00, 0xCF, 0x6C,
NULL },
580 *g = &floppy_type[
type];
582 *g = &floppy_type[3];
584 *g = &floppy_type[2];
586 *g = &floppy_type[1];
595 if (swim_readbit(base,
DISK_IN)) {
601 if (swim_track00(base))
603 "SWIM: cannot move floppy head to track 0\n");
607 get_floppy_geometry(fs, 0, &g);
626 if (mode & FMODE_EXCL)
634 swim_motor(base,
ON);
635 swim_action(base,
SETMFM);
661 swim_motor(base,
OFF);
670 ret = floppy_open(bdev, mode);
676 static int floppy_release(
struct gendisk *disk,
fmode_t mode)
688 swim_motor(base,
OFF);
695 unsigned int cmd,
unsigned long param)
708 err = floppy_eject(fs);
713 if (
copy_to_user((
void __user *) param, (
void *) &floppy_type,
732 ret = get_floppy_geometry(fs, 0, &g);
743 static unsigned int floppy_check_events(
struct gendisk *disk,
744 unsigned int clearing)
748 return fs->
ejected ? DISK_EVENT_MEDIA_CHANGE : 0;
751 static int floppy_revalidate(
struct gendisk *disk)
762 swim_motor(base,
OFF);
769 static const struct block_device_operations floppy_fops = {
771 .open = floppy_unlocked_open,
772 .release = floppy_release,
773 .ioctl = floppy_ioctl,
774 .getgeo = floppy_getgeo,
775 .check_events = floppy_check_events,
776 .revalidate_disk = floppy_revalidate,
782 int drive = (*part & 3);
799 swim_drive(base, location);
801 swim_motor(base,
OFF);
841 if (swd->
unit[drive].disk ==
NULL) {
855 swd->
unit[drive].disk->flags = GENHD_FL_REMOVABLE;
857 swd->
unit[drive].disk->first_minor = drive;
858 sprintf(swd->
unit[drive].disk->disk_name,
"fd%d", drive);
859 swd->
unit[drive].disk->fops = &floppy_fops;
860 swd->
unit[drive].disk->private_data = &swd->
unit[drive];
861 swd->
unit[drive].disk->queue = swd->
queue;
862 set_capacity(swd->
unit[drive].disk, 2880);
867 floppy_find,
NULL, swd);
904 set_swim_mode(swim_base, 1);
905 if (!get_swim_mode(swim_base)) {
918 platform_set_drvdata(dev, swd);
920 swd->
base = swim_base;
922 ret = swim_floppy_init(swd);
929 platform_set_drvdata(dev,
NULL);
941 struct swim_priv *swd = platform_get_drvdata(dev);
959 floppy_eject(&swd->
unit[drive]);
967 platform_set_drvdata(dev,
NULL);
982 static int __init swim_init(
void)
990 static void __exit swim_exit(
void)