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