Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the SWIM3 (Super Woz Integrated Machine 3) |
| 3 | * floppy controller found on Power Macintoshes. |
| 4 | * |
| 5 | * Copyright (C) 1996 Paul Mackerras. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * TODO: |
| 15 | * handle 2 drives |
| 16 | * handle GCR disks |
| 17 | */ |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/stddef.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/sched.h> |
| 22 | #include <linux/timer.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/fd.h> |
| 25 | #include <linux/ioctl.h> |
| 26 | #include <linux/blkdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 28 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
Paul Mackerras | 515729e | 2005-11-08 12:15:36 +1100 | [diff] [blame] | 30 | #include <linux/spinlock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/io.h> |
| 32 | #include <asm/dbdma.h> |
| 33 | #include <asm/prom.h> |
| 34 | #include <asm/uaccess.h> |
| 35 | #include <asm/mediabay.h> |
| 36 | #include <asm/machdep.h> |
| 37 | #include <asm/pmac_feature.h> |
| 38 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 39 | static DEFINE_MUTEX(swim3_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | static struct request_queue *swim3_queue; |
| 41 | static struct gendisk *disks[2]; |
| 42 | static struct request *fd_req; |
| 43 | |
| 44 | #define MAX_FLOPPIES 2 |
| 45 | |
| 46 | enum swim_state { |
| 47 | idle, |
| 48 | locating, |
| 49 | seeking, |
| 50 | settling, |
| 51 | do_transfer, |
| 52 | jogging, |
| 53 | available, |
| 54 | revalidating, |
| 55 | ejecting |
| 56 | }; |
| 57 | |
| 58 | #define REG(x) unsigned char x; char x ## _pad[15]; |
| 59 | |
| 60 | /* |
| 61 | * The names for these registers mostly represent speculation on my part. |
| 62 | * It will be interesting to see how close they are to the names Apple uses. |
| 63 | */ |
| 64 | struct swim3 { |
| 65 | REG(data); |
| 66 | REG(timer); /* counts down at 1MHz */ |
| 67 | REG(error); |
| 68 | REG(mode); |
| 69 | REG(select); /* controls CA0, CA1, CA2 and LSTRB signals */ |
| 70 | REG(setup); |
| 71 | REG(control); /* writing bits clears them */ |
| 72 | REG(status); /* writing bits sets them in control */ |
| 73 | REG(intr); |
| 74 | REG(nseek); /* # tracks to seek */ |
| 75 | REG(ctrack); /* current track number */ |
| 76 | REG(csect); /* current sector number */ |
| 77 | REG(gap3); /* size of gap 3 in track format */ |
| 78 | REG(sector); /* sector # to read or write */ |
| 79 | REG(nsect); /* # sectors to read or write */ |
| 80 | REG(intr_enable); |
| 81 | }; |
| 82 | |
| 83 | #define control_bic control |
| 84 | #define control_bis status |
| 85 | |
| 86 | /* Bits in select register */ |
| 87 | #define CA_MASK 7 |
| 88 | #define LSTRB 8 |
| 89 | |
| 90 | /* Bits in control register */ |
| 91 | #define DO_SEEK 0x80 |
| 92 | #define FORMAT 0x40 |
| 93 | #define SELECT 0x20 |
| 94 | #define WRITE_SECTORS 0x10 |
| 95 | #define DO_ACTION 0x08 |
| 96 | #define DRIVE2_ENABLE 0x04 |
| 97 | #define DRIVE_ENABLE 0x02 |
| 98 | #define INTR_ENABLE 0x01 |
| 99 | |
| 100 | /* Bits in status register */ |
| 101 | #define FIFO_1BYTE 0x80 |
| 102 | #define FIFO_2BYTE 0x40 |
| 103 | #define ERROR 0x20 |
| 104 | #define DATA 0x08 |
| 105 | #define RDDATA 0x04 |
| 106 | #define INTR_PENDING 0x02 |
| 107 | #define MARK_BYTE 0x01 |
| 108 | |
| 109 | /* Bits in intr and intr_enable registers */ |
| 110 | #define ERROR_INTR 0x20 |
| 111 | #define DATA_CHANGED 0x10 |
| 112 | #define TRANSFER_DONE 0x08 |
| 113 | #define SEEN_SECTOR 0x04 |
| 114 | #define SEEK_DONE 0x02 |
| 115 | #define TIMER_DONE 0x01 |
| 116 | |
| 117 | /* Bits in error register */ |
| 118 | #define ERR_DATA_CRC 0x80 |
| 119 | #define ERR_ADDR_CRC 0x40 |
| 120 | #define ERR_OVERRUN 0x04 |
| 121 | #define ERR_UNDERRUN 0x01 |
| 122 | |
| 123 | /* Bits in setup register */ |
| 124 | #define S_SW_RESET 0x80 |
| 125 | #define S_GCR_WRITE 0x40 |
| 126 | #define S_IBM_DRIVE 0x20 |
| 127 | #define S_TEST_MODE 0x10 |
| 128 | #define S_FCLK_DIV2 0x08 |
| 129 | #define S_GCR 0x04 |
| 130 | #define S_COPY_PROT 0x02 |
| 131 | #define S_INV_WDATA 0x01 |
| 132 | |
| 133 | /* Select values for swim3_action */ |
| 134 | #define SEEK_POSITIVE 0 |
| 135 | #define SEEK_NEGATIVE 4 |
| 136 | #define STEP 1 |
| 137 | #define MOTOR_ON 2 |
| 138 | #define MOTOR_OFF 6 |
| 139 | #define INDEX 3 |
| 140 | #define EJECT 7 |
| 141 | #define SETMFM 9 |
| 142 | #define SETGCR 13 |
| 143 | |
| 144 | /* Select values for swim3_select and swim3_readbit */ |
| 145 | #define STEP_DIR 0 |
| 146 | #define STEPPING 1 |
| 147 | #define MOTOR_ON 2 |
| 148 | #define RELAX 3 /* also eject in progress */ |
| 149 | #define READ_DATA_0 4 |
| 150 | #define TWOMEG_DRIVE 5 |
| 151 | #define SINGLE_SIDED 6 /* drive or diskette is 4MB type? */ |
| 152 | #define DRIVE_PRESENT 7 |
| 153 | #define DISK_IN 8 |
| 154 | #define WRITE_PROT 9 |
| 155 | #define TRACK_ZERO 10 |
| 156 | #define TACHO 11 |
| 157 | #define READ_DATA_1 12 |
| 158 | #define MFM_MODE 13 |
| 159 | #define SEEK_COMPLETE 14 |
| 160 | #define ONEMEG_MEDIA 15 |
| 161 | |
| 162 | /* Definitions of values used in writing and formatting */ |
| 163 | #define DATA_ESCAPE 0x99 |
| 164 | #define GCR_SYNC_EXC 0x3f |
| 165 | #define GCR_SYNC_CONV 0x80 |
| 166 | #define GCR_FIRST_MARK 0xd5 |
| 167 | #define GCR_SECOND_MARK 0xaa |
| 168 | #define GCR_ADDR_MARK "\xd5\xaa\x00" |
| 169 | #define GCR_DATA_MARK "\xd5\xaa\x0b" |
| 170 | #define GCR_SLIP_BYTE "\x27\xaa" |
| 171 | #define GCR_SELF_SYNC "\x3f\xbf\x1e\x34\x3c\x3f" |
| 172 | |
| 173 | #define DATA_99 "\x99\x99" |
| 174 | #define MFM_ADDR_MARK "\x99\xa1\x99\xa1\x99\xa1\x99\xfe" |
| 175 | #define MFM_INDEX_MARK "\x99\xc2\x99\xc2\x99\xc2\x99\xfc" |
| 176 | #define MFM_GAP_LEN 12 |
| 177 | |
| 178 | struct floppy_state { |
| 179 | enum swim_state state; |
Paul Mackerras | 515729e | 2005-11-08 12:15:36 +1100 | [diff] [blame] | 180 | spinlock_t lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | struct swim3 __iomem *swim3; /* hardware registers */ |
| 182 | struct dbdma_regs __iomem *dma; /* DMA controller registers */ |
| 183 | int swim3_intr; /* interrupt number for SWIM3 */ |
| 184 | int dma_intr; /* interrupt number for DMA channel */ |
| 185 | int cur_cyl; /* cylinder head is on, or -1 */ |
| 186 | int cur_sector; /* last sector we saw go past */ |
| 187 | int req_cyl; /* the cylinder for the current r/w request */ |
| 188 | int head; /* head number ditto */ |
| 189 | int req_sector; /* sector number ditto */ |
| 190 | int scount; /* # sectors we're transferring at present */ |
| 191 | int retries; |
| 192 | int settle_time; |
| 193 | int secpercyl; /* disk geometry information */ |
| 194 | int secpertrack; |
| 195 | int total_secs; |
| 196 | int write_prot; /* 1 if write-protected, 0 if not, -1 dunno */ |
| 197 | struct dbdma_cmd *dma_cmd; |
| 198 | int ref_count; |
| 199 | int expect_cyl; |
| 200 | struct timer_list timeout; |
| 201 | int timeout_pending; |
| 202 | int ejected; |
| 203 | wait_queue_head_t wait; |
| 204 | int wanted; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 205 | struct macio_dev *mdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | char dbdma_cmd_space[5 * sizeof(struct dbdma_cmd)]; |
| 207 | }; |
| 208 | |
| 209 | static struct floppy_state floppy_states[MAX_FLOPPIES]; |
| 210 | static int floppy_count = 0; |
| 211 | static DEFINE_SPINLOCK(swim3_lock); |
| 212 | |
| 213 | static unsigned short write_preamble[] = { |
| 214 | 0x4e4e, 0x4e4e, 0x4e4e, 0x4e4e, 0x4e4e, /* gap field */ |
| 215 | 0, 0, 0, 0, 0, 0, /* sync field */ |
| 216 | 0x99a1, 0x99a1, 0x99a1, 0x99fb, /* data address mark */ |
| 217 | 0x990f /* no escape for 512 bytes */ |
| 218 | }; |
| 219 | |
| 220 | static unsigned short write_postamble[] = { |
| 221 | 0x9904, /* insert CRC */ |
| 222 | 0x4e4e, 0x4e4e, |
| 223 | 0x9908, /* stop writing */ |
| 224 | 0, 0, 0, 0, 0, 0 |
| 225 | }; |
| 226 | |
| 227 | static void swim3_select(struct floppy_state *fs, int sel); |
| 228 | static void swim3_action(struct floppy_state *fs, int action); |
| 229 | static int swim3_readbit(struct floppy_state *fs, int bit); |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 230 | static void do_fd_request(struct request_queue * q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | static void start_request(struct floppy_state *fs); |
| 232 | static void set_timeout(struct floppy_state *fs, int nticks, |
| 233 | void (*proc)(unsigned long)); |
| 234 | static void scan_track(struct floppy_state *fs); |
| 235 | static void seek_track(struct floppy_state *fs, int n); |
| 236 | static void init_dma(struct dbdma_cmd *cp, int cmd, void *buf, int count); |
| 237 | static void setup_transfer(struct floppy_state *fs); |
| 238 | static void act(struct floppy_state *fs); |
| 239 | static void scan_timeout(unsigned long data); |
| 240 | static void seek_timeout(unsigned long data); |
| 241 | static void settle_timeout(unsigned long data); |
| 242 | static void xfer_timeout(unsigned long data); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 243 | static irqreturn_t swim3_interrupt(int irq, void *dev_id); |
| 244 | /*static void fd_dma_interrupt(int irq, void *dev_id);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | static int grab_drive(struct floppy_state *fs, enum swim_state state, |
| 246 | int interruptible); |
| 247 | static void release_drive(struct floppy_state *fs); |
| 248 | static int fd_eject(struct floppy_state *fs); |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 249 | static int floppy_ioctl(struct block_device *bdev, fmode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | unsigned int cmd, unsigned long param); |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 251 | static int floppy_open(struct block_device *bdev, fmode_t mode); |
| 252 | static int floppy_release(struct gendisk *disk, fmode_t mode); |
Tejun Heo | 4bbde77 | 2011-03-09 19:54:28 +0100 | [diff] [blame] | 253 | static unsigned int floppy_check_events(struct gendisk *disk, |
| 254 | unsigned int clearing); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | static int floppy_revalidate(struct gendisk *disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 257 | static bool swim3_end_request(int err, unsigned int nr_bytes) |
| 258 | { |
| 259 | if (__blk_end_request(fd_req, err, nr_bytes)) |
| 260 | return true; |
| 261 | |
| 262 | fd_req = NULL; |
| 263 | return false; |
| 264 | } |
| 265 | |
| 266 | static bool swim3_end_request_cur(int err) |
| 267 | { |
| 268 | return swim3_end_request(err, blk_rq_cur_bytes(fd_req)); |
| 269 | } |
| 270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | static void swim3_select(struct floppy_state *fs, int sel) |
| 272 | { |
| 273 | struct swim3 __iomem *sw = fs->swim3; |
| 274 | |
| 275 | out_8(&sw->select, RELAX); |
| 276 | if (sel & 8) |
| 277 | out_8(&sw->control_bis, SELECT); |
| 278 | else |
| 279 | out_8(&sw->control_bic, SELECT); |
| 280 | out_8(&sw->select, sel & CA_MASK); |
| 281 | } |
| 282 | |
| 283 | static void swim3_action(struct floppy_state *fs, int action) |
| 284 | { |
| 285 | struct swim3 __iomem *sw = fs->swim3; |
| 286 | |
| 287 | swim3_select(fs, action); |
| 288 | udelay(1); |
| 289 | out_8(&sw->select, sw->select | LSTRB); |
| 290 | udelay(2); |
| 291 | out_8(&sw->select, sw->select & ~LSTRB); |
| 292 | udelay(1); |
| 293 | } |
| 294 | |
| 295 | static int swim3_readbit(struct floppy_state *fs, int bit) |
| 296 | { |
| 297 | struct swim3 __iomem *sw = fs->swim3; |
| 298 | int stat; |
| 299 | |
| 300 | swim3_select(fs, bit); |
| 301 | udelay(1); |
| 302 | stat = in_8(&sw->status); |
| 303 | return (stat & DATA) == 0; |
| 304 | } |
| 305 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 306 | static void do_fd_request(struct request_queue * q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | { |
| 308 | int i; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 309 | |
| 310 | for(i=0; i<floppy_count; i++) { |
| 311 | struct floppy_state *fs = &floppy_states[i]; |
| 312 | if (fs->mdev->media_bay && |
| 313 | check_media_bay(fs->mdev->media_bay) != MB_FD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | continue; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 315 | start_request(fs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static void start_request(struct floppy_state *fs) |
| 320 | { |
| 321 | struct request *req; |
| 322 | unsigned long x; |
| 323 | |
| 324 | if (fs->state == idle && fs->wanted) { |
| 325 | fs->state = available; |
| 326 | wake_up(&fs->wait); |
| 327 | return; |
| 328 | } |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 329 | while (fs->state == idle) { |
| 330 | if (!fd_req) { |
Tejun Heo | 9934c8c | 2009-05-08 11:54:16 +0900 | [diff] [blame] | 331 | fd_req = blk_fetch_request(swim3_queue); |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 332 | if (!fd_req) |
| 333 | break; |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 334 | } |
| 335 | req = fd_req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | #if 0 |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 337 | printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%u buf=%p\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | req->rq_disk->disk_name, req->cmd, |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 339 | (long)blk_rq_pos(req), blk_rq_sectors(req), req->buffer); |
| 340 | printk(" errors=%d current_nr_sectors=%u\n", |
| 341 | req->errors, blk_rq_cur_sectors(req)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | #endif |
| 343 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 344 | if (blk_rq_pos(req) >= fs->total_secs) { |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 345 | swim3_end_request_cur(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | continue; |
| 347 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | if (fs->ejected) { |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 349 | swim3_end_request_cur(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | continue; |
| 351 | } |
| 352 | |
| 353 | if (rq_data_dir(req) == WRITE) { |
| 354 | if (fs->write_prot < 0) |
| 355 | fs->write_prot = swim3_readbit(fs, WRITE_PROT); |
| 356 | if (fs->write_prot) { |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 357 | swim3_end_request_cur(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | continue; |
| 359 | } |
| 360 | } |
| 361 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 362 | /* Do not remove the cast. blk_rq_pos(req) is now a |
| 363 | * sector_t and can be 64 bits, but it will never go |
| 364 | * past 32 bits for this driver anyway, so we can |
| 365 | * safely cast it down and not have to do a 64/32 |
| 366 | * division |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | */ |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 368 | fs->req_cyl = ((long)blk_rq_pos(req)) / fs->secpercyl; |
| 369 | x = ((long)blk_rq_pos(req)) % fs->secpercyl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | fs->head = x / fs->secpertrack; |
| 371 | fs->req_sector = x % fs->secpertrack + 1; |
| 372 | fd_req = req; |
| 373 | fs->state = do_transfer; |
| 374 | fs->retries = 0; |
| 375 | |
| 376 | act(fs); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | static void set_timeout(struct floppy_state *fs, int nticks, |
| 381 | void (*proc)(unsigned long)) |
| 382 | { |
| 383 | unsigned long flags; |
| 384 | |
Paul Mackerras | 515729e | 2005-11-08 12:15:36 +1100 | [diff] [blame] | 385 | spin_lock_irqsave(&fs->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | if (fs->timeout_pending) |
| 387 | del_timer(&fs->timeout); |
| 388 | fs->timeout.expires = jiffies + nticks; |
| 389 | fs->timeout.function = proc; |
| 390 | fs->timeout.data = (unsigned long) fs; |
| 391 | add_timer(&fs->timeout); |
| 392 | fs->timeout_pending = 1; |
Paul Mackerras | 515729e | 2005-11-08 12:15:36 +1100 | [diff] [blame] | 393 | spin_unlock_irqrestore(&fs->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static inline void scan_track(struct floppy_state *fs) |
| 397 | { |
| 398 | struct swim3 __iomem *sw = fs->swim3; |
| 399 | |
| 400 | swim3_select(fs, READ_DATA_0); |
| 401 | in_8(&sw->intr); /* clear SEEN_SECTOR bit */ |
| 402 | in_8(&sw->error); |
| 403 | out_8(&sw->intr_enable, SEEN_SECTOR); |
| 404 | out_8(&sw->control_bis, DO_ACTION); |
| 405 | /* enable intr when track found */ |
| 406 | set_timeout(fs, HZ, scan_timeout); /* enable timeout */ |
| 407 | } |
| 408 | |
| 409 | static inline void seek_track(struct floppy_state *fs, int n) |
| 410 | { |
| 411 | struct swim3 __iomem *sw = fs->swim3; |
| 412 | |
| 413 | if (n >= 0) { |
| 414 | swim3_action(fs, SEEK_POSITIVE); |
| 415 | sw->nseek = n; |
| 416 | } else { |
| 417 | swim3_action(fs, SEEK_NEGATIVE); |
| 418 | sw->nseek = -n; |
| 419 | } |
| 420 | fs->expect_cyl = (fs->cur_cyl >= 0)? fs->cur_cyl + n: -1; |
| 421 | swim3_select(fs, STEP); |
| 422 | in_8(&sw->error); |
| 423 | /* enable intr when seek finished */ |
| 424 | out_8(&sw->intr_enable, SEEK_DONE); |
| 425 | out_8(&sw->control_bis, DO_SEEK); |
| 426 | set_timeout(fs, 3*HZ, seek_timeout); /* enable timeout */ |
| 427 | fs->settle_time = 0; |
| 428 | } |
| 429 | |
| 430 | static inline void init_dma(struct dbdma_cmd *cp, int cmd, |
| 431 | void *buf, int count) |
| 432 | { |
| 433 | st_le16(&cp->req_count, count); |
| 434 | st_le16(&cp->command, cmd); |
| 435 | st_le32(&cp->phy_addr, virt_to_bus(buf)); |
| 436 | cp->xfer_status = 0; |
| 437 | } |
| 438 | |
| 439 | static inline void setup_transfer(struct floppy_state *fs) |
| 440 | { |
| 441 | int n; |
| 442 | struct swim3 __iomem *sw = fs->swim3; |
| 443 | struct dbdma_cmd *cp = fs->dma_cmd; |
| 444 | struct dbdma_regs __iomem *dr = fs->dma; |
| 445 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 446 | if (blk_rq_cur_sectors(fd_req) <= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | printk(KERN_ERR "swim3: transfer 0 sectors?\n"); |
| 448 | return; |
| 449 | } |
| 450 | if (rq_data_dir(fd_req) == WRITE) |
| 451 | n = 1; |
| 452 | else { |
| 453 | n = fs->secpertrack - fs->req_sector + 1; |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 454 | if (n > blk_rq_cur_sectors(fd_req)) |
| 455 | n = blk_rq_cur_sectors(fd_req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } |
| 457 | fs->scount = n; |
| 458 | swim3_select(fs, fs->head? READ_DATA_1: READ_DATA_0); |
| 459 | out_8(&sw->sector, fs->req_sector); |
| 460 | out_8(&sw->nsect, n); |
| 461 | out_8(&sw->gap3, 0); |
| 462 | out_le32(&dr->cmdptr, virt_to_bus(cp)); |
| 463 | if (rq_data_dir(fd_req) == WRITE) { |
| 464 | /* Set up 3 dma commands: write preamble, data, postamble */ |
| 465 | init_dma(cp, OUTPUT_MORE, write_preamble, sizeof(write_preamble)); |
| 466 | ++cp; |
| 467 | init_dma(cp, OUTPUT_MORE, fd_req->buffer, 512); |
| 468 | ++cp; |
| 469 | init_dma(cp, OUTPUT_LAST, write_postamble, sizeof(write_postamble)); |
| 470 | } else { |
| 471 | init_dma(cp, INPUT_LAST, fd_req->buffer, n * 512); |
| 472 | } |
| 473 | ++cp; |
| 474 | out_le16(&cp->command, DBDMA_STOP); |
| 475 | out_8(&sw->control_bic, DO_ACTION | WRITE_SECTORS); |
| 476 | in_8(&sw->error); |
| 477 | out_8(&sw->control_bic, DO_ACTION | WRITE_SECTORS); |
| 478 | if (rq_data_dir(fd_req) == WRITE) |
| 479 | out_8(&sw->control_bis, WRITE_SECTORS); |
| 480 | in_8(&sw->intr); |
| 481 | out_le32(&dr->control, (RUN << 16) | RUN); |
| 482 | /* enable intr when transfer complete */ |
| 483 | out_8(&sw->intr_enable, TRANSFER_DONE); |
| 484 | out_8(&sw->control_bis, DO_ACTION); |
| 485 | set_timeout(fs, 2*HZ, xfer_timeout); /* enable timeout */ |
| 486 | } |
| 487 | |
| 488 | static void act(struct floppy_state *fs) |
| 489 | { |
| 490 | for (;;) { |
| 491 | switch (fs->state) { |
| 492 | case idle: |
| 493 | return; /* XXX shouldn't get here */ |
| 494 | |
| 495 | case locating: |
| 496 | if (swim3_readbit(fs, TRACK_ZERO)) { |
| 497 | fs->cur_cyl = 0; |
| 498 | if (fs->req_cyl == 0) |
| 499 | fs->state = do_transfer; |
| 500 | else |
| 501 | fs->state = seeking; |
| 502 | break; |
| 503 | } |
| 504 | scan_track(fs); |
| 505 | return; |
| 506 | |
| 507 | case seeking: |
| 508 | if (fs->cur_cyl < 0) { |
| 509 | fs->expect_cyl = -1; |
| 510 | fs->state = locating; |
| 511 | break; |
| 512 | } |
| 513 | if (fs->req_cyl == fs->cur_cyl) { |
| 514 | printk("whoops, seeking 0\n"); |
| 515 | fs->state = do_transfer; |
| 516 | break; |
| 517 | } |
| 518 | seek_track(fs, fs->req_cyl - fs->cur_cyl); |
| 519 | return; |
| 520 | |
| 521 | case settling: |
| 522 | /* check for SEEK_COMPLETE after 30ms */ |
| 523 | fs->settle_time = (HZ + 32) / 33; |
| 524 | set_timeout(fs, fs->settle_time, settle_timeout); |
| 525 | return; |
| 526 | |
| 527 | case do_transfer: |
| 528 | if (fs->cur_cyl != fs->req_cyl) { |
| 529 | if (fs->retries > 5) { |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 530 | swim3_end_request_cur(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | fs->state = idle; |
| 532 | return; |
| 533 | } |
| 534 | fs->state = seeking; |
| 535 | break; |
| 536 | } |
| 537 | setup_transfer(fs); |
| 538 | return; |
| 539 | |
| 540 | case jogging: |
| 541 | seek_track(fs, -5); |
| 542 | return; |
| 543 | |
| 544 | default: |
| 545 | printk(KERN_ERR"swim3: unknown state %d\n", fs->state); |
| 546 | return; |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | static void scan_timeout(unsigned long data) |
| 552 | { |
| 553 | struct floppy_state *fs = (struct floppy_state *) data; |
| 554 | struct swim3 __iomem *sw = fs->swim3; |
| 555 | |
| 556 | fs->timeout_pending = 0; |
| 557 | out_8(&sw->control_bic, DO_ACTION | WRITE_SECTORS); |
| 558 | out_8(&sw->select, RELAX); |
| 559 | out_8(&sw->intr_enable, 0); |
| 560 | fs->cur_cyl = -1; |
| 561 | if (fs->retries > 5) { |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 562 | swim3_end_request_cur(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | fs->state = idle; |
| 564 | start_request(fs); |
| 565 | } else { |
| 566 | fs->state = jogging; |
| 567 | act(fs); |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | static void seek_timeout(unsigned long data) |
| 572 | { |
| 573 | struct floppy_state *fs = (struct floppy_state *) data; |
| 574 | struct swim3 __iomem *sw = fs->swim3; |
| 575 | |
| 576 | fs->timeout_pending = 0; |
| 577 | out_8(&sw->control_bic, DO_SEEK); |
| 578 | out_8(&sw->select, RELAX); |
| 579 | out_8(&sw->intr_enable, 0); |
| 580 | printk(KERN_ERR "swim3: seek timeout\n"); |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 581 | swim3_end_request_cur(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | fs->state = idle; |
| 583 | start_request(fs); |
| 584 | } |
| 585 | |
| 586 | static void settle_timeout(unsigned long data) |
| 587 | { |
| 588 | struct floppy_state *fs = (struct floppy_state *) data; |
| 589 | struct swim3 __iomem *sw = fs->swim3; |
| 590 | |
| 591 | fs->timeout_pending = 0; |
| 592 | if (swim3_readbit(fs, SEEK_COMPLETE)) { |
| 593 | out_8(&sw->select, RELAX); |
| 594 | fs->state = locating; |
| 595 | act(fs); |
| 596 | return; |
| 597 | } |
| 598 | out_8(&sw->select, RELAX); |
| 599 | if (fs->settle_time < 2*HZ) { |
| 600 | ++fs->settle_time; |
| 601 | set_timeout(fs, 1, settle_timeout); |
| 602 | return; |
| 603 | } |
| 604 | printk(KERN_ERR "swim3: seek settle timeout\n"); |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 605 | swim3_end_request_cur(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | fs->state = idle; |
| 607 | start_request(fs); |
| 608 | } |
| 609 | |
| 610 | static void xfer_timeout(unsigned long data) |
| 611 | { |
| 612 | struct floppy_state *fs = (struct floppy_state *) data; |
| 613 | struct swim3 __iomem *sw = fs->swim3; |
| 614 | struct dbdma_regs __iomem *dr = fs->dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | int n; |
| 616 | |
| 617 | fs->timeout_pending = 0; |
| 618 | out_le32(&dr->control, RUN << 16); |
| 619 | /* We must wait a bit for dbdma to stop */ |
| 620 | for (n = 0; (in_le32(&dr->status) & ACTIVE) && n < 1000; n++) |
| 621 | udelay(1); |
| 622 | out_8(&sw->intr_enable, 0); |
| 623 | out_8(&sw->control_bic, WRITE_SECTORS | DO_ACTION); |
| 624 | out_8(&sw->select, RELAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | printk(KERN_ERR "swim3: timeout %sing sector %ld\n", |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 626 | (rq_data_dir(fd_req)==WRITE? "writ": "read"), |
| 627 | (long)blk_rq_pos(fd_req)); |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 628 | swim3_end_request_cur(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | fs->state = idle; |
| 630 | start_request(fs); |
| 631 | } |
| 632 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 633 | static irqreturn_t swim3_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
| 635 | struct floppy_state *fs = (struct floppy_state *) dev_id; |
| 636 | struct swim3 __iomem *sw = fs->swim3; |
| 637 | int intr, err, n; |
| 638 | int stat, resid; |
| 639 | struct dbdma_regs __iomem *dr; |
| 640 | struct dbdma_cmd *cp; |
| 641 | |
| 642 | intr = in_8(&sw->intr); |
| 643 | err = (intr & ERROR_INTR)? in_8(&sw->error): 0; |
| 644 | if ((intr & ERROR_INTR) && fs->state != do_transfer) |
Olaf Hering | 14b1ffb | 2006-10-02 22:57:23 +0200 | [diff] [blame] | 645 | printk(KERN_ERR "swim3_interrupt, state=%d, dir=%x, intr=%x, err=%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | fs->state, rq_data_dir(fd_req), intr, err); |
| 647 | switch (fs->state) { |
| 648 | case locating: |
| 649 | if (intr & SEEN_SECTOR) { |
| 650 | out_8(&sw->control_bic, DO_ACTION | WRITE_SECTORS); |
| 651 | out_8(&sw->select, RELAX); |
| 652 | out_8(&sw->intr_enable, 0); |
| 653 | del_timer(&fs->timeout); |
| 654 | fs->timeout_pending = 0; |
| 655 | if (sw->ctrack == 0xff) { |
| 656 | printk(KERN_ERR "swim3: seen sector but cyl=ff?\n"); |
| 657 | fs->cur_cyl = -1; |
| 658 | if (fs->retries > 5) { |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 659 | swim3_end_request_cur(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | fs->state = idle; |
| 661 | start_request(fs); |
| 662 | } else { |
| 663 | fs->state = jogging; |
| 664 | act(fs); |
| 665 | } |
| 666 | break; |
| 667 | } |
| 668 | fs->cur_cyl = sw->ctrack; |
| 669 | fs->cur_sector = sw->csect; |
| 670 | if (fs->expect_cyl != -1 && fs->expect_cyl != fs->cur_cyl) |
| 671 | printk(KERN_ERR "swim3: expected cyl %d, got %d\n", |
| 672 | fs->expect_cyl, fs->cur_cyl); |
| 673 | fs->state = do_transfer; |
| 674 | act(fs); |
| 675 | } |
| 676 | break; |
| 677 | case seeking: |
| 678 | case jogging: |
| 679 | if (sw->nseek == 0) { |
| 680 | out_8(&sw->control_bic, DO_SEEK); |
| 681 | out_8(&sw->select, RELAX); |
| 682 | out_8(&sw->intr_enable, 0); |
| 683 | del_timer(&fs->timeout); |
| 684 | fs->timeout_pending = 0; |
| 685 | if (fs->state == seeking) |
| 686 | ++fs->retries; |
| 687 | fs->state = settling; |
| 688 | act(fs); |
| 689 | } |
| 690 | break; |
| 691 | case settling: |
| 692 | out_8(&sw->intr_enable, 0); |
| 693 | del_timer(&fs->timeout); |
| 694 | fs->timeout_pending = 0; |
| 695 | act(fs); |
| 696 | break; |
| 697 | case do_transfer: |
| 698 | if ((intr & (ERROR_INTR | TRANSFER_DONE)) == 0) |
| 699 | break; |
| 700 | out_8(&sw->intr_enable, 0); |
| 701 | out_8(&sw->control_bic, WRITE_SECTORS | DO_ACTION); |
| 702 | out_8(&sw->select, RELAX); |
| 703 | del_timer(&fs->timeout); |
| 704 | fs->timeout_pending = 0; |
| 705 | dr = fs->dma; |
| 706 | cp = fs->dma_cmd; |
| 707 | if (rq_data_dir(fd_req) == WRITE) |
| 708 | ++cp; |
| 709 | /* |
| 710 | * Check that the main data transfer has finished. |
| 711 | * On writing, the swim3 sometimes doesn't use |
| 712 | * up all the bytes of the postamble, so we can still |
| 713 | * see DMA active here. That doesn't matter as long |
| 714 | * as all the sector data has been transferred. |
| 715 | */ |
| 716 | if ((intr & ERROR_INTR) == 0 && cp->xfer_status == 0) { |
| 717 | /* wait a little while for DMA to complete */ |
| 718 | for (n = 0; n < 100; ++n) { |
| 719 | if (cp->xfer_status != 0) |
| 720 | break; |
| 721 | udelay(1); |
| 722 | barrier(); |
| 723 | } |
| 724 | } |
| 725 | /* turn off DMA */ |
| 726 | out_le32(&dr->control, (RUN | PAUSE) << 16); |
| 727 | stat = ld_le16(&cp->xfer_status); |
| 728 | resid = ld_le16(&cp->res_count); |
| 729 | if (intr & ERROR_INTR) { |
| 730 | n = fs->scount - 1 - resid / 512; |
| 731 | if (n > 0) { |
Tejun Heo | 467ca75 | 2009-04-28 13:06:12 +0900 | [diff] [blame] | 732 | blk_update_request(fd_req, 0, n << 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | fs->req_sector += n; |
| 734 | } |
| 735 | if (fs->retries < 5) { |
| 736 | ++fs->retries; |
| 737 | act(fs); |
| 738 | } else { |
| 739 | printk("swim3: error %sing block %ld (err=%x)\n", |
| 740 | rq_data_dir(fd_req) == WRITE? "writ": "read", |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 741 | (long)blk_rq_pos(fd_req), err); |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 742 | swim3_end_request_cur(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | fs->state = idle; |
| 744 | } |
| 745 | } else { |
| 746 | if ((stat & ACTIVE) == 0 || resid != 0) { |
| 747 | /* musta been an error */ |
| 748 | printk(KERN_ERR "swim3: fd dma: stat=%x resid=%d\n", stat, resid); |
Olaf Hering | 14b1ffb | 2006-10-02 22:57:23 +0200 | [diff] [blame] | 749 | printk(KERN_ERR " state=%d, dir=%x, intr=%x, err=%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | fs->state, rq_data_dir(fd_req), intr, err); |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 751 | swim3_end_request_cur(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | fs->state = idle; |
| 753 | start_request(fs); |
| 754 | break; |
| 755 | } |
Tejun Heo | f4bd4b9 | 2009-05-08 11:54:04 +0900 | [diff] [blame] | 756 | if (swim3_end_request(0, fs->scount << 9)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | fs->req_sector += fs->scount; |
| 758 | if (fs->req_sector > fs->secpertrack) { |
| 759 | fs->req_sector -= fs->secpertrack; |
| 760 | if (++fs->head > 1) { |
| 761 | fs->head = 0; |
| 762 | ++fs->req_cyl; |
| 763 | } |
| 764 | } |
| 765 | act(fs); |
Tejun Heo | 467ca75 | 2009-04-28 13:06:12 +0900 | [diff] [blame] | 766 | } else |
| 767 | fs->state = idle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | } |
| 769 | if (fs->state == idle) |
| 770 | start_request(fs); |
| 771 | break; |
| 772 | default: |
| 773 | printk(KERN_ERR "swim3: don't know what to do in state %d\n", fs->state); |
| 774 | } |
| 775 | return IRQ_HANDLED; |
| 776 | } |
| 777 | |
| 778 | /* |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 779 | static void fd_dma_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
| 781 | } |
| 782 | */ |
| 783 | |
| 784 | static int grab_drive(struct floppy_state *fs, enum swim_state state, |
| 785 | int interruptible) |
| 786 | { |
| 787 | unsigned long flags; |
| 788 | |
Paul Mackerras | 515729e | 2005-11-08 12:15:36 +1100 | [diff] [blame] | 789 | spin_lock_irqsave(&fs->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | if (fs->state != idle) { |
| 791 | ++fs->wanted; |
| 792 | while (fs->state != available) { |
| 793 | if (interruptible && signal_pending(current)) { |
| 794 | --fs->wanted; |
Paul Mackerras | 515729e | 2005-11-08 12:15:36 +1100 | [diff] [blame] | 795 | spin_unlock_irqrestore(&fs->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | return -EINTR; |
| 797 | } |
| 798 | interruptible_sleep_on(&fs->wait); |
| 799 | } |
| 800 | --fs->wanted; |
| 801 | } |
| 802 | fs->state = state; |
Paul Mackerras | 515729e | 2005-11-08 12:15:36 +1100 | [diff] [blame] | 803 | spin_unlock_irqrestore(&fs->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | static void release_drive(struct floppy_state *fs) |
| 808 | { |
| 809 | unsigned long flags; |
| 810 | |
Paul Mackerras | 515729e | 2005-11-08 12:15:36 +1100 | [diff] [blame] | 811 | spin_lock_irqsave(&fs->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | fs->state = idle; |
| 813 | start_request(fs); |
Paul Mackerras | 515729e | 2005-11-08 12:15:36 +1100 | [diff] [blame] | 814 | spin_unlock_irqrestore(&fs->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | static int fd_eject(struct floppy_state *fs) |
| 818 | { |
| 819 | int err, n; |
| 820 | |
| 821 | err = grab_drive(fs, ejecting, 1); |
| 822 | if (err) |
| 823 | return err; |
| 824 | swim3_action(fs, EJECT); |
| 825 | for (n = 20; n > 0; --n) { |
| 826 | if (signal_pending(current)) { |
| 827 | err = -EINTR; |
| 828 | break; |
| 829 | } |
| 830 | swim3_select(fs, RELAX); |
Nishanth Aravamudan | 86e8486 | 2005-09-10 00:27:28 -0700 | [diff] [blame] | 831 | schedule_timeout_interruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | if (swim3_readbit(fs, DISK_IN) == 0) |
| 833 | break; |
| 834 | } |
| 835 | swim3_select(fs, RELAX); |
| 836 | udelay(150); |
| 837 | fs->ejected = 1; |
| 838 | release_drive(fs); |
| 839 | return err; |
| 840 | } |
| 841 | |
| 842 | static struct floppy_struct floppy_type = |
| 843 | { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,NULL }; /* 7 1.44MB 3.5" */ |
| 844 | |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 845 | static int floppy_locked_ioctl(struct block_device *bdev, fmode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | unsigned int cmd, unsigned long param) |
| 847 | { |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 848 | struct floppy_state *fs = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | int err; |
| 850 | |
| 851 | if ((cmd & 0x80) && !capable(CAP_SYS_ADMIN)) |
| 852 | return -EPERM; |
| 853 | |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 854 | if (fs->mdev->media_bay && |
| 855 | check_media_bay(fs->mdev->media_bay) != MB_FD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | return -ENXIO; |
| 857 | |
| 858 | switch (cmd) { |
| 859 | case FDEJECT: |
| 860 | if (fs->ref_count != 1) |
| 861 | return -EBUSY; |
| 862 | err = fd_eject(fs); |
| 863 | return err; |
| 864 | case FDGETPRM: |
| 865 | if (copy_to_user((void __user *) param, &floppy_type, |
| 866 | sizeof(struct floppy_struct))) |
| 867 | return -EFAULT; |
| 868 | return 0; |
| 869 | } |
| 870 | return -ENOTTY; |
| 871 | } |
| 872 | |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 873 | static int floppy_ioctl(struct block_device *bdev, fmode_t mode, |
| 874 | unsigned int cmd, unsigned long param) |
| 875 | { |
| 876 | int ret; |
| 877 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 878 | mutex_lock(&swim3_mutex); |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 879 | ret = floppy_locked_ioctl(bdev, mode, cmd, param); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 880 | mutex_unlock(&swim3_mutex); |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 881 | |
| 882 | return ret; |
| 883 | } |
| 884 | |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 885 | static int floppy_open(struct block_device *bdev, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | { |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 887 | struct floppy_state *fs = bdev->bd_disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | struct swim3 __iomem *sw = fs->swim3; |
| 889 | int n, err = 0; |
| 890 | |
| 891 | if (fs->ref_count == 0) { |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 892 | if (fs->mdev->media_bay && |
| 893 | check_media_bay(fs->mdev->media_bay) != MB_FD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | return -ENXIO; |
| 895 | out_8(&sw->setup, S_IBM_DRIVE | S_FCLK_DIV2); |
| 896 | out_8(&sw->control_bic, 0xff); |
| 897 | out_8(&sw->mode, 0x95); |
| 898 | udelay(10); |
| 899 | out_8(&sw->intr_enable, 0); |
| 900 | out_8(&sw->control_bis, DRIVE_ENABLE | INTR_ENABLE); |
| 901 | swim3_action(fs, MOTOR_ON); |
| 902 | fs->write_prot = -1; |
| 903 | fs->cur_cyl = -1; |
| 904 | for (n = 0; n < 2 * HZ; ++n) { |
| 905 | if (n >= HZ/30 && swim3_readbit(fs, SEEK_COMPLETE)) |
| 906 | break; |
| 907 | if (signal_pending(current)) { |
| 908 | err = -EINTR; |
| 909 | break; |
| 910 | } |
| 911 | swim3_select(fs, RELAX); |
Nishanth Aravamudan | 86e8486 | 2005-09-10 00:27:28 -0700 | [diff] [blame] | 912 | schedule_timeout_interruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | if (err == 0 && (swim3_readbit(fs, SEEK_COMPLETE) == 0 |
| 915 | || swim3_readbit(fs, DISK_IN) == 0)) |
| 916 | err = -ENXIO; |
| 917 | swim3_action(fs, SETMFM); |
| 918 | swim3_select(fs, RELAX); |
| 919 | |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 920 | } else if (fs->ref_count == -1 || mode & FMODE_EXCL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | return -EBUSY; |
| 922 | |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 923 | if (err == 0 && (mode & FMODE_NDELAY) == 0 |
| 924 | && (mode & (FMODE_READ|FMODE_WRITE))) { |
| 925 | check_disk_change(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | if (fs->ejected) |
| 927 | err = -ENXIO; |
| 928 | } |
| 929 | |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 930 | if (err == 0 && (mode & FMODE_WRITE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | if (fs->write_prot < 0) |
| 932 | fs->write_prot = swim3_readbit(fs, WRITE_PROT); |
| 933 | if (fs->write_prot) |
| 934 | err = -EROFS; |
| 935 | } |
| 936 | |
| 937 | if (err) { |
| 938 | if (fs->ref_count == 0) { |
| 939 | swim3_action(fs, MOTOR_OFF); |
| 940 | out_8(&sw->control_bic, DRIVE_ENABLE | INTR_ENABLE); |
| 941 | swim3_select(fs, RELAX); |
| 942 | } |
| 943 | return err; |
| 944 | } |
| 945 | |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 946 | if (mode & FMODE_EXCL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | fs->ref_count = -1; |
| 948 | else |
| 949 | ++fs->ref_count; |
| 950 | |
| 951 | return 0; |
| 952 | } |
| 953 | |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 954 | static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode) |
| 955 | { |
| 956 | int ret; |
| 957 | |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 958 | mutex_lock(&swim3_mutex); |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 959 | ret = floppy_open(bdev, mode); |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 960 | mutex_unlock(&swim3_mutex); |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 961 | |
| 962 | return ret; |
| 963 | } |
| 964 | |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 965 | static int floppy_release(struct gendisk *disk, fmode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | { |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 967 | struct floppy_state *fs = disk->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | struct swim3 __iomem *sw = fs->swim3; |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 969 | mutex_lock(&swim3_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | if (fs->ref_count > 0 && --fs->ref_count == 0) { |
| 971 | swim3_action(fs, MOTOR_OFF); |
| 972 | out_8(&sw->control_bic, 0xff); |
| 973 | swim3_select(fs, RELAX); |
| 974 | } |
Arnd Bergmann | 2a48fc0 | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 975 | mutex_unlock(&swim3_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | return 0; |
| 977 | } |
| 978 | |
Tejun Heo | 4bbde77 | 2011-03-09 19:54:28 +0100 | [diff] [blame] | 979 | static unsigned int floppy_check_events(struct gendisk *disk, |
| 980 | unsigned int clearing) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | { |
| 982 | struct floppy_state *fs = disk->private_data; |
Tejun Heo | 4bbde77 | 2011-03-09 19:54:28 +0100 | [diff] [blame] | 983 | return fs->ejected ? DISK_EVENT_MEDIA_CHANGE : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | static int floppy_revalidate(struct gendisk *disk) |
| 987 | { |
| 988 | struct floppy_state *fs = disk->private_data; |
| 989 | struct swim3 __iomem *sw; |
| 990 | int ret, n; |
| 991 | |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 992 | if (fs->mdev->media_bay && |
| 993 | check_media_bay(fs->mdev->media_bay) != MB_FD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
| 996 | sw = fs->swim3; |
| 997 | grab_drive(fs, revalidating, 0); |
| 998 | out_8(&sw->intr_enable, 0); |
| 999 | out_8(&sw->control_bis, DRIVE_ENABLE); |
| 1000 | swim3_action(fs, MOTOR_ON); /* necessary? */ |
| 1001 | fs->write_prot = -1; |
| 1002 | fs->cur_cyl = -1; |
| 1003 | mdelay(1); |
| 1004 | for (n = HZ; n > 0; --n) { |
| 1005 | if (swim3_readbit(fs, SEEK_COMPLETE)) |
| 1006 | break; |
| 1007 | if (signal_pending(current)) |
| 1008 | break; |
| 1009 | swim3_select(fs, RELAX); |
Nishanth Aravamudan | 86e8486 | 2005-09-10 00:27:28 -0700 | [diff] [blame] | 1010 | schedule_timeout_interruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | } |
| 1012 | ret = swim3_readbit(fs, SEEK_COMPLETE) == 0 |
| 1013 | || swim3_readbit(fs, DISK_IN) == 0; |
| 1014 | if (ret) |
| 1015 | swim3_action(fs, MOTOR_OFF); |
| 1016 | else { |
| 1017 | fs->ejected = 0; |
| 1018 | swim3_action(fs, SETMFM); |
| 1019 | } |
| 1020 | swim3_select(fs, RELAX); |
| 1021 | |
| 1022 | release_drive(fs); |
| 1023 | return ret; |
| 1024 | } |
| 1025 | |
Alexey Dobriyan | 83d5cde | 2009-09-21 17:01:13 -0700 | [diff] [blame] | 1026 | static const struct block_device_operations floppy_fops = { |
Arnd Bergmann | 6e9624b | 2010-08-07 18:25:34 +0200 | [diff] [blame] | 1027 | .open = floppy_unlocked_open, |
Al Viro | b4d9a44 | 2008-03-02 10:20:44 -0500 | [diff] [blame] | 1028 | .release = floppy_release, |
Arnd Bergmann | 8a6cfeb | 2010-07-08 10:18:46 +0200 | [diff] [blame] | 1029 | .ioctl = floppy_ioctl, |
Tejun Heo | 4bbde77 | 2011-03-09 19:54:28 +0100 | [diff] [blame] | 1030 | .check_events = floppy_check_events, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | .revalidate_disk= floppy_revalidate, |
| 1032 | }; |
| 1033 | |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1034 | static int swim3_add_device(struct macio_dev *mdev, int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | { |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 1036 | struct device_node *swim = mdev->ofdev.dev.of_node; |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1037 | struct floppy_state *fs = &floppy_states[index]; |
| 1038 | int rc = -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1040 | /* Check & Request resources */ |
| 1041 | if (macio_resource_count(mdev) < 2) { |
| 1042 | printk(KERN_WARNING "ifd%d: no address for %s\n", |
| 1043 | index, swim->full_name); |
| 1044 | return -ENXIO; |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1045 | } |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1046 | if (macio_irq_count(mdev) < 2) { |
| 1047 | printk(KERN_WARNING "fd%d: no intrs for device %s\n", |
| 1048 | index, swim->full_name); |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1049 | } |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1050 | if (macio_request_resource(mdev, 0, "swim3 (mmio)")) { |
| 1051 | printk(KERN_ERR "fd%d: can't request mmio resource for %s\n", |
| 1052 | index, swim->full_name); |
| 1053 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | } |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1055 | if (macio_request_resource(mdev, 1, "swim3 (dma)")) { |
| 1056 | printk(KERN_ERR "fd%d: can't request dma resource for %s\n", |
| 1057 | index, swim->full_name); |
| 1058 | macio_release_resource(mdev, 0); |
| 1059 | return -EBUSY; |
| 1060 | } |
| 1061 | dev_set_drvdata(&mdev->ofdev.dev, fs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 1063 | if (mdev->media_bay == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | pmac_call_feature(PMAC_FTR_SWIM3_ENABLE, swim, 0, 1); |
| 1065 | |
| 1066 | memset(fs, 0, sizeof(*fs)); |
Paul Mackerras | 515729e | 2005-11-08 12:15:36 +1100 | [diff] [blame] | 1067 | spin_lock_init(&fs->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | fs->state = idle; |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1069 | fs->swim3 = (struct swim3 __iomem *) |
| 1070 | ioremap(macio_resource_start(mdev, 0), 0x200); |
| 1071 | if (fs->swim3 == NULL) { |
| 1072 | printk("fd%d: couldn't map registers for %s\n", |
| 1073 | index, swim->full_name); |
| 1074 | rc = -ENOMEM; |
| 1075 | goto out_release; |
| 1076 | } |
| 1077 | fs->dma = (struct dbdma_regs __iomem *) |
| 1078 | ioremap(macio_resource_start(mdev, 1), 0x200); |
| 1079 | if (fs->dma == NULL) { |
| 1080 | printk("fd%d: couldn't map DMA for %s\n", |
| 1081 | index, swim->full_name); |
| 1082 | iounmap(fs->swim3); |
| 1083 | rc = -ENOMEM; |
| 1084 | goto out_release; |
| 1085 | } |
| 1086 | fs->swim3_intr = macio_irq(mdev, 0); |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 1087 | fs->dma_intr = macio_irq(mdev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | fs->cur_cyl = -1; |
| 1089 | fs->cur_sector = -1; |
| 1090 | fs->secpercyl = 36; |
| 1091 | fs->secpertrack = 18; |
| 1092 | fs->total_secs = 2880; |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 1093 | fs->mdev = mdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | init_waitqueue_head(&fs->wait); |
| 1095 | |
| 1096 | fs->dma_cmd = (struct dbdma_cmd *) DBDMA_ALIGN(fs->dbdma_cmd_space); |
| 1097 | memset(fs->dma_cmd, 0, 2 * sizeof(struct dbdma_cmd)); |
| 1098 | st_le16(&fs->dma_cmd[1].command, DBDMA_STOP); |
| 1099 | |
| 1100 | if (request_irq(fs->swim3_intr, swim3_interrupt, 0, "SWIM3", fs)) { |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1101 | printk(KERN_ERR "fd%d: couldn't request irq %d for %s\n", |
| 1102 | index, fs->swim3_intr, swim->full_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | pmac_call_feature(PMAC_FTR_SWIM3_ENABLE, swim, 0, 0); |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1104 | goto out_unmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | return -EBUSY; |
| 1106 | } |
| 1107 | /* |
| 1108 | if (request_irq(fs->dma_intr, fd_dma_interrupt, 0, "SWIM3-dma", fs)) { |
| 1109 | printk(KERN_ERR "Couldn't get irq %d for SWIM3 DMA", |
| 1110 | fs->dma_intr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | return -EBUSY; |
| 1112 | } |
| 1113 | */ |
| 1114 | |
| 1115 | init_timer(&fs->timeout); |
| 1116 | |
| 1117 | printk(KERN_INFO "fd%d: SWIM3 floppy controller %s\n", floppy_count, |
Benjamin Herrenschmidt | d58b0c3 | 2009-12-01 14:36:28 +0000 | [diff] [blame] | 1118 | mdev->media_bay ? "in media bay" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1120 | return 0; |
| 1121 | |
| 1122 | out_unmap: |
| 1123 | iounmap(fs->dma); |
| 1124 | iounmap(fs->swim3); |
| 1125 | |
| 1126 | out_release: |
| 1127 | macio_release_resource(mdev, 0); |
| 1128 | macio_release_resource(mdev, 1); |
| 1129 | |
| 1130 | return rc; |
| 1131 | } |
| 1132 | |
| 1133 | static int __devinit swim3_attach(struct macio_dev *mdev, const struct of_device_id *match) |
| 1134 | { |
| 1135 | int i, rc; |
| 1136 | struct gendisk *disk; |
| 1137 | |
| 1138 | /* Add the drive */ |
| 1139 | rc = swim3_add_device(mdev, floppy_count); |
| 1140 | if (rc) |
| 1141 | return rc; |
| 1142 | |
| 1143 | /* Now create the queue if not there yet */ |
| 1144 | if (swim3_queue == NULL) { |
| 1145 | /* If we failed, there isn't much we can do as the driver is still |
| 1146 | * too dumb to remove the device, just bail out |
| 1147 | */ |
| 1148 | if (register_blkdev(FLOPPY_MAJOR, "fd")) |
| 1149 | return 0; |
| 1150 | swim3_queue = blk_init_queue(do_fd_request, &swim3_lock); |
| 1151 | if (swim3_queue == NULL) { |
| 1152 | unregister_blkdev(FLOPPY_MAJOR, "fd"); |
| 1153 | return 0; |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | /* Now register that disk. Same comment about failure handling */ |
| 1158 | i = floppy_count++; |
| 1159 | disk = disks[i] = alloc_disk(1); |
| 1160 | if (disk == NULL) |
| 1161 | return 0; |
| 1162 | |
| 1163 | disk->major = FLOPPY_MAJOR; |
| 1164 | disk->first_minor = i; |
| 1165 | disk->fops = &floppy_fops; |
| 1166 | disk->private_data = &floppy_states[i]; |
| 1167 | disk->queue = swim3_queue; |
| 1168 | disk->flags |= GENHD_FL_REMOVABLE; |
| 1169 | sprintf(disk->disk_name, "fd%d", i); |
| 1170 | set_capacity(disk, 2880); |
| 1171 | add_disk(disk); |
| 1172 | |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
| 1176 | static struct of_device_id swim3_match[] = |
| 1177 | { |
| 1178 | { |
| 1179 | .name = "swim3", |
| 1180 | }, |
| 1181 | { |
| 1182 | .compatible = "ohare-swim3" |
| 1183 | }, |
| 1184 | { |
| 1185 | .compatible = "swim3" |
| 1186 | }, |
Axel Lin | f41c53a | 2011-08-03 15:02:55 +0200 | [diff] [blame] | 1187 | { /* end of list */ } |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1188 | }; |
| 1189 | |
| 1190 | static struct macio_driver swim3_driver = |
| 1191 | { |
Benjamin Herrenschmidt | c2cdf6a | 2010-06-02 17:09:18 +1000 | [diff] [blame] | 1192 | .driver = { |
| 1193 | .name = "swim3", |
| 1194 | .of_match_table = swim3_match, |
| 1195 | }, |
Benjamin Herrenschmidt | 3e9a692 | 2006-07-03 17:25:26 +1000 | [diff] [blame] | 1196 | .probe = swim3_attach, |
| 1197 | #if 0 |
| 1198 | .suspend = swim3_suspend, |
| 1199 | .resume = swim3_resume, |
| 1200 | #endif |
| 1201 | }; |
| 1202 | |
| 1203 | |
| 1204 | int swim3_init(void) |
| 1205 | { |
| 1206 | macio_register_driver(&swim3_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | return 0; |
| 1208 | } |
| 1209 | |
| 1210 | module_init(swim3_init) |
| 1211 | |
| 1212 | MODULE_LICENSE("GPL"); |
| 1213 | MODULE_AUTHOR("Paul Mackerras"); |
| 1214 | MODULE_ALIAS_BLOCKDEV_MAJOR(FLOPPY_MAJOR); |