sparc: Move EBUS DMA interfaces into seperate header file.
[linux-2.6.git] / 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/ebus_dma.h>
298 #include <asm/ns87303.h>
299
300 static struct ebus_dma_info sun_pci_fd_ebus_dma;
301 static struct pci_dev *sun_pci_ebus_dev;
302 static int sun_pci_broken_drive = -1;
303
304 struct sun_pci_dma_op {
305         unsigned int    addr;
306         int             len;
307         int             direction;
308         char            *buf;
309 };
310 static struct sun_pci_dma_op sun_pci_dma_current = { -1U, 0, 0, NULL};
311 static struct sun_pci_dma_op sun_pci_dma_pending = { -1U, 0, 0, NULL};
312
313 extern irqreturn_t floppy_interrupt(int irq, void *dev_id);
314
315 static unsigned char sun_pci_fd_inb(unsigned long port)
316 {
317         udelay(5);
318         return inb(port);
319 }
320
321 static void sun_pci_fd_outb(unsigned char val, unsigned long port)
322 {
323         udelay(5);
324         outb(val, port);
325 }
326
327 static void sun_pci_fd_broken_outb(unsigned char val, unsigned long port)
328 {
329         udelay(5);
330         /*
331          * XXX: Due to SUN's broken floppy connector on AX and AXi
332          *      we need to turn on MOTOR_0 also, if the floppy is
333          *      jumpered to DS1 (like most PC floppies are). I hope
334          *      this does not hurt correct hardware like the AXmp.
335          *      (Eddie, Sep 12 1998).
336          */
337         if (port == ((unsigned long)sun_fdc) + 2) {
338                 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x20)) {
339                         val |= 0x10;
340                 }
341         }
342         outb(val, port);
343 }
344
345 #ifdef PCI_FDC_SWAP_DRIVES
346 static void sun_pci_fd_lde_broken_outb(unsigned char val, unsigned long port)
347 {
348         udelay(5);
349         /*
350          * XXX: Due to SUN's broken floppy connector on AX and AXi
351          *      we need to turn on MOTOR_0 also, if the floppy is
352          *      jumpered to DS1 (like most PC floppies are). I hope
353          *      this does not hurt correct hardware like the AXmp.
354          *      (Eddie, Sep 12 1998).
355          */
356         if (port == ((unsigned long)sun_fdc) + 2) {
357                 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x10)) {
358                         val &= ~(0x03);
359                         val |= 0x21;
360                 }
361         }
362         outb(val, port);
363 }
364 #endif /* PCI_FDC_SWAP_DRIVES */
365
366 static void sun_pci_fd_enable_dma(void)
367 {
368         BUG_ON((NULL == sun_pci_dma_pending.buf)        ||
369             (0    == sun_pci_dma_pending.len)   ||
370             (0    == sun_pci_dma_pending.direction));
371
372         sun_pci_dma_current.buf = sun_pci_dma_pending.buf;
373         sun_pci_dma_current.len = sun_pci_dma_pending.len;
374         sun_pci_dma_current.direction = sun_pci_dma_pending.direction;
375
376         sun_pci_dma_pending.buf  = NULL;
377         sun_pci_dma_pending.len  = 0;
378         sun_pci_dma_pending.direction = 0;
379         sun_pci_dma_pending.addr = -1U;
380
381         sun_pci_dma_current.addr =
382                 pci_map_single(sun_pci_ebus_dev,
383                                sun_pci_dma_current.buf,
384                                sun_pci_dma_current.len,
385                                sun_pci_dma_current.direction);
386
387         ebus_dma_enable(&sun_pci_fd_ebus_dma, 1);
388
389         if (ebus_dma_request(&sun_pci_fd_ebus_dma,
390                              sun_pci_dma_current.addr,
391                              sun_pci_dma_current.len))
392                 BUG();
393 }
394
395 static void sun_pci_fd_disable_dma(void)
396 {
397         ebus_dma_enable(&sun_pci_fd_ebus_dma, 0);
398         if (sun_pci_dma_current.addr != -1U)
399                 pci_unmap_single(sun_pci_ebus_dev,
400                                  sun_pci_dma_current.addr,
401                                  sun_pci_dma_current.len,
402                                  sun_pci_dma_current.direction);
403         sun_pci_dma_current.addr = -1U;
404 }
405
406 static void sun_pci_fd_set_dma_mode(int mode)
407 {
408         if (mode == DMA_MODE_WRITE)
409                 sun_pci_dma_pending.direction = PCI_DMA_TODEVICE;
410         else
411                 sun_pci_dma_pending.direction = PCI_DMA_FROMDEVICE;
412
413         ebus_dma_prepare(&sun_pci_fd_ebus_dma, mode != DMA_MODE_WRITE);
414 }
415
416 static void sun_pci_fd_set_dma_count(int length)
417 {
418         sun_pci_dma_pending.len = length;
419 }
420
421 static void sun_pci_fd_set_dma_addr(char *buffer)
422 {
423         sun_pci_dma_pending.buf = buffer;
424 }
425
426 static unsigned int sun_pci_get_dma_residue(void)
427 {
428         return ebus_dma_residue(&sun_pci_fd_ebus_dma);
429 }
430
431 static int sun_pci_fd_request_irq(void)
432 {
433         return ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 1);
434 }
435
436 static void sun_pci_fd_free_irq(void)
437 {
438         ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 0);
439 }
440
441 static int sun_pci_fd_eject(int drive)
442 {
443         return -EINVAL;
444 }
445
446 void sun_pci_fd_dma_callback(struct ebus_dma_info *p, int event, void *cookie)
447 {
448         floppy_interrupt(0, NULL);
449 }
450
451 /*
452  * Floppy probing, we'd like to use /dev/fd0 for a single Floppy on PCI,
453  * even if this is configured using DS1, thus looks like /dev/fd1 with
454  * the cabling used in Ultras.
455  */
456 #define DOR     (port + 2)
457 #define MSR     (port + 4)
458 #define FIFO    (port + 5)
459
460 static void sun_pci_fd_out_byte(unsigned long port, unsigned char val,
461                                 unsigned long reg)
462 {
463         unsigned char status;
464         int timeout = 1000;
465
466         while (!((status = inb(MSR)) & 0x80) && --timeout)
467                 udelay(100);
468         outb(val, reg);
469 }
470
471 static unsigned char sun_pci_fd_sensei(unsigned long port)
472 {
473         unsigned char result[2] = { 0x70, 0x00 };
474         unsigned char status;
475         int i = 0;
476
477         sun_pci_fd_out_byte(port, 0x08, FIFO);
478         do {
479                 int timeout = 1000;
480
481                 while (!((status = inb(MSR)) & 0x80) && --timeout)
482                         udelay(100);
483
484                 if (!timeout)
485                         break;
486
487                 if ((status & 0xf0) == 0xd0)
488                         result[i++] = inb(FIFO);
489                 else
490                         break;
491         } while (i < 2);
492
493         return result[0];
494 }
495
496 static void sun_pci_fd_reset(unsigned long port)
497 {
498         unsigned char mask = 0x00;
499         unsigned char status;
500         int timeout = 10000;
501
502         outb(0x80, MSR);
503         do {
504                 status = sun_pci_fd_sensei(port);
505                 if ((status & 0xc0) == 0xc0)
506                         mask |= 1 << (status & 0x03);
507                 else
508                         udelay(100);
509         } while ((mask != 0x0f) && --timeout);
510 }
511
512 static int sun_pci_fd_test_drive(unsigned long port, int drive)
513 {
514         unsigned char status, data;
515         int timeout = 1000;
516         int ready;
517
518         sun_pci_fd_reset(port);
519
520         data = (0x10 << drive) | 0x0c | drive;
521         sun_pci_fd_out_byte(port, data, DOR);
522
523         sun_pci_fd_out_byte(port, 0x07, FIFO);
524         sun_pci_fd_out_byte(port, drive & 0x03, FIFO);
525
526         do {
527                 udelay(100);
528                 status = sun_pci_fd_sensei(port);
529         } while (((status & 0xc0) == 0x80) && --timeout);
530
531         if (!timeout)
532                 ready = 0;
533         else
534                 ready = (status & 0x10) ? 0 : 1;
535
536         sun_pci_fd_reset(port);
537         return ready;
538 }
539 #undef FIFO
540 #undef MSR
541 #undef DOR
542
543 #endif /* CONFIG_PCI */
544
545 #ifdef CONFIG_PCI
546 static int __init ebus_fdthree_p(struct linux_ebus_device *edev)
547 {
548         if (!strcmp(edev->prom_node->name, "fdthree"))
549                 return 1;
550         if (!strcmp(edev->prom_node->name, "floppy")) {
551                 const char *compat;
552
553                 compat = of_get_property(edev->prom_node,
554                                          "compatible", NULL);
555                 if (compat && !strcmp(compat, "fdthree"))
556                         return 1;
557         }
558         return 0;
559 }
560 #endif
561
562 static unsigned long __init sun_floppy_init(void)
563 {
564         static int initialized = 0;
565         struct device_node *dp;
566         struct of_device *op;
567         const char *prop;
568         char state[128];
569
570         if (initialized)
571                 return sun_floppy_types[0];
572         initialized = 1;
573
574         op = NULL;
575
576         for_each_node_by_name(dp, "SUNW,fdtwo") {
577                 if (strcmp(dp->parent->name, "sbus"))
578                         continue;
579                 op = of_find_device_by_node(dp);
580                 if (op)
581                         break;
582         }
583         if (op) {
584                 floppy_op = op;
585                 FLOPPY_IRQ = op->irqs[0];
586         } else {
587 #ifdef CONFIG_PCI
588                 struct linux_ebus *ebus;
589                 struct linux_ebus_device *edev = NULL;
590                 unsigned long config = 0;
591                 void __iomem *auxio_reg;
592                 const char *state_prop;
593
594                 for_each_ebus(ebus) {
595                         for_each_ebusdev(edev, ebus) {
596                                 if (ebus_fdthree_p(edev))
597                                         goto ebus_done;
598                         }
599                 }
600         ebus_done:
601                 if (!edev)
602                         return 0;
603
604                 op = &edev->ofdev;
605
606                 state_prop = of_get_property(op->node, "status", NULL);
607                 if (state_prop && !strncmp(state_prop, "disabled", 8))
608                         return 0;
609
610                 FLOPPY_IRQ = edev->irqs[0];
611
612                 /* Make sure the high density bit is set, some systems
613                  * (most notably Ultra5/Ultra10) come up with it clear.
614                  */
615                 auxio_reg = (void __iomem *) edev->resource[2].start;
616                 writel(readl(auxio_reg)|0x2, auxio_reg);
617
618                 sun_pci_ebus_dev = ebus->self;
619
620                 spin_lock_init(&sun_pci_fd_ebus_dma.lock);
621
622                 /* XXX ioremap */
623                 sun_pci_fd_ebus_dma.regs = (void __iomem *)
624                         edev->resource[1].start;
625                 if (!sun_pci_fd_ebus_dma.regs)
626                         return 0;
627
628                 sun_pci_fd_ebus_dma.flags = (EBUS_DMA_FLAG_USE_EBDMA_HANDLER |
629                                              EBUS_DMA_FLAG_TCI_DISABLE);
630                 sun_pci_fd_ebus_dma.callback = sun_pci_fd_dma_callback;
631                 sun_pci_fd_ebus_dma.client_cookie = NULL;
632                 sun_pci_fd_ebus_dma.irq = FLOPPY_IRQ;
633                 strcpy(sun_pci_fd_ebus_dma.name, "floppy");
634                 if (ebus_dma_register(&sun_pci_fd_ebus_dma))
635                         return 0;
636
637                 /* XXX ioremap */
638                 sun_fdc = (struct sun_flpy_controller *)edev->resource[0].start;
639
640                 sun_fdops.fd_inb = sun_pci_fd_inb;
641                 sun_fdops.fd_outb = sun_pci_fd_outb;
642
643                 can_use_virtual_dma = use_virtual_dma = 0;
644                 sun_fdops.fd_enable_dma = sun_pci_fd_enable_dma;
645                 sun_fdops.fd_disable_dma = sun_pci_fd_disable_dma;
646                 sun_fdops.fd_set_dma_mode = sun_pci_fd_set_dma_mode;
647                 sun_fdops.fd_set_dma_addr = sun_pci_fd_set_dma_addr;
648                 sun_fdops.fd_set_dma_count = sun_pci_fd_set_dma_count;
649                 sun_fdops.get_dma_residue = sun_pci_get_dma_residue;
650
651                 sun_fdops.fd_request_irq = sun_pci_fd_request_irq;
652                 sun_fdops.fd_free_irq = sun_pci_fd_free_irq;
653
654                 sun_fdops.fd_eject = sun_pci_fd_eject;
655
656                 fdc_status = (unsigned long) &sun_fdc->status_82077;
657
658                 /*
659                  * XXX: Find out on which machines this is really needed.
660                  */
661                 if (1) {
662                         sun_pci_broken_drive = 1;
663                         sun_fdops.fd_outb = sun_pci_fd_broken_outb;
664                 }
665
666                 allowed_drive_mask = 0;
667                 if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 0))
668                         sun_floppy_types[0] = 4;
669                 if (sun_pci_fd_test_drive((unsigned long)sun_fdc, 1))
670                         sun_floppy_types[1] = 4;
671
672                 /*
673                  * Find NS87303 SuperIO config registers (through ecpp).
674                  */
675                 for_each_ebus(ebus) {
676                         for_each_ebusdev(edev, ebus) {
677                                 if (!strcmp(edev->prom_node->name, "ecpp")) {
678                                         config = edev->resource[1].start;
679                                         goto config_done;
680                                 }
681                         }
682                 }
683         config_done:
684
685                 /*
686                  * Sanity check, is this really the NS87303?
687                  */
688                 switch (config & 0x3ff) {
689                 case 0x02e:
690                 case 0x15c:
691                 case 0x26e:
692                 case 0x398:
693                         break;
694                 default:
695                         config = 0;
696                 }
697
698                 if (!config)
699                         return sun_floppy_types[0];
700
701                 /* Enable PC-AT mode. */
702                 ns87303_modify(config, ASC, 0, 0xc0);
703
704 #ifdef PCI_FDC_SWAP_DRIVES
705                 /*
706                  * If only Floppy 1 is present, swap drives.
707                  */
708                 if (!sun_floppy_types[0] && sun_floppy_types[1]) {
709                         /*
710                          * Set the drive exchange bit in FCR on NS87303,
711                          * make sure other bits are sane before doing so.
712                          */
713                         ns87303_modify(config, FER, FER_EDM, 0);
714                         ns87303_modify(config, ASC, ASC_DRV2_SEL, 0);
715                         ns87303_modify(config, FCR, 0, FCR_LDE);
716
717                         config = sun_floppy_types[0];
718                         sun_floppy_types[0] = sun_floppy_types[1];
719                         sun_floppy_types[1] = config;
720
721                         if (sun_pci_broken_drive != -1) {
722                                 sun_pci_broken_drive = 1 - sun_pci_broken_drive;
723                                 sun_fdops.fd_outb = sun_pci_fd_lde_broken_outb;
724                         }
725                 }
726 #endif /* PCI_FDC_SWAP_DRIVES */
727
728                 return sun_floppy_types[0];
729 #else
730                 return 0;
731 #endif
732         }
733         prop = of_get_property(op->node, "status", NULL);
734         if (prop && !strncmp(state, "disabled", 8))
735                 return 0;
736
737         /*
738          * We cannot do of_ioremap here: it does request_region,
739          * which the generic floppy driver tries to do once again.
740          * But we must use the sdev resource values as they have
741          * had parent ranges applied.
742          */
743         sun_fdc = (struct sun_flpy_controller *)
744                 (op->resource[0].start +
745                  ((op->resource[0].flags & 0x1ffUL) << 32UL));
746
747         /* Last minute sanity check... */
748         if (sbus_readb(&sun_fdc->status1_82077) == 0xff) {
749                 sun_fdc = (struct sun_flpy_controller *)-1;
750                 return 0;
751         }
752
753         sun_fdops.fd_inb = sun_82077_fd_inb;
754         sun_fdops.fd_outb = sun_82077_fd_outb;
755
756         can_use_virtual_dma = use_virtual_dma = 1;
757         sun_fdops.fd_enable_dma = sun_fd_enable_dma;
758         sun_fdops.fd_disable_dma = sun_fd_disable_dma;
759         sun_fdops.fd_set_dma_mode = sun_fd_set_dma_mode;
760         sun_fdops.fd_set_dma_addr = sun_fd_set_dma_addr;
761         sun_fdops.fd_set_dma_count = sun_fd_set_dma_count;
762         sun_fdops.get_dma_residue = sun_get_dma_residue;
763
764         sun_fdops.fd_request_irq = sun_fd_request_irq;
765         sun_fdops.fd_free_irq = sun_fd_free_irq;
766
767         sun_fdops.fd_eject = sun_fd_eject;
768
769         fdc_status = (unsigned long) &sun_fdc->status_82077;
770
771         /* Success... */
772         allowed_drive_mask = 0x01;
773         sun_floppy_types[0] = 4;
774         sun_floppy_types[1] = 0;
775
776         return sun_floppy_types[0];
777 }
778
779 #define EXTRA_FLOPPY_PARAMS
780
781 static DEFINE_SPINLOCK(dma_spin_lock);
782
783 #define claim_dma_lock() \
784 ({      unsigned long flags; \
785         spin_lock_irqsave(&dma_spin_lock, flags); \
786         flags; \
787 })
788
789 #define release_dma_lock(__flags) \
790         spin_unlock_irqrestore(&dma_spin_lock, __flags);
791
792 #endif /* !(__ASM_SPARC64_FLOPPY_H) */