[PATCH] Typo fixes
[linux-2.6.git] / include / asm-sparc64 / floppy.h
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.
3  *
4  * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
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/config.h>
14 #include <linux/init.h>
15
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>
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 sbus_dev *floppy_sdev = 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 static int FLOPPY_MOTOR_MASK = 0x10;
89
90 /* Super paranoid... */
91 #undef HAVE_DISABLE_HLT
92
93 static int sun_floppy_types[2] = { 0, 0 };
94
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.
98  */
99 #define FLOPPY0_TYPE            sun_floppy_init()
100 #define FLOPPY1_TYPE            sun_floppy_types[1]
101
102 #define FDC1                    ((unsigned long)sun_fdc)
103
104 #define N_FDC    1
105 #define N_DRIVE  8
106
107 /* No 64k boundary crossing problems on the Sparc. */
108 #define CROSS_64KB(a,s) (0)
109
110 static unsigned char sun_82077_fd_inb(unsigned long port)
111 {
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);
124         };
125         panic("sun_82072_fd_inb: How did I get here?");
126 }
127
128 static void sun_82077_fd_outb(unsigned char value, unsigned long port)
129 {
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;
148         };
149         return;
150 }
151
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
161  */
162 unsigned char *pdma_vaddr;
163 unsigned long pdma_size;
164 volatile int doing_pdma = 0;
165
166 /* This is software state */
167 char *pdma_base = NULL;
168 unsigned long pdma_areasize;
169
170 /* Common routines to all controller types on the Sparc. */
171 static void sun_fd_disable_dma(void)
172 {
173         doing_pdma = 0;
174         if (pdma_base) {
175                 mmu_unlockarea(pdma_base, pdma_areasize);
176                 pdma_base = NULL;
177         }
178 }
179
180 static void sun_fd_set_dma_mode(int mode)
181 {
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...");
192         }
193 }
194
195 static void sun_fd_set_dma_addr(char *buffer)
196 {
197         pdma_vaddr = buffer;
198 }
199
200 static void sun_fd_set_dma_count(int length)
201 {
202         pdma_size = length;
203 }
204
205 static void sun_fd_enable_dma(void)
206 {
207         pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
208         pdma_base = pdma_vaddr;
209         pdma_areasize = pdma_size;
210 }
211
212 extern irqreturn_t sparc_floppy_irq(int, void *, struct pt_regs *);
213
214 static int sun_fd_request_irq(void)
215 {
216         static int once = 0;
217         int error;
218
219         if(!once) {
220                 once = 1;
221
222                 error = request_irq(FLOPPY_IRQ, sparc_floppy_irq, 
223                                     SA_INTERRUPT, "floppy", NULL);
224
225                 return ((error == 0) ? 0 : -1);
226         }
227         return 0;
228 }
229
230 static void sun_fd_free_irq(void)
231 {
232 }
233
234 static unsigned int sun_get_dma_residue(void)
235 {
236         /* XXX This isn't really correct. XXX */
237         return 0;
238 }
239
240 static int sun_fd_eject(int drive)
241 {
242         set_dor(0x00, 0xff, 0x90);
243         udelay(500);
244         set_dor(0x00, 0x6f, 0x00);
245         udelay(500);
246         return 0;
247 }
248
249 #ifdef CONFIG_PCI
250 #include <asm/ebus.h>
251 #include <asm/isa.h>
252 #include <asm/ns87303.h>
253
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;
257
258 struct sun_pci_dma_op {
259         unsigned int    addr;
260         int             len;
261         int             direction;
262         char            *buf;
263 };
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};
266
267 extern irqreturn_t floppy_interrupt(int irq, void *dev_id, struct pt_regs *regs);
268
269 static unsigned char sun_pci_fd_inb(unsigned long port)
270 {
271         udelay(5);
272         return inb(port);
273 }
274
275 static void sun_pci_fd_outb(unsigned char val, unsigned long port)
276 {
277         udelay(5);
278         outb(val, port);
279 }
280
281 static void sun_pci_fd_broken_outb(unsigned char val, unsigned long port)
282 {
283         udelay(5);
284         /*
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).
290          */
291         if (port == ((unsigned long)sun_fdc) + 2) {
292                 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x20)) {
293                         val |= 0x10;
294                 }
295         }
296         outb(val, port);
297 }
298
299 #ifdef PCI_FDC_SWAP_DRIVES
300 static void sun_pci_fd_lde_broken_outb(unsigned char val, unsigned long port)
301 {
302         udelay(5);
303         /*
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).
309          */
310         if (port == ((unsigned long)sun_fdc) + 2) {
311                 if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x10)) {
312                         val &= ~(0x03);
313                         val |= 0x21;
314                 }
315         }
316         outb(val, port);
317 }
318 #endif /* PCI_FDC_SWAP_DRIVES */
319
320 static void sun_pci_fd_enable_dma(void)
321 {
322         BUG_ON((NULL == sun_pci_dma_pending.buf)        ||
323             (0    == sun_pci_dma_pending.len)   ||
324             (0    == sun_pci_dma_pending.direction));
325
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;
329
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;
334
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);
340
341         ebus_dma_enable(&sun_pci_fd_ebus_dma, 1);
342
343         if (ebus_dma_request(&sun_pci_fd_ebus_dma,
344                              sun_pci_dma_current.addr,
345                              sun_pci_dma_current.len))
346                 BUG();
347 }
348
349 static void sun_pci_fd_disable_dma(void)
350 {
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;
358 }
359
360 static void sun_pci_fd_set_dma_mode(int mode)
361 {
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;
366
367         ebus_dma_prepare(&sun_pci_fd_ebus_dma, mode != DMA_MODE_WRITE);
368 }
369
370 static void sun_pci_fd_set_dma_count(int length)
371 {
372         sun_pci_dma_pending.len = length;
373 }
374
375 static void sun_pci_fd_set_dma_addr(char *buffer)
376 {
377         sun_pci_dma_pending.buf = buffer;
378 }
379
380 static unsigned int sun_pci_get_dma_residue(void)
381 {
382         return ebus_dma_residue(&sun_pci_fd_ebus_dma);
383 }
384
385 static int sun_pci_fd_request_irq(void)
386 {
387         return ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 1);
388 }
389
390 static void sun_pci_fd_free_irq(void)
391 {
392         ebus_dma_irq_enable(&sun_pci_fd_ebus_dma, 0);
393 }
394
395 static int sun_pci_fd_eject(int drive)
396 {
397         return -EINVAL;
398 }
399
400 void sun_pci_fd_dma_callback(struct ebus_dma_info *p, int event, void *cookie)
401 {
402         floppy_interrupt(0, NULL, NULL);
403 }
404
405 /*
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.
409  */
410 #define DOR     (port + 2)
411 #define MSR     (port + 4)
412 #define FIFO    (port + 5)
413
414 static void sun_pci_fd_out_byte(unsigned long port, unsigned char val,
415                                 unsigned long reg)
416 {
417         unsigned char status;
418         int timeout = 1000;
419
420         while (!((status = inb(MSR)) & 0x80) && --timeout)
421                 udelay(100);
422         outb(val, reg);
423 }
424
425 static unsigned char sun_pci_fd_sensei(unsigned long port)
426 {
427         unsigned char result[2] = { 0x70, 0x00 };
428         unsigned char status;
429         int i = 0;
430
431         sun_pci_fd_out_byte(port, 0x08, FIFO);
432         do {
433                 int timeout = 1000;
434
435                 while (!((status = inb(MSR)) & 0x80) && --timeout)
436                         udelay(100);
437
438                 if (!timeout)
439                         break;
440
441                 if ((status & 0xf0) == 0xd0)
442                         result[i++] = inb(FIFO);
443                 else
444                         break;
445         } while (i < 2);
446
447         return result[0];
448 }
449
450 static void sun_pci_fd_reset(unsigned long port)
451 {
452         unsigned char mask = 0x00;
453         unsigned char status;
454         int timeout = 10000;
455
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);
464 }
465
466 static int sun_pci_fd_test_drive(unsigned long port, int drive)
467 {
468         unsigned char status, data;
469         int timeout = 1000;
470         int ready;
471
472         sun_pci_fd_reset(port);
473
474         data = (0x10 << drive) | 0x0c | drive;
475         sun_pci_fd_out_byte(port, data, DOR);
476
477         sun_pci_fd_out_byte(port, 0x07, FIFO);
478         sun_pci_fd_out_byte(port, drive & 0x03, FIFO);
479
480         do {
481                 udelay(100);
482                 status = sun_pci_fd_sensei(port);
483         } while (((status & 0xc0) == 0x80) && --timeout);
484
485         if (!timeout)
486                 ready = 0;
487         else
488                 ready = (status & 0x10) ? 0 : 1;
489
490         sun_pci_fd_reset(port);
491         return ready;
492 }
493 #undef FIFO
494 #undef MSR
495 #undef DOR
496
497 #endif /* CONFIG_PCI */
498
499 #ifdef CONFIG_PCI
500 static int __init ebus_fdthree_p(struct linux_ebus_device *edev)
501 {
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;
512         }
513         return 0;
514 }
515 #endif
516
517 #ifdef CONFIG_PCI
518 #undef ISA_FLOPPY_WORKS
519
520 #ifdef ISA_FLOPPY_WORKS
521 static unsigned long __init isa_floppy_init(void)
522 {
523         struct sparc_isa_bridge *isa_br;
524         struct sparc_isa_device *isa_dev = NULL;
525
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;
531
532                                 while (child) {
533                                         if (!strcmp(child->prom_name,
534                                                     "floppy")) {
535                                                 isa_dev = child;
536                                                 goto isa_done;
537                                         }
538                                         child = child->next;
539                                 }
540                         }
541                 }
542         }
543 isa_done:
544         if (!isa_dev)
545                 return 0;
546
547         /* We could use DMA on devices behind the ISA bridge, but...
548          *
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.
554          */
555
556         sun_fdc = (struct sun_flpy_controller *)isa_dev->resource.start;
557         FLOPPY_IRQ = isa_dev->irq;
558
559         sun_fdops.fd_inb = sun_pci_fd_inb;
560         sun_fdops.fd_outb = sun_pci_fd_outb;
561
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;
569
570         sun_fdops.fd_request_irq = sun_fd_request_irq;
571         sun_fdops.fd_free_irq = sun_fd_free_irq;
572
573         /* Floppy eject is manual.   Actually, could determine this
574          * via presence of 'manual' property in OBP node.
575          */
576         sun_fdops.fd_eject = sun_pci_fd_eject;
577
578         fdc_status = (unsigned long) &sun_fdc->status_82077;
579         FLOPPY_MOTOR_MASK = 0xf0;
580
581         allowed_drive_mask = 0;
582         sun_floppy_types[0] = 0;
583         sun_floppy_types[1] = 4;
584
585         sun_pci_broken_drive = 1;
586         sun_fdops.fd_outb = sun_pci_fd_broken_outb;
587
588         return sun_floppy_types[0];
589 }
590 #endif /* ISA_FLOPPY_WORKS */
591
592 #endif
593
594 static unsigned long __init sun_floppy_init(void)
595 {
596         char state[128];
597         struct sbus_bus *bus;
598         struct sbus_dev *sdev = NULL;
599         static int initialized = 0;
600
601         if (initialized)
602                 return sun_floppy_types[0];
603         initialized = 1;
604
605         for_all_sbusdev (sdev, bus) {
606                 if (!strcmp(sdev->prom_name, "SUNW,fdtwo")) 
607                         break;
608         }
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;
618
619                 for_each_ebus(ebus) {
620                         for_each_ebusdev(edev, ebus) {
621                                 if (ebus_fdthree_p(edev))
622                                         goto ebus_done;
623                         }
624                 }
625         ebus_done:
626                 if (!edev) {
627 #ifdef ISA_FLOPPY_WORKS
628                         return isa_floppy_init();
629 #else
630                         return 0;
631 #endif
632                 }
633
634                 prom_getproperty(edev->prom_node, "status",
635                                  state, sizeof(state));
636                 if (!strncmp(state, "disabled", 8))
637                         return 0;
638                         
639                 FLOPPY_IRQ = edev->irqs[0];
640
641                 /* Make sure the high density bit is set, some systems
642                  * (most notably Ultra5/Ultra10) come up with it clear.
643                  */
644                 auxio_reg = (void __iomem *) edev->resource[2].start;
645                 writel(readl(auxio_reg)|0x2, auxio_reg);
646
647                 sun_pci_ebus_dev = ebus->self;
648
649                 spin_lock_init(&sun_pci_fd_ebus_dma.lock);
650
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;
656
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;
665
666                 /* XXX ioremap */
667                 sun_fdc = (struct sun_flpy_controller *)edev->resource[0].start;
668
669                 sun_fdops.fd_inb = sun_pci_fd_inb;
670                 sun_fdops.fd_outb = sun_pci_fd_outb;
671
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;
679
680                 sun_fdops.fd_request_irq = sun_pci_fd_request_irq;
681                 sun_fdops.fd_free_irq = sun_pci_fd_free_irq;
682
683                 sun_fdops.fd_eject = sun_pci_fd_eject;
684
685                 fdc_status = (unsigned long) &sun_fdc->status_82077;
686                 FLOPPY_MOTOR_MASK = 0xf0;
687
688                 /*
689                  * XXX: Find out on which machines this is really needed.
690                  */
691                 if (1) {
692                         sun_pci_broken_drive = 1;
693                         sun_fdops.fd_outb = sun_pci_fd_broken_outb;
694                 }
695
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;
701
702                 /*
703                  * Find NS87303 SuperIO config registers (through ecpp).
704                  */
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;
710                                 }
711                         }
712                 }
713         config_done:
714
715                 /*
716                  * Sanity check, is this really the NS87303?
717                  */
718                 switch (config & 0x3ff) {
719                 case 0x02e:
720                 case 0x15c:
721                 case 0x26e:
722                 case 0x398:
723                         break;
724                 default:
725                         config = 0;
726                 }
727
728                 if (!config)
729                         return sun_floppy_types[0];
730
731                 /* Enable PC-AT mode. */
732                 ns87303_modify(config, ASC, 0, 0xc0);
733
734 #ifdef PCI_FDC_SWAP_DRIVES
735                 /*
736                  * If only Floppy 1 is present, swap drives.
737                  */
738                 if (!sun_floppy_types[0] && sun_floppy_types[1]) {
739                         /*
740                          * Set the drive exchange bit in FCR on NS87303,
741                          * make sure other bits are sane before doing so.
742                          */
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);
746
747                         config = sun_floppy_types[0];
748                         sun_floppy_types[0] = sun_floppy_types[1];
749                         sun_floppy_types[1] = config;
750
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;
754                         }
755                 }
756 #endif /* PCI_FDC_SWAP_DRIVES */
757
758                 return sun_floppy_types[0];
759 #else
760                 return 0;
761 #endif
762         }
763         prom_getproperty(sdev->prom_node, "status", state, sizeof(state));
764         if(!strncmp(state, "disabled", 8))
765                 return 0;
766
767         /*
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.
772          */
773         sun_fdc = (struct sun_flpy_controller *)
774                 (sdev->resource[0].start +
775                  ((sdev->resource[0].flags & 0x1ffUL) << 32UL));
776
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;
781         }
782
783         sun_fdops.fd_inb = sun_82077_fd_inb;
784         sun_fdops.fd_outb = sun_82077_fd_outb;
785
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;
793
794         sun_fdops.fd_request_irq = sun_fd_request_irq;
795         sun_fdops.fd_free_irq = sun_fd_free_irq;
796
797         sun_fdops.fd_eject = sun_fd_eject;
798
799         fdc_status = (unsigned long) &sun_fdc->status_82077;
800
801         /* Success... */
802         allowed_drive_mask = 0x01;
803         sun_floppy_types[0] = 4;
804         sun_floppy_types[1] = 0;
805
806         return sun_floppy_types[0];
807 }
808
809 #define EXTRA_FLOPPY_PARAMS
810
811 #endif /* !(__ASM_SPARC64_FLOPPY_H) */