sparc: asm/mostek.h is now 32-bit only
[safe/jmp/linux-2.6] / arch / sparc / include / asm / floppy_64.h
1 /* floppy.h: Sparc specific parts of the Floppy driver.
2  *
3  * Copyright (C) 1996, 2007, 2008 David S. Miller (davem@davemloft.net)
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
12 #include <linux/init.h>
13 #include <linux/pci.h>
14 #include <linux/of.h>
15 #include <linux/of_device.h>
16
17 #include <asm/page.h>
18 #include <asm/pgtable.h>
19 #include <asm/system.h>
20 #include <asm/idprom.h>
21 #include <asm/oplib.h>
22 #include <asm/auxio.h>
23 #include <asm/irq.h>
24
25
26 /*
27  * Define this to enable exchanging drive 0 and 1 if only drive 1 is
28  * probed on PCI machines.
29  */
30 #undef PCI_FDC_SWAP_DRIVES
31
32
33 /* References:
34  * 1) Netbsd Sun floppy driver.
35  * 2) NCR 82077 controller manual
36  * 3) Intel 82077 controller manual
37  */
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. */
49 };
50
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 of_device *floppy_op = NULL;
55
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);
68 };
69
70 static struct sun_floppy_ops sun_fdops;
71
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)
87
88 /* Super paranoid... */
89 #undef HAVE_DISABLE_HLT
90
91 static int sun_floppy_types[2] = { 0, 0 };
92
93 /* Here is where we catch the floppy driver trying to initialize,
94  * therefore this is where we call the PROM device tree probing
95  * routine etc. on the Sparc.
96  */
97 #define FLOPPY0_TYPE            sun_floppy_init()
98 #define FLOPPY1_TYPE            sun_floppy_types[1]
99
100 #define FDC1                    ((unsigned long)sun_fdc)
101
102 #define N_FDC    1
103 #define N_DRIVE  8
104
105 /* No 64k boundary crossing problems on the Sparc. */
106 #define CROSS_64KB(a,s) (0)
107
108 static unsigned char sun_82077_fd_inb(unsigned long port)
109 {
110         udelay(5);
111         switch(port & 7) {
112         default:
113                 printk("floppy: Asked to read unknown port %lx\n", port);
114                 panic("floppy: Port bolixed.");
115         case 4: /* FD_STATUS */
116                 return sbus_readb(&sun_fdc->status_82077) & ~STATUS_DMA;
117         case 5: /* FD_DATA */
118                 return sbus_readb(&sun_fdc->data_82077);
119         case 7: /* FD_DIR */
120                 /* XXX: Is DCL on 0x80 in sun4m? */
121                 return sbus_readb(&sun_fdc->dir_82077);
122         };
123         panic("sun_82072_fd_inb: How did I get here?");
124 }
125
126 static void sun_82077_fd_outb(unsigned char value, unsigned long port)
127 {
128         udelay(5);
129         switch(port & 7) {
130         default:
131                 printk("floppy: Asked to write to unknown port %lx\n", port);
132                 panic("floppy: Port bolixed.");
133         case 2: /* FD_DOR */
134                 /* Happily, the 82077 has a real DOR register. */
135                 sbus_writeb(value, &sun_fdc->dor_82077);
136                 break;
137         case 5: /* FD_DATA */
138                 sbus_writeb(value, &sun_fdc->data_82077);
139                 break;
140         case 7: /* FD_DCR */
141                 sbus_writeb(value, &sun_fdc->dcr_82077);
142                 break;
143         case 4: /* FD_STATUS */
144                 sbus_writeb(value, &sun_fdc->status_82077);
145                 break;
146         };
147         return;
148 }
149
150 /* For pseudo-dma (Sun floppy drives have no real DMA available to
151  * them so we must eat the data fifo bytes directly ourselves) we have
152  * three state variables.  doing_pdma tells our inline low-level
153  * assembly floppy interrupt entry point whether it should sit and eat
154  * bytes from the fifo or just transfer control up to the higher level
155  * floppy interrupt c-code.  I tried very hard but I could not get the
156  * pseudo-dma to work in c-code without getting many overruns and
157  * underruns.  If non-zero, doing_pdma encodes the direction of
158  * the transfer for debugging.  1=read 2=write
159  */
160 unsigned char *pdma_vaddr;
161 unsigned long pdma_size;
162 volatile int doing_pdma = 0;
163
164 /* This is software state */
165 char *pdma_base = NULL;
166 unsigned long pdma_areasize;
167
168 /* Common routines to all controller types on the Sparc. */
169 static void sun_fd_disable_dma(void)
170 {
171         doing_pdma = 0;
172         if (pdma_base) {
173                 mmu_unlockarea(pdma_base, pdma_areasize);
174                 pdma_base = NULL;
175         }
176 }
177
178 static void sun_fd_set_dma_mode(int mode)
179 {
180         switch(mode) {
181         case DMA_MODE_READ:
182                 doing_pdma = 1;
183                 break;
184         case DMA_MODE_WRITE:
185                 doing_pdma = 2;
186                 break;
187         default:
188                 printk("Unknown dma mode %d\n", mode);
189                 panic("floppy: Giving up...");
190         }
191 }
192
193 static void sun_fd_set_dma_addr(char *buffer)
194 {
195         pdma_vaddr = buffer;
196 }
197
198 static void sun_fd_set_dma_count(int length)
199 {
200         pdma_size = length;
201 }
202
203 static void sun_fd_enable_dma(void)
204 {
205         pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
206         pdma_base = pdma_vaddr;
207         pdma_areasize = pdma_size;
208 }
209
210 irqreturn_t sparc_floppy_irq(int irq, void *dev_cookie)
211 {
212         if (likely(doing_pdma)) {
213                 void __iomem *stat = (void __iomem *) fdc_status;
214                 unsigned char *vaddr = pdma_vaddr;
215                 unsigned long size = pdma_size;
216                 u8 val;
217
218                 while (size) {
219                         val = readb(stat);
220                         if (unlikely(!(val & 0x80))) {
221                                 pdma_vaddr = vaddr;
222                                 pdma_size = size;
223                                 return IRQ_HANDLED;
224                         }
225                         if (unlikely(!(val & 0x20))) {
226                                 pdma_vaddr = vaddr;
227                                 pdma_size = size;
228                                 doing_pdma = 0;
229                                 goto main_interrupt;
230                         }
231                         if (val & 0x40) {
232                                 /* read */
233                                 *vaddr++ = readb(stat + 1);
234                         } else {
235                                 unsigned char data = *vaddr++;
236
237                                 /* write */
238                                 writeb(data, stat + 1);
239                         }
240                         size--;
241                 }
242
243                 pdma_vaddr = vaddr;
244                 pdma_size = size;
245
246                 /* Send Terminal Count pulse to floppy controller. */
247                 val = readb(auxio_register);
248                 val |= AUXIO_AUX1_FTCNT;
249                 writeb(val, auxio_register);
250                 val &= ~AUXIO_AUX1_FTCNT;
251                 writeb(val, auxio_register);
252
253                 doing_pdma = 0;
254         }
255
256 main_interrupt:
257         return floppy_interrupt(irq, dev_cookie);
258 }
259
260 static int sun_fd_request_irq(void)
261 {
262         static int once = 0;
263         int error;
264
265         if(!once) {
266                 once = 1;
267
268                 error = request_irq(FLOPPY_IRQ, sparc_floppy_irq,
269                                     IRQF_DISABLED, "floppy", NULL);
270
271                 return ((error == 0) ? 0 : -1);
272         }
273         return 0;
274 }
275
276 static void sun_fd_free_irq(void)
277 {
278 }
279
280 static unsigned int sun_get_dma_residue(void)
281 {
282         /* XXX This isn't really correct. XXX */
283         return 0;
284 }
285
286 static int sun_fd_eject(int drive)
287 {
288         set_dor(0x00, 0xff, 0x90);
289         udelay(500);
290         set_dor(0x00, 0x6f, 0x00);
291         udelay(500);
292         return 0;
293 }
294
295 #ifdef CONFIG_PCI
296 #include <asm/ebus.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
312 extern irqreturn_t floppy_interrupt(int irq, void *dev_id);
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 {
447         floppy_interrupt(0, NULL);
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 {
547         if (!strcmp(edev->prom_node->name, "fdthree"))
548                 return 1;
549         if (!strcmp(edev->prom_node->name, "floppy")) {
550                 const char *compat;
551
552                 compat = of_get_property(edev->prom_node,
553                                          "compatible", NULL);
554                 if (compat && !strcmp(compat, "fdthree"))
555                         return 1;
556         }
557         return 0;
558 }
559 #endif
560
561 static unsigned long __init sun_floppy_init(void)
562 {
563         static int initialized = 0;
564         struct device_node *dp;
565         struct of_device *op;
566         const char *prop;
567         char state[128];
568
569         if (initialized)
570                 return sun_floppy_types[0];
571         initialized = 1;
572
573         op = NULL;
574
575         for_each_node_by_name(dp, "SUNW,fdtwo") {
576                 if (strcmp(dp->parent->name, "sbus"))
577                         continue;
578                 op = of_find_device_by_node(dp);
579                 if (op)
580                         break;
581         }
582         if (op) {
583                 floppy_op = op;
584                 FLOPPY_IRQ = op->irqs[0];
585         } else {
586 #ifdef CONFIG_PCI
587                 struct linux_ebus *ebus;
588                 struct linux_ebus_device *edev = NULL;
589                 unsigned long config = 0;
590                 void __iomem *auxio_reg;
591                 const char *state_prop;
592
593                 for_each_ebus(ebus) {
594                         for_each_ebusdev(edev, ebus) {
595                                 if (ebus_fdthree_p(edev))
596                                         goto ebus_done;
597                         }
598                 }
599         ebus_done:
600                 if (!edev)
601                         return 0;
602
603                 op = &edev->ofdev;
604
605                 state_prop = of_get_property(op->node, "status", NULL);
606                 if (state_prop && !strncmp(state_prop, "disabled", 8))
607                         return 0;
608
609                 FLOPPY_IRQ = edev->irqs[0];
610
611                 /* Make sure the high density bit is set, some systems
612                  * (most notably Ultra5/Ultra10) come up with it clear.
613                  */
614                 auxio_reg = (void __iomem *) edev->resource[2].start;
615                 writel(readl(auxio_reg)|0x2, auxio_reg);
616
617                 sun_pci_ebus_dev = ebus->self;
618
619                 spin_lock_init(&sun_pci_fd_ebus_dma.lock);
620
621                 /* XXX ioremap */
622                 sun_pci_fd_ebus_dma.regs = (void __iomem *)
623                         edev->resource[1].start;
624                 if (!sun_pci_fd_ebus_dma.regs)
625                         return 0;
626
627                 sun_pci_fd_ebus_dma.flags = (EBUS_DMA_FLAG_USE_EBDMA_HANDLER |
628                                              EBUS_DMA_FLAG_TCI_DISABLE);
629                 sun_pci_fd_ebus_dma.callback = sun_pci_fd_dma_callback;
630                 sun_pci_fd_ebus_dma.client_cookie = NULL;
631                 sun_pci_fd_ebus_dma.irq = FLOPPY_IRQ;
632                 strcpy(sun_pci_fd_ebus_dma.name, "floppy");
633                 if (ebus_dma_register(&sun_pci_fd_ebus_dma))
634                         return 0;
635
636                 /* XXX ioremap */
637                 sun_fdc = (struct sun_flpy_controller *)edev->resource[0].start;
638
639                 sun_fdops.fd_inb = sun_pci_fd_inb;
640                 sun_fdops.fd_outb = sun_pci_fd_outb;
641
642                 can_use_virtual_dma = use_virtual_dma = 0;
643                 sun_fdops.fd_enable_dma = sun_pci_fd_enable_dma;
644                 sun_fdops.fd_disable_dma = sun_pci_fd_disable_dma;
645                 sun_fdops.fd_set_dma_mode = sun_pci_fd_set_dma_mode;
646                 sun_fdops.fd_set_dma_addr = sun_pci_fd_set_dma_addr;
647                 sun_fdops.fd_set_dma_count = sun_pci_fd_set_dma_count;
648                 sun_fdops.get_dma_residue = sun_pci_get_dma_residue;
649
650                 sun_fdops.fd_request_irq = sun_pci_fd_request_irq;
651                 sun_fdops.fd_free_irq = sun_pci_fd_free_irq;
652
653                 sun_fdops.fd_eject = sun_pci_fd_eject;
654
655                 fdc_status = (unsigned long) &sun_fdc->status_82077;
656
657                 /*
658                  * XXX: Find out on which machines this is really needed.
659                  */
660                 if (1) {
661                         sun_pci_broken_drive = 1;
662                         sun_fdops.fd_outb = sun_pci_fd_broken_outb;
663                 }
664
665                 allowed_drive_mask = 0;
666                 if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 0))
667                         sun_floppy_types[0] = 4;
668                 if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 1))
669                         sun_floppy_types[1] = 4;
670
671                 /*
672                  * Find NS87303 SuperIO config registers (through ecpp).
673                  */
674                 for_each_ebus(ebus) {
675                         for_each_ebusdev(edev, ebus) {
676                                 if (!strcmp(edev->prom_node->name, "ecpp")) {
677                                         config = edev->resource[1].start;
678                                         goto config_done;
679                                 }
680                         }
681                 }
682         config_done:
683
684                 /*
685                  * Sanity check, is this really the NS87303?
686                  */
687                 switch (config & 0x3ff) {
688                 case 0x02e:
689                 case 0x15c:
690                 case 0x26e:
691                 case 0x398:
692                         break;
693                 default:
694                         config = 0;
695                 }
696
697                 if (!config)
698                         return sun_floppy_types[0];
699
700                 /* Enable PC-AT mode. */
701                 ns87303_modify(config, ASC, 0, 0xc0);
702
703 #ifdef PCI_FDC_SWAP_DRIVES
704                 /*
705                  * If only Floppy 1 is present, swap drives.
706                  */
707                 if (!sun_floppy_types[0] && sun_floppy_types[1]) {
708                         /*
709                          * Set the drive exchange bit in FCR on NS87303,
710                          * make sure other bits are sane before doing so.
711                          */
712                         ns87303_modify(config, FER, FER_EDM, 0);
713                         ns87303_modify(config, ASC, ASC_DRV2_SEL, 0);
714                         ns87303_modify(config, FCR, 0, FCR_LDE);
715
716                         config = sun_floppy_types[0];
717                         sun_floppy_types[0] = sun_floppy_types[1];
718                         sun_floppy_types[1] = config;
719
720                         if (sun_pci_broken_drive != -1) {
721                                 sun_pci_broken_drive = 1 - sun_pci_broken_drive;
722                                 sun_fdops.fd_outb = sun_pci_fd_lde_broken_outb;
723                         }
724                 }
725 #endif /* PCI_FDC_SWAP_DRIVES */
726
727                 return sun_floppy_types[0];
728 #else
729                 return 0;
730 #endif
731         }
732         prop = of_get_property(op->node, "status", NULL);
733         if (prop && !strncmp(state, "disabled", 8))
734                 return 0;
735
736         /*
737          * We cannot do of_ioremap here: it does request_region,
738          * which the generic floppy driver tries to do once again.
739          * But we must use the sdev resource values as they have
740          * had parent ranges applied.
741          */
742         sun_fdc = (struct sun_flpy_controller *)
743                 (op->resource[0].start +
744                  ((op->resource[0].flags & 0x1ffUL) << 32UL));
745
746         /* Last minute sanity check... */
747         if (sbus_readb(&sun_fdc->status1_82077) == 0xff) {
748                 sun_fdc = (struct sun_flpy_controller *)-1;
749                 return 0;
750         }
751
752         sun_fdops.fd_inb = sun_82077_fd_inb;
753         sun_fdops.fd_outb = sun_82077_fd_outb;
754
755         can_use_virtual_dma = use_virtual_dma = 1;
756         sun_fdops.fd_enable_dma = sun_fd_enable_dma;
757         sun_fdops.fd_disable_dma = sun_fd_disable_dma;
758         sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode;
759         sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr;
760         sun_fdops.fd_set_dma_count = sun_fd_set_dma_count;
761         sun_fdops.get_dma_residue = sun_get_dma_residue;
762
763         sun_fdops.fd_request_irq = sun_fd_request_irq;
764         sun_fdops.fd_free_irq = sun_fd_free_irq;
765
766         sun_fdops.fd_eject = sun_fd_eject;
767
768         fdc_status = (unsigned long) &sun_fdc->status_82077;
769
770         /* Success... */
771         allowed_drive_mask = 0x01;
772         sun_floppy_types[0] = 4;
773         sun_floppy_types[1] = 0;
774
775         return sun_floppy_types[0];
776 }
777
778 #define EXTRA_FLOPPY_PARAMS
779
780 static DEFINE_SPINLOCK(dma_spin_lock);
781
782 #define claim_dma_lock() \
783 ({      unsigned long flags; \
784         spin_lock_irqsave(&dma_spin_lock, flags); \
785         flags; \
786 })
787
788 #define release_dma_lock(__flags) \
789         spin_unlock_irqrestore(&dma_spin_lock, __flags);
790
791 #endif /* !(__ASM_SPARC64_FLOPPY_H) */