David S. Miller | 9b539c0 | 2007-07-28 23:39:30 -0700 | [diff] [blame] | 1 | /* floppy.h: Sparc specific parts of the Floppy driver. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
David S. Miller | 9b539c0 | 2007-07-28 23:39:30 -0700 | [diff] [blame] | 3 | * Copyright (C) 1996, 2007 David S. Miller (davem@davemloft.net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
| 5 | * |
| 6 | * Ultra/PCI support added: Sep 1997 Eddie C. Dost (ecd@skynet.be) |
| 7 | */ |
| 8 | |
| 9 | #ifndef __ASM_SPARC64_FLOPPY_H |
| 10 | #define __ASM_SPARC64_FLOPPY_H |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/init.h> |
David S. Miller | 9b539c0 | 2007-07-28 23:39:30 -0700 | [diff] [blame] | 13 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | #include <asm/page.h> |
| 16 | #include <asm/pgtable.h> |
| 17 | #include <asm/system.h> |
| 18 | #include <asm/idprom.h> |
| 19 | #include <asm/oplib.h> |
| 20 | #include <asm/auxio.h> |
| 21 | #include <asm/sbus.h> |
| 22 | #include <asm/irq.h> |
| 23 | |
| 24 | |
| 25 | /* |
| 26 | * Define this to enable exchanging drive 0 and 1 if only drive 1 is |
| 27 | * probed on PCI machines. |
| 28 | */ |
| 29 | #undef PCI_FDC_SWAP_DRIVES |
| 30 | |
| 31 | |
| 32 | /* References: |
| 33 | * 1) Netbsd Sun floppy driver. |
| 34 | * 2) NCR 82077 controller manual |
| 35 | * 3) Intel 82077 controller manual |
| 36 | */ |
| 37 | struct sun_flpy_controller { |
| 38 | volatile unsigned char status1_82077; /* Auxiliary Status reg. 1 */ |
| 39 | volatile unsigned char status2_82077; /* Auxiliary Status reg. 2 */ |
| 40 | volatile unsigned char dor_82077; /* Digital Output reg. */ |
| 41 | volatile unsigned char tapectl_82077; /* Tape Control reg */ |
| 42 | volatile unsigned char status_82077; /* Main Status Register. */ |
| 43 | #define drs_82077 status_82077 /* Digital Rate Select reg. */ |
| 44 | volatile unsigned char data_82077; /* Data fifo. */ |
| 45 | volatile unsigned char ___unused; |
| 46 | volatile unsigned char dir_82077; /* Digital Input reg. */ |
| 47 | #define dcr_82077 dir_82077 /* Config Control reg. */ |
| 48 | }; |
| 49 | |
| 50 | /* You'll only ever find one controller on an Ultra anyways. */ |
| 51 | static struct sun_flpy_controller *sun_fdc = (struct sun_flpy_controller *)-1; |
| 52 | unsigned long fdc_status; |
| 53 | static struct sbus_dev *floppy_sdev = NULL; |
| 54 | |
| 55 | struct sun_floppy_ops { |
| 56 | unsigned char (*fd_inb) (unsigned long port); |
| 57 | void (*fd_outb) (unsigned char value, unsigned long port); |
| 58 | void (*fd_enable_dma) (void); |
| 59 | void (*fd_disable_dma) (void); |
| 60 | void (*fd_set_dma_mode) (int); |
| 61 | void (*fd_set_dma_addr) (char *); |
| 62 | void (*fd_set_dma_count) (int); |
| 63 | unsigned int (*get_dma_residue) (void); |
| 64 | int (*fd_request_irq) (void); |
| 65 | void (*fd_free_irq) (void); |
| 66 | int (*fd_eject) (int); |
| 67 | }; |
| 68 | |
| 69 | static struct sun_floppy_ops sun_fdops; |
| 70 | |
| 71 | #define fd_inb(port) sun_fdops.fd_inb(port) |
| 72 | #define fd_outb(value,port) sun_fdops.fd_outb(value,port) |
| 73 | #define fd_enable_dma() sun_fdops.fd_enable_dma() |
| 74 | #define fd_disable_dma() sun_fdops.fd_disable_dma() |
| 75 | #define fd_request_dma() (0) /* nothing... */ |
| 76 | #define fd_free_dma() /* nothing... */ |
| 77 | #define fd_clear_dma_ff() /* nothing... */ |
| 78 | #define fd_set_dma_mode(mode) sun_fdops.fd_set_dma_mode(mode) |
| 79 | #define fd_set_dma_addr(addr) sun_fdops.fd_set_dma_addr(addr) |
| 80 | #define fd_set_dma_count(count) sun_fdops.fd_set_dma_count(count) |
| 81 | #define get_dma_residue(x) sun_fdops.get_dma_residue() |
| 82 | #define fd_cacheflush(addr, size) /* nothing... */ |
| 83 | #define fd_request_irq() sun_fdops.fd_request_irq() |
| 84 | #define fd_free_irq() sun_fdops.fd_free_irq() |
| 85 | #define fd_eject(drive) sun_fdops.fd_eject(drive) |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* Super paranoid... */ |
| 88 | #undef HAVE_DISABLE_HLT |
| 89 | |
| 90 | static int sun_floppy_types[2] = { 0, 0 }; |
| 91 | |
| 92 | /* Here is where we catch the floppy driver trying to initialize, |
| 93 | * therefore this is where we call the PROM device tree probing |
| 94 | * routine etc. on the Sparc. |
| 95 | */ |
| 96 | #define FLOPPY0_TYPE sun_floppy_init() |
| 97 | #define FLOPPY1_TYPE sun_floppy_types[1] |
| 98 | |
| 99 | #define FDC1 ((unsigned long)sun_fdc) |
| 100 | |
| 101 | #define N_FDC 1 |
| 102 | #define N_DRIVE 8 |
| 103 | |
| 104 | /* No 64k boundary crossing problems on the Sparc. */ |
| 105 | #define CROSS_64KB(a,s) (0) |
| 106 | |
| 107 | static unsigned char sun_82077_fd_inb(unsigned long port) |
| 108 | { |
| 109 | udelay(5); |
| 110 | switch(port & 7) { |
| 111 | default: |
| 112 | printk("floppy: Asked to read unknown port %lx\n", port); |
| 113 | panic("floppy: Port bolixed."); |
| 114 | case 4: /* FD_STATUS */ |
| 115 | return sbus_readb(&sun_fdc->status_82077) & ~STATUS_DMA; |
| 116 | case 5: /* FD_DATA */ |
| 117 | return sbus_readb(&sun_fdc->data_82077); |
| 118 | case 7: /* FD_DIR */ |
| 119 | /* XXX: Is DCL on 0x80 in sun4m? */ |
| 120 | return sbus_readb(&sun_fdc->dir_82077); |
| 121 | }; |
| 122 | panic("sun_82072_fd_inb: How did I get here?"); |
| 123 | } |
| 124 | |
| 125 | static void sun_82077_fd_outb(unsigned char value, unsigned long port) |
| 126 | { |
| 127 | udelay(5); |
| 128 | switch(port & 7) { |
| 129 | default: |
| 130 | printk("floppy: Asked to write to unknown port %lx\n", port); |
| 131 | panic("floppy: Port bolixed."); |
| 132 | case 2: /* FD_DOR */ |
| 133 | /* Happily, the 82077 has a real DOR register. */ |
| 134 | sbus_writeb(value, &sun_fdc->dor_82077); |
| 135 | break; |
| 136 | case 5: /* FD_DATA */ |
| 137 | sbus_writeb(value, &sun_fdc->data_82077); |
| 138 | break; |
| 139 | case 7: /* FD_DCR */ |
| 140 | sbus_writeb(value, &sun_fdc->dcr_82077); |
| 141 | break; |
| 142 | case 4: /* FD_STATUS */ |
| 143 | sbus_writeb(value, &sun_fdc->status_82077); |
| 144 | break; |
| 145 | }; |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | /* For pseudo-dma (Sun floppy drives have no real DMA available to |
| 150 | * them so we must eat the data fifo bytes directly ourselves) we have |
| 151 | * three state variables. doing_pdma tells our inline low-level |
| 152 | * assembly floppy interrupt entry point whether it should sit and eat |
| 153 | * bytes from the fifo or just transfer control up to the higher level |
| 154 | * floppy interrupt c-code. I tried very hard but I could not get the |
| 155 | * pseudo-dma to work in c-code without getting many overruns and |
| 156 | * underruns. If non-zero, doing_pdma encodes the direction of |
| 157 | * the transfer for debugging. 1=read 2=write |
| 158 | */ |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 159 | unsigned char *pdma_vaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | unsigned long pdma_size; |
| 161 | volatile int doing_pdma = 0; |
| 162 | |
| 163 | /* This is software state */ |
| 164 | char *pdma_base = NULL; |
| 165 | unsigned long pdma_areasize; |
| 166 | |
| 167 | /* Common routines to all controller types on the Sparc. */ |
| 168 | static void sun_fd_disable_dma(void) |
| 169 | { |
| 170 | doing_pdma = 0; |
| 171 | if (pdma_base) { |
| 172 | mmu_unlockarea(pdma_base, pdma_areasize); |
| 173 | pdma_base = NULL; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | static void sun_fd_set_dma_mode(int mode) |
| 178 | { |
| 179 | switch(mode) { |
| 180 | case DMA_MODE_READ: |
| 181 | doing_pdma = 1; |
| 182 | break; |
| 183 | case DMA_MODE_WRITE: |
| 184 | doing_pdma = 2; |
| 185 | break; |
| 186 | default: |
| 187 | printk("Unknown dma mode %d\n", mode); |
| 188 | panic("floppy: Giving up..."); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | static void sun_fd_set_dma_addr(char *buffer) |
| 193 | { |
| 194 | pdma_vaddr = buffer; |
| 195 | } |
| 196 | |
| 197 | static void sun_fd_set_dma_count(int length) |
| 198 | { |
| 199 | pdma_size = length; |
| 200 | } |
| 201 | |
| 202 | static void sun_fd_enable_dma(void) |
| 203 | { |
| 204 | pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size); |
| 205 | pdma_base = pdma_vaddr; |
| 206 | pdma_areasize = pdma_size; |
| 207 | } |
| 208 | |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 209 | irqreturn_t sparc_floppy_irq(int irq, void *dev_cookie) |
David S. Miller | 3505599 | 2006-06-25 01:32:25 -0700 | [diff] [blame] | 210 | { |
| 211 | if (likely(doing_pdma)) { |
| 212 | void __iomem *stat = (void __iomem *) fdc_status; |
| 213 | unsigned char *vaddr = pdma_vaddr; |
| 214 | unsigned long size = pdma_size; |
| 215 | u8 val; |
| 216 | |
| 217 | while (size) { |
| 218 | val = readb(stat); |
| 219 | if (unlikely(!(val & 0x80))) { |
| 220 | pdma_vaddr = vaddr; |
| 221 | pdma_size = size; |
| 222 | return IRQ_HANDLED; |
| 223 | } |
| 224 | if (unlikely(!(val & 0x20))) { |
| 225 | pdma_vaddr = vaddr; |
| 226 | pdma_size = size; |
| 227 | doing_pdma = 0; |
| 228 | goto main_interrupt; |
| 229 | } |
| 230 | if (val & 0x40) { |
| 231 | /* read */ |
| 232 | *vaddr++ = readb(stat + 1); |
| 233 | } else { |
| 234 | unsigned char data = *vaddr++; |
| 235 | |
| 236 | /* write */ |
| 237 | writeb(data, stat + 1); |
| 238 | } |
| 239 | size--; |
| 240 | } |
| 241 | |
| 242 | pdma_vaddr = vaddr; |
| 243 | pdma_size = size; |
| 244 | |
| 245 | /* Send Terminal Count pulse to floppy controller. */ |
| 246 | val = readb(auxio_register); |
| 247 | val |= AUXIO_AUX1_FTCNT; |
| 248 | writeb(val, auxio_register); |
| 249 | val &= ~AUXIO_AUX1_FTCNT; |
| 250 | writeb(val, auxio_register); |
| 251 | |
| 252 | doing_pdma = 0; |
| 253 | } |
| 254 | |
| 255 | main_interrupt: |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 256 | return floppy_interrupt(irq, dev_cookie); |
David S. Miller | 3505599 | 2006-06-25 01:32:25 -0700 | [diff] [blame] | 257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | static int sun_fd_request_irq(void) |
| 260 | { |
| 261 | static int once = 0; |
| 262 | int error; |
| 263 | |
| 264 | if(!once) { |
| 265 | once = 1; |
| 266 | |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 267 | error = request_irq(FLOPPY_IRQ, sparc_floppy_irq, |
Thomas Gleixner | d356d7f4 | 2006-07-01 19:29:26 -0700 | [diff] [blame] | 268 | IRQF_DISABLED, "floppy", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | return ((error == 0) ? 0 : -1); |
| 271 | } |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | static void sun_fd_free_irq(void) |
| 276 | { |
| 277 | } |
| 278 | |
| 279 | static unsigned int sun_get_dma_residue(void) |
| 280 | { |
| 281 | /* XXX This isn't really correct. XXX */ |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | static int sun_fd_eject(int drive) |
| 286 | { |
| 287 | set_dor(0x00, 0xff, 0x90); |
| 288 | udelay(500); |
| 289 | set_dor(0x00, 0x6f, 0x00); |
| 290 | udelay(500); |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | #ifdef CONFIG_PCI |
| 295 | #include <asm/ebus.h> |
| 296 | #include <asm/isa.h> |
| 297 | #include <asm/ns87303.h> |
| 298 | |
| 299 | static struct ebus_dma_info sun_pci_fd_ebus_dma; |
| 300 | static struct pci_dev *sun_pci_ebus_dev; |
| 301 | static int sun_pci_broken_drive = -1; |
| 302 | |
| 303 | struct sun_pci_dma_op { |
| 304 | unsigned int addr; |
| 305 | int len; |
| 306 | int direction; |
| 307 | char *buf; |
| 308 | }; |
| 309 | static struct sun_pci_dma_op sun_pci_dma_current = { -1U, 0, 0, NULL}; |
| 310 | static struct sun_pci_dma_op sun_pci_dma_pending = { -1U, 0, 0, NULL}; |
| 311 | |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 312 | extern irqreturn_t floppy_interrupt(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | static unsigned char sun_pci_fd_inb(unsigned long port) |
| 315 | { |
| 316 | udelay(5); |
| 317 | return inb(port); |
| 318 | } |
| 319 | |
| 320 | static void sun_pci_fd_outb(unsigned char val, unsigned long port) |
| 321 | { |
| 322 | udelay(5); |
| 323 | outb(val, port); |
| 324 | } |
| 325 | |
| 326 | static void sun_pci_fd_broken_outb(unsigned char val, unsigned long port) |
| 327 | { |
| 328 | udelay(5); |
| 329 | /* |
| 330 | * XXX: Due to SUN's broken floppy connector on AX and AXi |
| 331 | * we need to turn on MOTOR_0 also, if the floppy is |
| 332 | * jumpered to DS1 (like most PC floppies are). I hope |
| 333 | * this does not hurt correct hardware like the AXmp. |
| 334 | * (Eddie, Sep 12 1998). |
| 335 | */ |
| 336 | if (port == ((unsigned long)sun_fdc) + 2) { |
| 337 | if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x20)) { |
| 338 | val |= 0x10; |
| 339 | } |
| 340 | } |
| 341 | outb(val, port); |
| 342 | } |
| 343 | |
| 344 | #ifdef PCI_FDC_SWAP_DRIVES |
| 345 | static void sun_pci_fd_lde_broken_outb(unsigned char val, unsigned long port) |
| 346 | { |
| 347 | udelay(5); |
| 348 | /* |
| 349 | * XXX: Due to SUN's broken floppy connector on AX and AXi |
| 350 | * we need to turn on MOTOR_0 also, if the floppy is |
| 351 | * jumpered to DS1 (like most PC floppies are). I hope |
| 352 | * this does not hurt correct hardware like the AXmp. |
| 353 | * (Eddie, Sep 12 1998). |
| 354 | */ |
| 355 | if (port == ((unsigned long)sun_fdc) + 2) { |
| 356 | if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x10)) { |
| 357 | val &= ~(0x03); |
| 358 | val |= 0x21; |
| 359 | } |
| 360 | } |
| 361 | outb(val, port); |
| 362 | } |
| 363 | #endif /* PCI_FDC_SWAP_DRIVES */ |
| 364 | |
| 365 | static void sun_pci_fd_enable_dma(void) |
| 366 | { |
| 367 | BUG_ON((NULL == sun_pci_dma_pending.buf) || |
| 368 | (0 == sun_pci_dma_pending.len) || |
| 369 | (0 == sun_pci_dma_pending.direction)); |
| 370 | |
| 371 | sun_pci_dma_current.buf = sun_pci_dma_pending.buf; |
| 372 | sun_pci_dma_current.len = sun_pci_dma_pending.len; |
| 373 | sun_pci_dma_current.direction = sun_pci_dma_pending.direction; |
| 374 | |
| 375 | sun_pci_dma_pending.buf = NULL; |
| 376 | sun_pci_dma_pending.len = 0; |
| 377 | sun_pci_dma_pending.direction = 0; |
| 378 | sun_pci_dma_pending.addr = -1U; |
| 379 | |
| 380 | sun_pci_dma_current.addr = |
| 381 | pci_map_single(sun_pci_ebus_dev, |
| 382 | sun_pci_dma_current.buf, |
| 383 | sun_pci_dma_current.len, |
| 384 | sun_pci_dma_current.direction); |
| 385 | |
| 386 | ebus_dma_enable(&sun_pci_fd_ebus_dma, 1); |
| 387 | |
| 388 | if (ebus_dma_request(&sun_pci_fd_ebus_dma, |
| 389 | sun_pci_dma_current.addr, |
| 390 | sun_pci_dma_current.len)) |
| 391 | BUG(); |
| 392 | } |
| 393 | |
| 394 | static void sun_pci_fd_disable_dma(void) |
| 395 | { |
| 396 | ebus_dma_enable(&sun_pci_fd_ebus_dma, 0); |
| 397 | if (sun_pci_dma_current.addr != -1U) |
| 398 | pci_unmap_single(sun_pci_ebus_dev, |
| 399 | sun_pci_dma_current.addr, |
| 400 | sun_pci_dma_current.len, |
| 401 | sun_pci_dma_current.direction); |
| 402 | sun_pci_dma_current.addr = -1U; |
| 403 | } |
| 404 | |
| 405 | static void sun_pci_fd_set_dma_mode(int mode) |
| 406 | { |
| 407 | if (mode == DMA_MODE_WRITE) |
| 408 | sun_pci_dma_pending.direction = PCI_DMA_TODEVICE; |
| 409 | else |
| 410 | sun_pci_dma_pending.direction = PCI_DMA_FROMDEVICE; |
| 411 | |
| 412 | ebus_dma_prepare(&sun_pci_fd_ebus_dma, mode != DMA_MODE_WRITE); |
| 413 | } |
| 414 | |
| 415 | static void sun_pci_fd_set_dma_count(int length) |
| 416 | { |
| 417 | sun_pci_dma_pending.len = length; |
| 418 | } |
| 419 | |
| 420 | static void sun_pci_fd_set_dma_addr(char *buffer) |
| 421 | { |
| 422 | sun_pci_dma_pending.buf = buffer; |
| 423 | } |
| 424 | |
| 425 | static unsigned int sun_pci_get_dma_residue(void) |
| 426 | { |
| 427 | return ebus_dma_residue(&sun_pci_fd_ebus_dma); |
| 428 | } |
| 429 | |
| 430 | static int sun_pci_fd_request_irq(void) |
| 431 | { |
| 432 | return ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 1); |
| 433 | } |
| 434 | |
| 435 | static void sun_pci_fd_free_irq(void) |
| 436 | { |
| 437 | ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 0); |
| 438 | } |
| 439 | |
| 440 | static int sun_pci_fd_eject(int drive) |
| 441 | { |
| 442 | return -EINVAL; |
| 443 | } |
| 444 | |
| 445 | void sun_pci_fd_dma_callback(struct ebus_dma_info *p, int event, void *cookie) |
| 446 | { |
Al Viro | 6d24c8d | 2006-10-08 08:23:28 -0400 | [diff] [blame] | 447 | floppy_interrupt(0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /* |
| 451 | * Floppy probing, we'd like to use /dev/fd0 for a single Floppy on PCI, |
| 452 | * even if this is configured using DS1, thus looks like /dev/fd1 with |
| 453 | * the cabling used in Ultras. |
| 454 | */ |
| 455 | #define DOR (port + 2) |
| 456 | #define MSR (port + 4) |
| 457 | #define FIFO (port + 5) |
| 458 | |
| 459 | static void sun_pci_fd_out_byte(unsigned long port, unsigned char val, |
| 460 | unsigned long reg) |
| 461 | { |
| 462 | unsigned char status; |
| 463 | int timeout = 1000; |
| 464 | |
| 465 | while (!((status = inb(MSR)) & 0x80) && --timeout) |
| 466 | udelay(100); |
| 467 | outb(val, reg); |
| 468 | } |
| 469 | |
| 470 | static unsigned char sun_pci_fd_sensei(unsigned long port) |
| 471 | { |
| 472 | unsigned char result[2] = { 0x70, 0x00 }; |
| 473 | unsigned char status; |
| 474 | int i = 0; |
| 475 | |
| 476 | sun_pci_fd_out_byte(port, 0x08, FIFO); |
| 477 | do { |
| 478 | int timeout = 1000; |
| 479 | |
| 480 | while (!((status = inb(MSR)) & 0x80) && --timeout) |
| 481 | udelay(100); |
| 482 | |
| 483 | if (!timeout) |
| 484 | break; |
| 485 | |
| 486 | if ((status & 0xf0) == 0xd0) |
| 487 | result[i++] = inb(FIFO); |
| 488 | else |
| 489 | break; |
| 490 | } while (i < 2); |
| 491 | |
| 492 | return result[0]; |
| 493 | } |
| 494 | |
| 495 | static void sun_pci_fd_reset(unsigned long port) |
| 496 | { |
| 497 | unsigned char mask = 0x00; |
| 498 | unsigned char status; |
| 499 | int timeout = 10000; |
| 500 | |
| 501 | outb(0x80, MSR); |
| 502 | do { |
| 503 | status = sun_pci_fd_sensei(port); |
| 504 | if ((status & 0xc0) == 0xc0) |
| 505 | mask |= 1 << (status & 0x03); |
| 506 | else |
| 507 | udelay(100); |
| 508 | } while ((mask != 0x0f) && --timeout); |
| 509 | } |
| 510 | |
| 511 | static int sun_pci_fd_test_drive(unsigned long port, int drive) |
| 512 | { |
| 513 | unsigned char status, data; |
| 514 | int timeout = 1000; |
| 515 | int ready; |
| 516 | |
| 517 | sun_pci_fd_reset(port); |
| 518 | |
| 519 | data = (0x10 << drive) | 0x0c | drive; |
| 520 | sun_pci_fd_out_byte(port, data, DOR); |
| 521 | |
| 522 | sun_pci_fd_out_byte(port, 0x07, FIFO); |
| 523 | sun_pci_fd_out_byte(port, drive & 0x03, FIFO); |
| 524 | |
| 525 | do { |
| 526 | udelay(100); |
| 527 | status = sun_pci_fd_sensei(port); |
| 528 | } while (((status & 0xc0) == 0x80) && --timeout); |
| 529 | |
| 530 | if (!timeout) |
| 531 | ready = 0; |
| 532 | else |
| 533 | ready = (status & 0x10) ? 0 : 1; |
| 534 | |
| 535 | sun_pci_fd_reset(port); |
| 536 | return ready; |
| 537 | } |
| 538 | #undef FIFO |
| 539 | #undef MSR |
| 540 | #undef DOR |
| 541 | |
| 542 | #endif /* CONFIG_PCI */ |
| 543 | |
| 544 | #ifdef CONFIG_PCI |
| 545 | static int __init ebus_fdthree_p(struct linux_ebus_device *edev) |
| 546 | { |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 547 | if (!strcmp(edev->prom_node->name, "fdthree")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | return 1; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 549 | if (!strcmp(edev->prom_node->name, "floppy")) { |
Stephen Rothwell | 66f3cb7 | 2007-03-29 00:50:29 -0700 | [diff] [blame] | 550 | const char *compat; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 551 | |
| 552 | compat = of_get_property(edev->prom_node, |
| 553 | "compatible", NULL); |
| 554 | if (compat && !strcmp(compat, "fdthree")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | return 1; |
| 556 | } |
| 557 | return 0; |
| 558 | } |
| 559 | #endif |
| 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | static unsigned long __init sun_floppy_init(void) |
| 562 | { |
| 563 | char state[128]; |
| 564 | struct sbus_bus *bus; |
| 565 | struct sbus_dev *sdev = NULL; |
| 566 | static int initialized = 0; |
| 567 | |
| 568 | if (initialized) |
| 569 | return sun_floppy_types[0]; |
| 570 | initialized = 1; |
| 571 | |
| 572 | for_all_sbusdev (sdev, bus) { |
| 573 | if (!strcmp(sdev->prom_name, "SUNW,fdtwo")) |
| 574 | break; |
| 575 | } |
| 576 | if(sdev) { |
| 577 | floppy_sdev = sdev; |
| 578 | FLOPPY_IRQ = sdev->irqs[0]; |
| 579 | } else { |
| 580 | #ifdef CONFIG_PCI |
| 581 | struct linux_ebus *ebus; |
| 582 | struct linux_ebus_device *edev = NULL; |
| 583 | unsigned long config = 0; |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 584 | void __iomem *auxio_reg; |
Stephen Rothwell | 66f3cb7 | 2007-03-29 00:50:29 -0700 | [diff] [blame] | 585 | const char *state_prop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
| 587 | for_each_ebus(ebus) { |
| 588 | for_each_ebusdev(edev, ebus) { |
| 589 | if (ebus_fdthree_p(edev)) |
| 590 | goto ebus_done; |
| 591 | } |
| 592 | } |
| 593 | ebus_done: |
David S. Miller | 0eb78f0 | 2008-04-26 03:35:02 -0700 | [diff] [blame^] | 594 | if (!edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 597 | state_prop = of_get_property(edev->prom_node, "status", NULL); |
| 598 | if (state_prop && !strncmp(state_prop, "disabled", 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | return 0; |
| 600 | |
| 601 | FLOPPY_IRQ = edev->irqs[0]; |
| 602 | |
| 603 | /* Make sure the high density bit is set, some systems |
| 604 | * (most notably Ultra5/Ultra10) come up with it clear. |
| 605 | */ |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 606 | auxio_reg = (void __iomem *) edev->resource[2].start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | writel(readl(auxio_reg)|0x2, auxio_reg); |
| 608 | |
| 609 | sun_pci_ebus_dev = ebus->self; |
| 610 | |
| 611 | spin_lock_init(&sun_pci_fd_ebus_dma.lock); |
| 612 | |
| 613 | /* XXX ioremap */ |
David S. Miller | 63b6145 | 2005-06-27 17:04:45 -0700 | [diff] [blame] | 614 | sun_pci_fd_ebus_dma.regs = (void __iomem *) |
| 615 | edev->resource[1].start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | if (!sun_pci_fd_ebus_dma.regs) |
| 617 | return 0; |
| 618 | |
| 619 | sun_pci_fd_ebus_dma.flags = (EBUS_DMA_FLAG_USE_EBDMA_HANDLER | |
| 620 | EBUS_DMA_FLAG_TCI_DISABLE); |
| 621 | sun_pci_fd_ebus_dma.callback = sun_pci_fd_dma_callback; |
| 622 | sun_pci_fd_ebus_dma.client_cookie = NULL; |
| 623 | sun_pci_fd_ebus_dma.irq = FLOPPY_IRQ; |
| 624 | strcpy(sun_pci_fd_ebus_dma.name, "floppy"); |
| 625 | if (ebus_dma_register(&sun_pci_fd_ebus_dma)) |
| 626 | return 0; |
| 627 | |
| 628 | /* XXX ioremap */ |
| 629 | sun_fdc = (struct sun_flpy_controller *)edev->resource[0].start; |
| 630 | |
| 631 | sun_fdops.fd_inb = sun_pci_fd_inb; |
| 632 | sun_fdops.fd_outb = sun_pci_fd_outb; |
| 633 | |
| 634 | can_use_virtual_dma = use_virtual_dma = 0; |
| 635 | sun_fdops.fd_enable_dma = sun_pci_fd_enable_dma; |
| 636 | sun_fdops.fd_disable_dma = sun_pci_fd_disable_dma; |
| 637 | sun_fdops.fd_set_dma_mode = sun_pci_fd_set_dma_mode; |
| 638 | sun_fdops.fd_set_dma_addr = sun_pci_fd_set_dma_addr; |
| 639 | sun_fdops.fd_set_dma_count = sun_pci_fd_set_dma_count; |
| 640 | sun_fdops.get_dma_residue = sun_pci_get_dma_residue; |
| 641 | |
| 642 | sun_fdops.fd_request_irq = sun_pci_fd_request_irq; |
| 643 | sun_fdops.fd_free_irq = sun_pci_fd_free_irq; |
| 644 | |
| 645 | sun_fdops.fd_eject = sun_pci_fd_eject; |
| 646 | |
| 647 | fdc_status = (unsigned long) &sun_fdc->status_82077; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
| 649 | /* |
| 650 | * XXX: Find out on which machines this is really needed. |
| 651 | */ |
| 652 | if (1) { |
| 653 | sun_pci_broken_drive = 1; |
| 654 | sun_fdops.fd_outb = sun_pci_fd_broken_outb; |
| 655 | } |
| 656 | |
| 657 | allowed_drive_mask = 0; |
| 658 | if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 0)) |
| 659 | sun_floppy_types[0] = 4; |
| 660 | if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 1)) |
| 661 | sun_floppy_types[1] = 4; |
| 662 | |
| 663 | /* |
| 664 | * Find NS87303 SuperIO config registers (through ecpp). |
| 665 | */ |
| 666 | for_each_ebus(ebus) { |
| 667 | for_each_ebusdev(edev, ebus) { |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 668 | if (!strcmp(edev->prom_node->name, "ecpp")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | config = edev->resource[1].start; |
| 670 | goto config_done; |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | config_done: |
| 675 | |
| 676 | /* |
| 677 | * Sanity check, is this really the NS87303? |
| 678 | */ |
| 679 | switch (config & 0x3ff) { |
| 680 | case 0x02e: |
| 681 | case 0x15c: |
| 682 | case 0x26e: |
| 683 | case 0x398: |
| 684 | break; |
| 685 | default: |
| 686 | config = 0; |
| 687 | } |
| 688 | |
| 689 | if (!config) |
| 690 | return sun_floppy_types[0]; |
| 691 | |
| 692 | /* Enable PC-AT mode. */ |
| 693 | ns87303_modify(config, ASC, 0, 0xc0); |
| 694 | |
| 695 | #ifdef PCI_FDC_SWAP_DRIVES |
| 696 | /* |
| 697 | * If only Floppy 1 is present, swap drives. |
| 698 | */ |
| 699 | if (!sun_floppy_types[0] && sun_floppy_types[1]) { |
| 700 | /* |
| 701 | * Set the drive exchange bit in FCR on NS87303, |
Alexey Dobriyan | 7f927fc | 2006-03-28 01:56:53 -0800 | [diff] [blame] | 702 | * make sure other bits are sane before doing so. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | */ |
| 704 | ns87303_modify(config, FER, FER_EDM, 0); |
| 705 | ns87303_modify(config, ASC, ASC_DRV2_SEL, 0); |
| 706 | ns87303_modify(config, FCR, 0, FCR_LDE); |
| 707 | |
| 708 | config = sun_floppy_types[0]; |
| 709 | sun_floppy_types[0] = sun_floppy_types[1]; |
| 710 | sun_floppy_types[1] = config; |
| 711 | |
| 712 | if (sun_pci_broken_drive != -1) { |
| 713 | sun_pci_broken_drive = 1 - sun_pci_broken_drive; |
| 714 | sun_fdops.fd_outb = sun_pci_fd_lde_broken_outb; |
| 715 | } |
| 716 | } |
| 717 | #endif /* PCI_FDC_SWAP_DRIVES */ |
| 718 | |
| 719 | return sun_floppy_types[0]; |
| 720 | #else |
| 721 | return 0; |
| 722 | #endif |
| 723 | } |
| 724 | prom_getproperty(sdev->prom_node, "status", state, sizeof(state)); |
| 725 | if(!strncmp(state, "disabled", 8)) |
| 726 | return 0; |
| 727 | |
| 728 | /* |
| 729 | * We cannot do sbus_ioremap here: it does request_region, |
| 730 | * which the generic floppy driver tries to do once again. |
| 731 | * But we must use the sdev resource values as they have |
| 732 | * had parent ranges applied. |
| 733 | */ |
| 734 | sun_fdc = (struct sun_flpy_controller *) |
| 735 | (sdev->resource[0].start + |
| 736 | ((sdev->resource[0].flags & 0x1ffUL) << 32UL)); |
| 737 | |
| 738 | /* Last minute sanity check... */ |
| 739 | if(sbus_readb(&sun_fdc->status1_82077) == 0xff) { |
| 740 | sun_fdc = (struct sun_flpy_controller *)-1; |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | sun_fdops.fd_inb = sun_82077_fd_inb; |
| 745 | sun_fdops.fd_outb = sun_82077_fd_outb; |
| 746 | |
| 747 | can_use_virtual_dma = use_virtual_dma = 1; |
| 748 | sun_fdops.fd_enable_dma = sun_fd_enable_dma; |
| 749 | sun_fdops.fd_disable_dma = sun_fd_disable_dma; |
| 750 | sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode; |
| 751 | sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr; |
| 752 | sun_fdops.fd_set_dma_count = sun_fd_set_dma_count; |
| 753 | sun_fdops.get_dma_residue = sun_get_dma_residue; |
| 754 | |
| 755 | sun_fdops.fd_request_irq = sun_fd_request_irq; |
| 756 | sun_fdops.fd_free_irq = sun_fd_free_irq; |
| 757 | |
| 758 | sun_fdops.fd_eject = sun_fd_eject; |
| 759 | |
| 760 | fdc_status = (unsigned long) &sun_fdc->status_82077; |
| 761 | |
| 762 | /* Success... */ |
| 763 | allowed_drive_mask = 0x01; |
| 764 | sun_floppy_types[0] = 4; |
| 765 | sun_floppy_types[1] = 0; |
| 766 | |
| 767 | return sun_floppy_types[0]; |
| 768 | } |
| 769 | |
| 770 | #define EXTRA_FLOPPY_PARAMS |
| 771 | |
David S. Miller | 78ad0b8 | 2007-03-04 20:36:18 -0800 | [diff] [blame] | 772 | static DEFINE_SPINLOCK(dma_spin_lock); |
| 773 | |
| 774 | #define claim_dma_lock() \ |
| 775 | ({ unsigned long flags; \ |
| 776 | spin_lock_irqsave(&dma_spin_lock, flags); \ |
| 777 | flags; \ |
| 778 | }) |
| 779 | |
| 780 | #define release_dma_lock(__flags) \ |
| 781 | spin_unlock_irqrestore(&dma_spin_lock, __flags); |
| 782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | #endif /* !(__ASM_SPARC64_FLOPPY_H) */ |