[PATCH] bcm43xx: Fix array overrun in bcm43xx_geo_init
[linux-2.6/kmemtrace.git] / include / asm-sparc64 / floppy.h
blob6a95d5d0c57613c5760773123ace45b08d765456
1 /* $Id: floppy.h,v 1.32 2001/10/26 17:59:36 davem Exp $
2 * asm-sparc64/floppy.h: Sparc specific parts of the Floppy driver.
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 * Ultra/PCI support added: Sep 1997 Eddie C. Dost (ecd@skynet.be)
8 */
10 #ifndef __ASM_SPARC64_FLOPPY_H
11 #define __ASM_SPARC64_FLOPPY_H
13 #include <linux/config.h>
14 #include <linux/init.h>
16 #include <asm/page.h>
17 #include <asm/pgtable.h>
18 #include <asm/system.h>
19 #include <asm/idprom.h>
20 #include <asm/oplib.h>
21 #include <asm/auxio.h>
22 #include <asm/sbus.h>
23 #include <asm/irq.h>
27 * Define this to enable exchanging drive 0 and 1 if only drive 1 is
28 * probed on PCI machines.
30 #undef PCI_FDC_SWAP_DRIVES
33 /* References:
34 * 1) Netbsd Sun floppy driver.
35 * 2) NCR 82077 controller manual
36 * 3) Intel 82077 controller manual
38 struct sun_flpy_controller {
39 volatile unsigned char status1_82077; /* Auxiliary Status reg. 1 */
40 volatile unsigned char status2_82077; /* Auxiliary Status reg. 2 */
41 volatile unsigned char dor_82077; /* Digital Output reg. */
42 volatile unsigned char tapectl_82077; /* Tape Control reg */
43 volatile unsigned char status_82077; /* Main Status Register. */
44 #define drs_82077 status_82077 /* Digital Rate Select reg. */
45 volatile unsigned char data_82077; /* Data fifo. */
46 volatile unsigned char ___unused;
47 volatile unsigned char dir_82077; /* Digital Input reg. */
48 #define dcr_82077 dir_82077 /* Config Control reg. */
51 /* You'll only ever find one controller on an Ultra anyways. */
52 static struct sun_flpy_controller *sun_fdc = (struct sun_flpy_controller *)-1;
53 unsigned long fdc_status;
54 static struct sbus_dev *floppy_sdev = NULL;
56 struct sun_floppy_ops {
57 unsigned char (*fd_inb) (unsigned long port);
58 void (*fd_outb) (unsigned char value, unsigned long port);
59 void (*fd_enable_dma) (void);
60 void (*fd_disable_dma) (void);
61 void (*fd_set_dma_mode) (int);
62 void (*fd_set_dma_addr) (char *);
63 void (*fd_set_dma_count) (int);
64 unsigned int (*get_dma_residue) (void);
65 int (*fd_request_irq) (void);
66 void (*fd_free_irq) (void);
67 int (*fd_eject) (int);
70 static struct sun_floppy_ops sun_fdops;
72 #define fd_inb(port) sun_fdops.fd_inb(port)
73 #define fd_outb(value,port) sun_fdops.fd_outb(value,port)
74 #define fd_enable_dma() sun_fdops.fd_enable_dma()
75 #define fd_disable_dma() sun_fdops.fd_disable_dma()
76 #define fd_request_dma() (0) /* nothing... */
77 #define fd_free_dma() /* nothing... */
78 #define fd_clear_dma_ff() /* nothing... */
79 #define fd_set_dma_mode(mode) sun_fdops.fd_set_dma_mode(mode)
80 #define fd_set_dma_addr(addr) sun_fdops.fd_set_dma_addr(addr)
81 #define fd_set_dma_count(count) sun_fdops.fd_set_dma_count(count)
82 #define get_dma_residue(x) sun_fdops.get_dma_residue()
83 #define fd_cacheflush(addr, size) /* nothing... */
84 #define fd_request_irq() sun_fdops.fd_request_irq()
85 #define fd_free_irq() sun_fdops.fd_free_irq()
86 #define fd_eject(drive) sun_fdops.fd_eject(drive)
88 static int FLOPPY_MOTOR_MASK = 0x10;
90 /* Super paranoid... */
91 #undef HAVE_DISABLE_HLT
93 static int sun_floppy_types[2] = { 0, 0 };
95 /* Here is where we catch the floppy driver trying to initialize,
96 * therefore this is where we call the PROM device tree probing
97 * routine etc. on the Sparc.
99 #define FLOPPY0_TYPE sun_floppy_init()
100 #define FLOPPY1_TYPE sun_floppy_types[1]
102 #define FDC1 ((unsigned long)sun_fdc)
104 #define N_FDC 1
105 #define N_DRIVE 8
107 /* No 64k boundary crossing problems on the Sparc. */
108 #define CROSS_64KB(a,s) (0)
110 static unsigned char sun_82077_fd_inb(unsigned long port)
112 udelay(5);
113 switch(port & 7) {
114 default:
115 printk("floppy: Asked to read unknown port %lx\n", port);
116 panic("floppy: Port bolixed.");
117 case 4: /* FD_STATUS */
118 return sbus_readb(&sun_fdc->status_82077) & ~STATUS_DMA;
119 case 5: /* FD_DATA */
120 return sbus_readb(&sun_fdc->data_82077);
121 case 7: /* FD_DIR */
122 /* XXX: Is DCL on 0x80 in sun4m? */
123 return sbus_readb(&sun_fdc->dir_82077);
125 panic("sun_82072_fd_inb: How did I get here?");
128 static void sun_82077_fd_outb(unsigned char value, unsigned long port)
130 udelay(5);
131 switch(port & 7) {
132 default:
133 printk("floppy: Asked to write to unknown port %lx\n", port);
134 panic("floppy: Port bolixed.");
135 case 2: /* FD_DOR */
136 /* Happily, the 82077 has a real DOR register. */
137 sbus_writeb(value, &sun_fdc->dor_82077);
138 break;
139 case 5: /* FD_DATA */
140 sbus_writeb(value, &sun_fdc->data_82077);
141 break;
142 case 7: /* FD_DCR */
143 sbus_writeb(value, &sun_fdc->dcr_82077);
144 break;
145 case 4: /* FD_STATUS */
146 sbus_writeb(value, &sun_fdc->status_82077);
147 break;
149 return;
152 /* For pseudo-dma (Sun floppy drives have no real DMA available to
153 * them so we must eat the data fifo bytes directly ourselves) we have
154 * three state variables. doing_pdma tells our inline low-level
155 * assembly floppy interrupt entry point whether it should sit and eat
156 * bytes from the fifo or just transfer control up to the higher level
157 * floppy interrupt c-code. I tried very hard but I could not get the
158 * pseudo-dma to work in c-code without getting many overruns and
159 * underruns. If non-zero, doing_pdma encodes the direction of
160 * the transfer for debugging. 1=read 2=write
162 unsigned char *pdma_vaddr;
163 unsigned long pdma_size;
164 volatile int doing_pdma = 0;
166 /* This is software state */
167 char *pdma_base = NULL;
168 unsigned long pdma_areasize;
170 /* Common routines to all controller types on the Sparc. */
171 static void sun_fd_disable_dma(void)
173 doing_pdma = 0;
174 if (pdma_base) {
175 mmu_unlockarea(pdma_base, pdma_areasize);
176 pdma_base = NULL;
180 static void sun_fd_set_dma_mode(int mode)
182 switch(mode) {
183 case DMA_MODE_READ:
184 doing_pdma = 1;
185 break;
186 case DMA_MODE_WRITE:
187 doing_pdma = 2;
188 break;
189 default:
190 printk("Unknown dma mode %d\n", mode);
191 panic("floppy: Giving up...");
195 static void sun_fd_set_dma_addr(char *buffer)
197 pdma_vaddr = buffer;
200 static void sun_fd_set_dma_count(int length)
202 pdma_size = length;
205 static void sun_fd_enable_dma(void)
207 pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
208 pdma_base = pdma_vaddr;
209 pdma_areasize = pdma_size;
212 extern irqreturn_t sparc_floppy_irq(int, void *, struct pt_regs *);
214 static int sun_fd_request_irq(void)
216 static int once = 0;
217 int error;
219 if(!once) {
220 once = 1;
222 error = request_irq(FLOPPY_IRQ, sparc_floppy_irq,
223 SA_INTERRUPT, "floppy", NULL);
225 return ((error == 0) ? 0 : -1);
227 return 0;
230 static void sun_fd_free_irq(void)
234 static unsigned int sun_get_dma_residue(void)
236 /* XXX This isn't really correct. XXX */
237 return 0;
240 static int sun_fd_eject(int drive)
242 set_dor(0x00, 0xff, 0x90);
243 udelay(500);
244 set_dor(0x00, 0x6f, 0x00);
245 udelay(500);
246 return 0;
249 #ifdef CONFIG_PCI
250 #include <asm/ebus.h>
251 #include <asm/isa.h>
252 #include <asm/ns87303.h>
254 static struct ebus_dma_info sun_pci_fd_ebus_dma;
255 static struct pci_dev *sun_pci_ebus_dev;
256 static int sun_pci_broken_drive = -1;
258 struct sun_pci_dma_op {
259 unsigned int addr;
260 int len;
261 int direction;
262 char *buf;
264 static struct sun_pci_dma_op sun_pci_dma_current = { -1U, 0, 0, NULL};
265 static struct sun_pci_dma_op sun_pci_dma_pending = { -1U, 0, 0, NULL};
267 extern irqreturn_t floppy_interrupt(int irq, void *dev_id, struct pt_regs *regs);
269 static unsigned char sun_pci_fd_inb(unsigned long port)
271 udelay(5);
272 return inb(port);
275 static void sun_pci_fd_outb(unsigned char val, unsigned long port)
277 udelay(5);
278 outb(val, port);
281 static void sun_pci_fd_broken_outb(unsigned char val, unsigned long port)
283 udelay(5);
285 * XXX: Due to SUN's broken floppy connector on AX and AXi
286 * we need to turn on MOTOR_0 also, if the floppy is
287 * jumpered to DS1 (like most PC floppies are). I hope
288 * this does not hurt correct hardware like the AXmp.
289 * (Eddie, Sep 12 1998).
291 if (port == ((unsigned long)sun_fdc) + 2) {
292 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x20)) {
293 val |= 0x10;
296 outb(val, port);
299 #ifdef PCI_FDC_SWAP_DRIVES
300 static void sun_pci_fd_lde_broken_outb(unsigned char val, unsigned long port)
302 udelay(5);
304 * XXX: Due to SUN's broken floppy connector on AX and AXi
305 * we need to turn on MOTOR_0 also, if the floppy is
306 * jumpered to DS1 (like most PC floppies are). I hope
307 * this does not hurt correct hardware like the AXmp.
308 * (Eddie, Sep 12 1998).
310 if (port == ((unsigned long)sun_fdc) + 2) {
311 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x10)) {
312 val &= ~(0x03);
313 val |= 0x21;
316 outb(val, port);
318 #endif /* PCI_FDC_SWAP_DRIVES */
320 static void sun_pci_fd_enable_dma(void)
322 BUG_ON((NULL == sun_pci_dma_pending.buf) ||
323 (0 == sun_pci_dma_pending.len) ||
324 (0 == sun_pci_dma_pending.direction));
326 sun_pci_dma_current.buf = sun_pci_dma_pending.buf;
327 sun_pci_dma_current.len = sun_pci_dma_pending.len;
328 sun_pci_dma_current.direction = sun_pci_dma_pending.direction;
330 sun_pci_dma_pending.buf = NULL;
331 sun_pci_dma_pending.len = 0;
332 sun_pci_dma_pending.direction = 0;
333 sun_pci_dma_pending.addr = -1U;
335 sun_pci_dma_current.addr =
336 pci_map_single(sun_pci_ebus_dev,
337 sun_pci_dma_current.buf,
338 sun_pci_dma_current.len,
339 sun_pci_dma_current.direction);
341 ebus_dma_enable(&sun_pci_fd_ebus_dma, 1);
343 if (ebus_dma_request(&sun_pci_fd_ebus_dma,
344 sun_pci_dma_current.addr,
345 sun_pci_dma_current.len))
346 BUG();
349 static void sun_pci_fd_disable_dma(void)
351 ebus_dma_enable(&sun_pci_fd_ebus_dma, 0);
352 if (sun_pci_dma_current.addr != -1U)
353 pci_unmap_single(sun_pci_ebus_dev,
354 sun_pci_dma_current.addr,
355 sun_pci_dma_current.len,
356 sun_pci_dma_current.direction);
357 sun_pci_dma_current.addr = -1U;
360 static void sun_pci_fd_set_dma_mode(int mode)
362 if (mode == DMA_MODE_WRITE)
363 sun_pci_dma_pending.direction = PCI_DMA_TODEVICE;
364 else
365 sun_pci_dma_pending.direction = PCI_DMA_FROMDEVICE;
367 ebus_dma_prepare(&sun_pci_fd_ebus_dma, mode != DMA_MODE_WRITE);
370 static void sun_pci_fd_set_dma_count(int length)
372 sun_pci_dma_pending.len = length;
375 static void sun_pci_fd_set_dma_addr(char *buffer)
377 sun_pci_dma_pending.buf = buffer;
380 static unsigned int sun_pci_get_dma_residue(void)
382 return ebus_dma_residue(&sun_pci_fd_ebus_dma);
385 static int sun_pci_fd_request_irq(void)
387 return ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 1);
390 static void sun_pci_fd_free_irq(void)
392 ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 0);
395 static int sun_pci_fd_eject(int drive)
397 return -EINVAL;
400 void sun_pci_fd_dma_callback(struct ebus_dma_info *p, int event, void *cookie)
402 floppy_interrupt(0, NULL, NULL);
406 * Floppy probing, we'd like to use /dev/fd0 for a single Floppy on PCI,
407 * even if this is configured using DS1, thus looks like /dev/fd1 with
408 * the cabling used in Ultras.
410 #define DOR (port + 2)
411 #define MSR (port + 4)
412 #define FIFO (port + 5)
414 static void sun_pci_fd_out_byte(unsigned long port, unsigned char val,
415 unsigned long reg)
417 unsigned char status;
418 int timeout = 1000;
420 while (!((status = inb(MSR)) & 0x80) && --timeout)
421 udelay(100);
422 outb(val, reg);
425 static unsigned char sun_pci_fd_sensei(unsigned long port)
427 unsigned char result[2] = { 0x70, 0x00 };
428 unsigned char status;
429 int i = 0;
431 sun_pci_fd_out_byte(port, 0x08, FIFO);
432 do {
433 int timeout = 1000;
435 while (!((status = inb(MSR)) & 0x80) && --timeout)
436 udelay(100);
438 if (!timeout)
439 break;
441 if ((status & 0xf0) == 0xd0)
442 result[i++] = inb(FIFO);
443 else
444 break;
445 } while (i < 2);
447 return result[0];
450 static void sun_pci_fd_reset(unsigned long port)
452 unsigned char mask = 0x00;
453 unsigned char status;
454 int timeout = 10000;
456 outb(0x80, MSR);
457 do {
458 status = sun_pci_fd_sensei(port);
459 if ((status & 0xc0) == 0xc0)
460 mask |= 1 << (status & 0x03);
461 else
462 udelay(100);
463 } while ((mask != 0x0f) && --timeout);
466 static int sun_pci_fd_test_drive(unsigned long port, int drive)
468 unsigned char status, data;
469 int timeout = 1000;
470 int ready;
472 sun_pci_fd_reset(port);
474 data = (0x10 << drive) | 0x0c | drive;
475 sun_pci_fd_out_byte(port, data, DOR);
477 sun_pci_fd_out_byte(port, 0x07, FIFO);
478 sun_pci_fd_out_byte(port, drive & 0x03, FIFO);
480 do {
481 udelay(100);
482 status = sun_pci_fd_sensei(port);
483 } while (((status & 0xc0) == 0x80) && --timeout);
485 if (!timeout)
486 ready = 0;
487 else
488 ready = (status & 0x10) ? 0 : 1;
490 sun_pci_fd_reset(port);
491 return ready;
493 #undef FIFO
494 #undef MSR
495 #undef DOR
497 #endif /* CONFIG_PCI */
499 #ifdef CONFIG_PCI
500 static int __init ebus_fdthree_p(struct linux_ebus_device *edev)
502 if (!strcmp(edev->prom_name, "fdthree"))
503 return 1;
504 if (!strcmp(edev->prom_name, "floppy")) {
505 char compat[16];
506 prom_getstring(edev->prom_node,
507 "compatible",
508 compat, sizeof(compat));
509 compat[15] = '\0';
510 if (!strcmp(compat, "fdthree"))
511 return 1;
513 return 0;
515 #endif
517 #ifdef CONFIG_PCI
518 #undef ISA_FLOPPY_WORKS
520 #ifdef ISA_FLOPPY_WORKS
521 static unsigned long __init isa_floppy_init(void)
523 struct sparc_isa_bridge *isa_br;
524 struct sparc_isa_device *isa_dev = NULL;
526 for_each_isa(isa_br) {
527 for_each_isadev(isa_dev, isa_br) {
528 if (!strcmp(isa_dev->prom_name, "dma")) {
529 struct sparc_isa_device *child =
530 isa_dev->child;
532 while (child) {
533 if (!strcmp(child->prom_name,
534 "floppy")) {
535 isa_dev = child;
536 goto isa_done;
538 child = child->next;
543 isa_done:
544 if (!isa_dev)
545 return 0;
547 /* We could use DMA on devices behind the ISA bridge, but...
549 * There is a slight problem. Normally on x86 kit the x86 processor
550 * delays I/O port instructions when the ISA bus "dma in progress"
551 * signal is active. Well, sparc64 systems do not monitor this
552 * signal thus we would need to block all I/O port accesses in software
553 * when a dma transfer is active for some device.
556 sun_fdc = (struct sun_flpy_controller *)isa_dev->resource.start;
557 FLOPPY_IRQ = isa_dev->irq;
559 sun_fdops.fd_inb = sun_pci_fd_inb;
560 sun_fdops.fd_outb = sun_pci_fd_outb;
562 can_use_virtual_dma = use_virtual_dma = 1;
563 sun_fdops.fd_enable_dma = sun_fd_enable_dma;
564 sun_fdops.fd_disable_dma = sun_fd_disable_dma;
565 sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode;
566 sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr;
567 sun_fdops.fd_set_dma_count = sun_fd_set_dma_count;
568 sun_fdops.get_dma_residue = sun_get_dma_residue;
570 sun_fdops.fd_request_irq = sun_fd_request_irq;
571 sun_fdops.fd_free_irq = sun_fd_free_irq;
573 /* Floppy eject is manual. Actually, could determine this
574 * via presence of 'manual' property in OBP node.
576 sun_fdops.fd_eject = sun_pci_fd_eject;
578 fdc_status = (unsigned long) &sun_fdc->status_82077;
579 FLOPPY_MOTOR_MASK = 0xf0;
581 allowed_drive_mask = 0;
582 sun_floppy_types[0] = 0;
583 sun_floppy_types[1] = 4;
585 sun_pci_broken_drive = 1;
586 sun_fdops.fd_outb = sun_pci_fd_broken_outb;
588 return sun_floppy_types[0];
590 #endif /* ISA_FLOPPY_WORKS */
592 #endif
594 static unsigned long __init sun_floppy_init(void)
596 char state[128];
597 struct sbus_bus *bus;
598 struct sbus_dev *sdev = NULL;
599 static int initialized = 0;
601 if (initialized)
602 return sun_floppy_types[0];
603 initialized = 1;
605 for_all_sbusdev (sdev, bus) {
606 if (!strcmp(sdev->prom_name, "SUNW,fdtwo"))
607 break;
609 if(sdev) {
610 floppy_sdev = sdev;
611 FLOPPY_IRQ = sdev->irqs[0];
612 } else {
613 #ifdef CONFIG_PCI
614 struct linux_ebus *ebus;
615 struct linux_ebus_device *edev = NULL;
616 unsigned long config = 0;
617 void __iomem *auxio_reg;
619 for_each_ebus(ebus) {
620 for_each_ebusdev(edev, ebus) {
621 if (ebus_fdthree_p(edev))
622 goto ebus_done;
625 ebus_done:
626 if (!edev) {
627 #ifdef ISA_FLOPPY_WORKS
628 return isa_floppy_init();
629 #else
630 return 0;
631 #endif
634 prom_getproperty(edev->prom_node, "status",
635 state, sizeof(state));
636 if (!strncmp(state, "disabled", 8))
637 return 0;
639 FLOPPY_IRQ = edev->irqs[0];
641 /* Make sure the high density bit is set, some systems
642 * (most notably Ultra5/Ultra10) come up with it clear.
644 auxio_reg = (void __iomem *) edev->resource[2].start;
645 writel(readl(auxio_reg)|0x2, auxio_reg);
647 sun_pci_ebus_dev = ebus->self;
649 spin_lock_init(&sun_pci_fd_ebus_dma.lock);
651 /* XXX ioremap */
652 sun_pci_fd_ebus_dma.regs = (void __iomem *)
653 edev->resource[1].start;
654 if (!sun_pci_fd_ebus_dma.regs)
655 return 0;
657 sun_pci_fd_ebus_dma.flags = (EBUS_DMA_FLAG_USE_EBDMA_HANDLER |
658 EBUS_DMA_FLAG_TCI_DISABLE);
659 sun_pci_fd_ebus_dma.callback = sun_pci_fd_dma_callback;
660 sun_pci_fd_ebus_dma.client_cookie = NULL;
661 sun_pci_fd_ebus_dma.irq = FLOPPY_IRQ;
662 strcpy(sun_pci_fd_ebus_dma.name, "floppy");
663 if (ebus_dma_register(&sun_pci_fd_ebus_dma))
664 return 0;
666 /* XXX ioremap */
667 sun_fdc = (struct sun_flpy_controller *)edev->resource[0].start;
669 sun_fdops.fd_inb = sun_pci_fd_inb;
670 sun_fdops.fd_outb = sun_pci_fd_outb;
672 can_use_virtual_dma = use_virtual_dma = 0;
673 sun_fdops.fd_enable_dma = sun_pci_fd_enable_dma;
674 sun_fdops.fd_disable_dma = sun_pci_fd_disable_dma;
675 sun_fdops.fd_set_dma_mode = sun_pci_fd_set_dma_mode;
676 sun_fdops.fd_set_dma_addr = sun_pci_fd_set_dma_addr;
677 sun_fdops.fd_set_dma_count = sun_pci_fd_set_dma_count;
678 sun_fdops.get_dma_residue = sun_pci_get_dma_residue;
680 sun_fdops.fd_request_irq = sun_pci_fd_request_irq;
681 sun_fdops.fd_free_irq = sun_pci_fd_free_irq;
683 sun_fdops.fd_eject = sun_pci_fd_eject;
685 fdc_status = (unsigned long) &sun_fdc->status_82077;
686 FLOPPY_MOTOR_MASK = 0xf0;
689 * XXX: Find out on which machines this is really needed.
691 if (1) {
692 sun_pci_broken_drive = 1;
693 sun_fdops.fd_outb = sun_pci_fd_broken_outb;
696 allowed_drive_mask = 0;
697 if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 0))
698 sun_floppy_types[0] = 4;
699 if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 1))
700 sun_floppy_types[1] = 4;
703 * Find NS87303 SuperIO config registers (through ecpp).
705 for_each_ebus(ebus) {
706 for_each_ebusdev(edev, ebus) {
707 if (!strcmp(edev->prom_name, "ecpp")) {
708 config = edev->resource[1].start;
709 goto config_done;
713 config_done:
716 * Sanity check, is this really the NS87303?
718 switch (config & 0x3ff) {
719 case 0x02e:
720 case 0x15c:
721 case 0x26e:
722 case 0x398:
723 break;
724 default:
725 config = 0;
728 if (!config)
729 return sun_floppy_types[0];
731 /* Enable PC-AT mode. */
732 ns87303_modify(config, ASC, 0, 0xc0);
734 #ifdef PCI_FDC_SWAP_DRIVES
736 * If only Floppy 1 is present, swap drives.
738 if (!sun_floppy_types[0] && sun_floppy_types[1]) {
740 * Set the drive exchange bit in FCR on NS87303,
741 * make sure other bits are sane before doing so.
743 ns87303_modify(config, FER, FER_EDM, 0);
744 ns87303_modify(config, ASC, ASC_DRV2_SEL, 0);
745 ns87303_modify(config, FCR, 0, FCR_LDE);
747 config = sun_floppy_types[0];
748 sun_floppy_types[0] = sun_floppy_types[1];
749 sun_floppy_types[1] = config;
751 if (sun_pci_broken_drive != -1) {
752 sun_pci_broken_drive = 1 - sun_pci_broken_drive;
753 sun_fdops.fd_outb = sun_pci_fd_lde_broken_outb;
756 #endif /* PCI_FDC_SWAP_DRIVES */
758 return sun_floppy_types[0];
759 #else
760 return 0;
761 #endif
763 prom_getproperty(sdev->prom_node, "status", state, sizeof(state));
764 if(!strncmp(state, "disabled", 8))
765 return 0;
768 * We cannot do sbus_ioremap here: it does request_region,
769 * which the generic floppy driver tries to do once again.
770 * But we must use the sdev resource values as they have
771 * had parent ranges applied.
773 sun_fdc = (struct sun_flpy_controller *)
774 (sdev->resource[0].start +
775 ((sdev->resource[0].flags & 0x1ffUL) << 32UL));
777 /* Last minute sanity check... */
778 if(sbus_readb(&sun_fdc->status1_82077) == 0xff) {
779 sun_fdc = (struct sun_flpy_controller *)-1;
780 return 0;
783 sun_fdops.fd_inb = sun_82077_fd_inb;
784 sun_fdops.fd_outb = sun_82077_fd_outb;
786 can_use_virtual_dma = use_virtual_dma = 1;
787 sun_fdops.fd_enable_dma = sun_fd_enable_dma;
788 sun_fdops.fd_disable_dma = sun_fd_disable_dma;
789 sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode;
790 sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr;
791 sun_fdops.fd_set_dma_count = sun_fd_set_dma_count;
792 sun_fdops.get_dma_residue = sun_get_dma_residue;
794 sun_fdops.fd_request_irq = sun_fd_request_irq;
795 sun_fdops.fd_free_irq = sun_fd_free_irq;
797 sun_fdops.fd_eject = sun_fd_eject;
799 fdc_status = (unsigned long) &sun_fdc->status_82077;
801 /* Success... */
802 allowed_drive_mask = 0x01;
803 sun_floppy_types[0] = 4;
804 sun_floppy_types[1] = 0;
806 return sun_floppy_types[0];
809 #define EXTRA_FLOPPY_PARAMS
811 #endif /* !(__ASM_SPARC64_FLOPPY_H) */