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