xref: /linux/arch/sparc/include/asm/floppy_32.h (revision 454eeb2dd7bd0418451ea33a606d0fa50aa36718)
1a439fe51SSam Ravnborg /* asm/floppy.h: Sparc specific parts of the Floppy driver.
2a439fe51SSam Ravnborg  *
3a439fe51SSam Ravnborg  * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
4a439fe51SSam Ravnborg  */
5a439fe51SSam Ravnborg 
6a439fe51SSam Ravnborg #ifndef __ASM_SPARC_FLOPPY_H
7a439fe51SSam Ravnborg #define __ASM_SPARC_FLOPPY_H
8a439fe51SSam Ravnborg 
9*454eeb2dSDavid S. Miller #include <linux/of.h>
10*454eeb2dSDavid S. Miller #include <linux/of_device.h>
11*454eeb2dSDavid S. Miller 
12a439fe51SSam Ravnborg #include <asm/page.h>
13a439fe51SSam Ravnborg #include <asm/pgtable.h>
14a439fe51SSam Ravnborg #include <asm/system.h>
15a439fe51SSam Ravnborg #include <asm/idprom.h>
16a439fe51SSam Ravnborg #include <asm/machines.h>
17a439fe51SSam Ravnborg #include <asm/oplib.h>
18a439fe51SSam Ravnborg #include <asm/auxio.h>
19a439fe51SSam Ravnborg #include <asm/irq.h>
20a439fe51SSam Ravnborg 
21a439fe51SSam Ravnborg /* We don't need no stinkin' I/O port allocation crap. */
22a439fe51SSam Ravnborg #undef release_region
23a439fe51SSam Ravnborg #undef request_region
24a439fe51SSam Ravnborg #define release_region(X, Y)	do { } while(0)
25a439fe51SSam Ravnborg #define request_region(X, Y, Z)	(1)
26a439fe51SSam Ravnborg 
27a439fe51SSam Ravnborg /* References:
28a439fe51SSam Ravnborg  * 1) Netbsd Sun floppy driver.
29a439fe51SSam Ravnborg  * 2) NCR 82077 controller manual
30a439fe51SSam Ravnborg  * 3) Intel 82077 controller manual
31a439fe51SSam Ravnborg  */
32a439fe51SSam Ravnborg struct sun_flpy_controller {
33a439fe51SSam Ravnborg 	volatile unsigned char status_82072;  /* Main Status reg. */
34a439fe51SSam Ravnborg #define dcr_82072              status_82072   /* Digital Control reg. */
35a439fe51SSam Ravnborg #define status1_82077          status_82072   /* Auxiliary Status reg. 1 */
36a439fe51SSam Ravnborg 
37a439fe51SSam Ravnborg 	volatile unsigned char data_82072;    /* Data fifo. */
38a439fe51SSam Ravnborg #define status2_82077          data_82072     /* Auxiliary Status reg. 2 */
39a439fe51SSam Ravnborg 
40a439fe51SSam Ravnborg 	volatile unsigned char dor_82077;     /* Digital Output reg. */
41a439fe51SSam Ravnborg 	volatile unsigned char tapectl_82077; /* What the? Tape control reg? */
42a439fe51SSam Ravnborg 
43a439fe51SSam Ravnborg 	volatile unsigned char status_82077;  /* Main Status Register. */
44a439fe51SSam Ravnborg #define drs_82077              status_82077   /* Digital Rate Select reg. */
45a439fe51SSam Ravnborg 
46a439fe51SSam Ravnborg 	volatile unsigned char data_82077;    /* Data fifo. */
47a439fe51SSam Ravnborg 	volatile unsigned char ___unused;
48a439fe51SSam Ravnborg 	volatile unsigned char dir_82077;     /* Digital Input reg. */
49a439fe51SSam Ravnborg #define dcr_82077              dir_82077      /* Config Control reg. */
50a439fe51SSam Ravnborg };
51a439fe51SSam Ravnborg 
52a439fe51SSam Ravnborg /* You'll only ever find one controller on a SparcStation anyways. */
53a439fe51SSam Ravnborg static struct sun_flpy_controller *sun_fdc = NULL;
54a439fe51SSam Ravnborg extern volatile unsigned char *fdc_status;
55a439fe51SSam Ravnborg 
56a439fe51SSam Ravnborg struct sun_floppy_ops {
57a439fe51SSam Ravnborg 	unsigned char (*fd_inb)(int port);
58a439fe51SSam Ravnborg 	void (*fd_outb)(unsigned char value, int port);
59a439fe51SSam Ravnborg };
60a439fe51SSam Ravnborg 
61a439fe51SSam Ravnborg static struct sun_floppy_ops sun_fdops;
62a439fe51SSam Ravnborg 
63a439fe51SSam Ravnborg #define fd_inb(port)              sun_fdops.fd_inb(port)
64a439fe51SSam Ravnborg #define fd_outb(value,port)       sun_fdops.fd_outb(value,port)
65a439fe51SSam Ravnborg #define fd_enable_dma()           sun_fd_enable_dma()
66a439fe51SSam Ravnborg #define fd_disable_dma()          sun_fd_disable_dma()
67a439fe51SSam Ravnborg #define fd_request_dma()          (0) /* nothing... */
68a439fe51SSam Ravnborg #define fd_free_dma()             /* nothing... */
69a439fe51SSam Ravnborg #define fd_clear_dma_ff()         /* nothing... */
70a439fe51SSam Ravnborg #define fd_set_dma_mode(mode)     sun_fd_set_dma_mode(mode)
71a439fe51SSam Ravnborg #define fd_set_dma_addr(addr)     sun_fd_set_dma_addr(addr)
72a439fe51SSam Ravnborg #define fd_set_dma_count(count)   sun_fd_set_dma_count(count)
73a439fe51SSam Ravnborg #define fd_enable_irq()           /* nothing... */
74a439fe51SSam Ravnborg #define fd_disable_irq()          /* nothing... */
75a439fe51SSam Ravnborg #define fd_cacheflush(addr, size) /* nothing... */
76a439fe51SSam Ravnborg #define fd_request_irq()          sun_fd_request_irq()
77a439fe51SSam Ravnborg #define fd_free_irq()             /* nothing... */
78a439fe51SSam Ravnborg #if 0  /* P3: added by Alain, these cause a MMU corruption. 19960524 XXX */
79a439fe51SSam Ravnborg #define fd_dma_mem_alloc(size)    ((unsigned long) vmalloc(size))
80a439fe51SSam Ravnborg #define fd_dma_mem_free(addr,size) (vfree((void *)(addr)))
81a439fe51SSam Ravnborg #endif
82a439fe51SSam Ravnborg 
83a439fe51SSam Ravnborg /* XXX This isn't really correct. XXX */
84a439fe51SSam Ravnborg #define get_dma_residue(x)        (0)
85a439fe51SSam Ravnborg 
86a439fe51SSam Ravnborg #define FLOPPY0_TYPE  4
87a439fe51SSam Ravnborg #define FLOPPY1_TYPE  0
88a439fe51SSam Ravnborg 
89a439fe51SSam Ravnborg /* Super paranoid... */
90a439fe51SSam Ravnborg #undef HAVE_DISABLE_HLT
91a439fe51SSam Ravnborg 
92a439fe51SSam Ravnborg /* Here is where we catch the floppy driver trying to initialize,
93a439fe51SSam Ravnborg  * therefore this is where we call the PROM device tree probing
94a439fe51SSam Ravnborg  * routine etc. on the Sparc.
95a439fe51SSam Ravnborg  */
96a439fe51SSam Ravnborg #define FDC1                      sun_floppy_init()
97a439fe51SSam Ravnborg 
98a439fe51SSam Ravnborg #define N_FDC    1
99a439fe51SSam Ravnborg #define N_DRIVE  8
100a439fe51SSam Ravnborg 
101a439fe51SSam Ravnborg /* No 64k boundary crossing problems on the Sparc. */
102a439fe51SSam Ravnborg #define CROSS_64KB(a,s) (0)
103a439fe51SSam Ravnborg 
104a439fe51SSam Ravnborg /* Routines unique to each controller type on a Sun. */
105a439fe51SSam Ravnborg static void sun_set_dor(unsigned char value, int fdc_82077)
106a439fe51SSam Ravnborg {
107a439fe51SSam Ravnborg 	if (sparc_cpu_model == sun4c) {
108a439fe51SSam Ravnborg 		unsigned int bits = 0;
109a439fe51SSam Ravnborg 		if (value & 0x10)
110a439fe51SSam Ravnborg 			bits |= AUXIO_FLPY_DSEL;
111a439fe51SSam Ravnborg 		if ((value & 0x80) == 0)
112a439fe51SSam Ravnborg 			bits |= AUXIO_FLPY_EJCT;
113a439fe51SSam Ravnborg 		set_auxio(bits, (~bits) & (AUXIO_FLPY_DSEL|AUXIO_FLPY_EJCT));
114a439fe51SSam Ravnborg 	}
115a439fe51SSam Ravnborg 	if (fdc_82077) {
116a439fe51SSam Ravnborg 		sun_fdc->dor_82077 = value;
117a439fe51SSam Ravnborg 	}
118a439fe51SSam Ravnborg }
119a439fe51SSam Ravnborg 
120a439fe51SSam Ravnborg static unsigned char sun_read_dir(void)
121a439fe51SSam Ravnborg {
122a439fe51SSam Ravnborg 	if (sparc_cpu_model == sun4c)
123a439fe51SSam Ravnborg 		return (get_auxio() & AUXIO_FLPY_DCHG) ? 0x80 : 0;
124a439fe51SSam Ravnborg 	else
125a439fe51SSam Ravnborg 		return sun_fdc->dir_82077;
126a439fe51SSam Ravnborg }
127a439fe51SSam Ravnborg 
128a439fe51SSam Ravnborg static unsigned char sun_82072_fd_inb(int port)
129a439fe51SSam Ravnborg {
130a439fe51SSam Ravnborg 	udelay(5);
131a439fe51SSam Ravnborg 	switch(port & 7) {
132a439fe51SSam Ravnborg 	default:
133a439fe51SSam Ravnborg 		printk("floppy: Asked to read unknown port %d\n", port);
134a439fe51SSam Ravnborg 		panic("floppy: Port bolixed.");
135a439fe51SSam Ravnborg 	case 4: /* FD_STATUS */
136a439fe51SSam Ravnborg 		return sun_fdc->status_82072 & ~STATUS_DMA;
137a439fe51SSam Ravnborg 	case 5: /* FD_DATA */
138a439fe51SSam Ravnborg 		return sun_fdc->data_82072;
139a439fe51SSam Ravnborg 	case 7: /* FD_DIR */
140a439fe51SSam Ravnborg 		return sun_read_dir();
141a439fe51SSam Ravnborg 	};
142a439fe51SSam Ravnborg 	panic("sun_82072_fd_inb: How did I get here?");
143a439fe51SSam Ravnborg }
144a439fe51SSam Ravnborg 
145a439fe51SSam Ravnborg static void sun_82072_fd_outb(unsigned char value, int port)
146a439fe51SSam Ravnborg {
147a439fe51SSam Ravnborg 	udelay(5);
148a439fe51SSam Ravnborg 	switch(port & 7) {
149a439fe51SSam Ravnborg 	default:
150a439fe51SSam Ravnborg 		printk("floppy: Asked to write to unknown port %d\n", port);
151a439fe51SSam Ravnborg 		panic("floppy: Port bolixed.");
152a439fe51SSam Ravnborg 	case 2: /* FD_DOR */
153a439fe51SSam Ravnborg 		sun_set_dor(value, 0);
154a439fe51SSam Ravnborg 		break;
155a439fe51SSam Ravnborg 	case 5: /* FD_DATA */
156a439fe51SSam Ravnborg 		sun_fdc->data_82072 = value;
157a439fe51SSam Ravnborg 		break;
158a439fe51SSam Ravnborg 	case 7: /* FD_DCR */
159a439fe51SSam Ravnborg 		sun_fdc->dcr_82072 = value;
160a439fe51SSam Ravnborg 		break;
161a439fe51SSam Ravnborg 	case 4: /* FD_STATUS */
162a439fe51SSam Ravnborg 		sun_fdc->status_82072 = value;
163a439fe51SSam Ravnborg 		break;
164a439fe51SSam Ravnborg 	};
165a439fe51SSam Ravnborg 	return;
166a439fe51SSam Ravnborg }
167a439fe51SSam Ravnborg 
168a439fe51SSam Ravnborg static unsigned char sun_82077_fd_inb(int port)
169a439fe51SSam Ravnborg {
170a439fe51SSam Ravnborg 	udelay(5);
171a439fe51SSam Ravnborg 	switch(port & 7) {
172a439fe51SSam Ravnborg 	default:
173a439fe51SSam Ravnborg 		printk("floppy: Asked to read unknown port %d\n", port);
174a439fe51SSam Ravnborg 		panic("floppy: Port bolixed.");
175a439fe51SSam Ravnborg 	case 0: /* FD_STATUS_0 */
176a439fe51SSam Ravnborg 		return sun_fdc->status1_82077;
177a439fe51SSam Ravnborg 	case 1: /* FD_STATUS_1 */
178a439fe51SSam Ravnborg 		return sun_fdc->status2_82077;
179a439fe51SSam Ravnborg 	case 2: /* FD_DOR */
180a439fe51SSam Ravnborg 		return sun_fdc->dor_82077;
181a439fe51SSam Ravnborg 	case 3: /* FD_TDR */
182a439fe51SSam Ravnborg 		return sun_fdc->tapectl_82077;
183a439fe51SSam Ravnborg 	case 4: /* FD_STATUS */
184a439fe51SSam Ravnborg 		return sun_fdc->status_82077 & ~STATUS_DMA;
185a439fe51SSam Ravnborg 	case 5: /* FD_DATA */
186a439fe51SSam Ravnborg 		return sun_fdc->data_82077;
187a439fe51SSam Ravnborg 	case 7: /* FD_DIR */
188a439fe51SSam Ravnborg 		return sun_read_dir();
189a439fe51SSam Ravnborg 	};
190a439fe51SSam Ravnborg 	panic("sun_82077_fd_inb: How did I get here?");
191a439fe51SSam Ravnborg }
192a439fe51SSam Ravnborg 
193a439fe51SSam Ravnborg static void sun_82077_fd_outb(unsigned char value, int port)
194a439fe51SSam Ravnborg {
195a439fe51SSam Ravnborg 	udelay(5);
196a439fe51SSam Ravnborg 	switch(port & 7) {
197a439fe51SSam Ravnborg 	default:
198a439fe51SSam Ravnborg 		printk("floppy: Asked to write to unknown port %d\n", port);
199a439fe51SSam Ravnborg 		panic("floppy: Port bolixed.");
200a439fe51SSam Ravnborg 	case 2: /* FD_DOR */
201a439fe51SSam Ravnborg 		sun_set_dor(value, 1);
202a439fe51SSam Ravnborg 		break;
203a439fe51SSam Ravnborg 	case 5: /* FD_DATA */
204a439fe51SSam Ravnborg 		sun_fdc->data_82077 = value;
205a439fe51SSam Ravnborg 		break;
206a439fe51SSam Ravnborg 	case 7: /* FD_DCR */
207a439fe51SSam Ravnborg 		sun_fdc->dcr_82077 = value;
208a439fe51SSam Ravnborg 		break;
209a439fe51SSam Ravnborg 	case 4: /* FD_STATUS */
210a439fe51SSam Ravnborg 		sun_fdc->status_82077 = value;
211a439fe51SSam Ravnborg 		break;
212a439fe51SSam Ravnborg 	case 3: /* FD_TDR */
213a439fe51SSam Ravnborg 		sun_fdc->tapectl_82077 = value;
214a439fe51SSam Ravnborg 		break;
215a439fe51SSam Ravnborg 	};
216a439fe51SSam Ravnborg 	return;
217a439fe51SSam Ravnborg }
218a439fe51SSam Ravnborg 
219a439fe51SSam Ravnborg /* For pseudo-dma (Sun floppy drives have no real DMA available to
220a439fe51SSam Ravnborg  * them so we must eat the data fifo bytes directly ourselves) we have
221a439fe51SSam Ravnborg  * three state variables.  doing_pdma tells our inline low-level
222a439fe51SSam Ravnborg  * assembly floppy interrupt entry point whether it should sit and eat
223a439fe51SSam Ravnborg  * bytes from the fifo or just transfer control up to the higher level
224a439fe51SSam Ravnborg  * floppy interrupt c-code.  I tried very hard but I could not get the
225a439fe51SSam Ravnborg  * pseudo-dma to work in c-code without getting many overruns and
226a439fe51SSam Ravnborg  * underruns.  If non-zero, doing_pdma encodes the direction of
227a439fe51SSam Ravnborg  * the transfer for debugging.  1=read 2=write
228a439fe51SSam Ravnborg  */
229a439fe51SSam Ravnborg extern char *pdma_vaddr;
230a439fe51SSam Ravnborg extern unsigned long pdma_size;
231a439fe51SSam Ravnborg extern volatile int doing_pdma;
232a439fe51SSam Ravnborg 
233a439fe51SSam Ravnborg /* This is software state */
234a439fe51SSam Ravnborg extern char *pdma_base;
235a439fe51SSam Ravnborg extern unsigned long pdma_areasize;
236a439fe51SSam Ravnborg 
237a439fe51SSam Ravnborg /* Common routines to all controller types on the Sparc. */
238a439fe51SSam Ravnborg static inline void virtual_dma_init(void)
239a439fe51SSam Ravnborg {
240a439fe51SSam Ravnborg 	/* nothing... */
241a439fe51SSam Ravnborg }
242a439fe51SSam Ravnborg 
243a439fe51SSam Ravnborg static inline void sun_fd_disable_dma(void)
244a439fe51SSam Ravnborg {
245a439fe51SSam Ravnborg 	doing_pdma = 0;
246a439fe51SSam Ravnborg 	if (pdma_base) {
247a439fe51SSam Ravnborg 		mmu_unlockarea(pdma_base, pdma_areasize);
248a439fe51SSam Ravnborg 		pdma_base = NULL;
249a439fe51SSam Ravnborg 	}
250a439fe51SSam Ravnborg }
251a439fe51SSam Ravnborg 
252a439fe51SSam Ravnborg static inline void sun_fd_set_dma_mode(int mode)
253a439fe51SSam Ravnborg {
254a439fe51SSam Ravnborg 	switch(mode) {
255a439fe51SSam Ravnborg 	case DMA_MODE_READ:
256a439fe51SSam Ravnborg 		doing_pdma = 1;
257a439fe51SSam Ravnborg 		break;
258a439fe51SSam Ravnborg 	case DMA_MODE_WRITE:
259a439fe51SSam Ravnborg 		doing_pdma = 2;
260a439fe51SSam Ravnborg 		break;
261a439fe51SSam Ravnborg 	default:
262a439fe51SSam Ravnborg 		printk("Unknown dma mode %d\n", mode);
263a439fe51SSam Ravnborg 		panic("floppy: Giving up...");
264a439fe51SSam Ravnborg 	}
265a439fe51SSam Ravnborg }
266a439fe51SSam Ravnborg 
267a439fe51SSam Ravnborg static inline void sun_fd_set_dma_addr(char *buffer)
268a439fe51SSam Ravnborg {
269a439fe51SSam Ravnborg 	pdma_vaddr = buffer;
270a439fe51SSam Ravnborg }
271a439fe51SSam Ravnborg 
272a439fe51SSam Ravnborg static inline void sun_fd_set_dma_count(int length)
273a439fe51SSam Ravnborg {
274a439fe51SSam Ravnborg 	pdma_size = length;
275a439fe51SSam Ravnborg }
276a439fe51SSam Ravnborg 
277a439fe51SSam Ravnborg static inline void sun_fd_enable_dma(void)
278a439fe51SSam Ravnborg {
279a439fe51SSam Ravnborg 	pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
280a439fe51SSam Ravnborg 	pdma_base = pdma_vaddr;
281a439fe51SSam Ravnborg 	pdma_areasize = pdma_size;
282a439fe51SSam Ravnborg }
283a439fe51SSam Ravnborg 
284a439fe51SSam Ravnborg /* Our low-level entry point in arch/sparc/kernel/entry.S */
285a439fe51SSam Ravnborg extern int sparc_floppy_request_irq(int irq, unsigned long flags,
286a439fe51SSam Ravnborg 				    irq_handler_t irq_handler);
287a439fe51SSam Ravnborg 
288a439fe51SSam Ravnborg static int sun_fd_request_irq(void)
289a439fe51SSam Ravnborg {
290a439fe51SSam Ravnborg 	static int once = 0;
291a439fe51SSam Ravnborg 	int error;
292a439fe51SSam Ravnborg 
293a439fe51SSam Ravnborg 	if(!once) {
294a439fe51SSam Ravnborg 		once = 1;
295a439fe51SSam Ravnborg 		error = sparc_floppy_request_irq(FLOPPY_IRQ,
296a439fe51SSam Ravnborg 						 IRQF_DISABLED,
297a439fe51SSam Ravnborg 						 floppy_interrupt);
298a439fe51SSam Ravnborg 		return ((error == 0) ? 0 : -1);
299a439fe51SSam Ravnborg 	} else return 0;
300a439fe51SSam Ravnborg }
301a439fe51SSam Ravnborg 
302a439fe51SSam Ravnborg static struct linux_prom_registers fd_regs[2];
303a439fe51SSam Ravnborg 
304a439fe51SSam Ravnborg static int sun_floppy_init(void)
305a439fe51SSam Ravnborg {
306a439fe51SSam Ravnborg 	char state[128];
307a439fe51SSam Ravnborg 	int tnode, fd_node, num_regs;
308a439fe51SSam Ravnborg 	struct resource r;
309a439fe51SSam Ravnborg 
310a439fe51SSam Ravnborg 	use_virtual_dma = 1;
311a439fe51SSam Ravnborg 
312a439fe51SSam Ravnborg 	FLOPPY_IRQ = 11;
313a439fe51SSam Ravnborg 	/* Forget it if we aren't on a machine that could possibly
314a439fe51SSam Ravnborg 	 * ever have a floppy drive.
315a439fe51SSam Ravnborg 	 */
316a439fe51SSam Ravnborg 	if((sparc_cpu_model != sun4c && sparc_cpu_model != sun4m) ||
317a439fe51SSam Ravnborg 	   ((idprom->id_machtype == (SM_SUN4C | SM_4C_SLC)) ||
318a439fe51SSam Ravnborg 	    (idprom->id_machtype == (SM_SUN4C | SM_4C_ELC)))) {
319a439fe51SSam Ravnborg 		/* We certainly don't have a floppy controller. */
320a439fe51SSam Ravnborg 		goto no_sun_fdc;
321a439fe51SSam Ravnborg 	}
322a439fe51SSam Ravnborg 	/* Well, try to find one. */
323a439fe51SSam Ravnborg 	tnode = prom_getchild(prom_root_node);
324a439fe51SSam Ravnborg 	fd_node = prom_searchsiblings(tnode, "obio");
325a439fe51SSam Ravnborg 	if(fd_node != 0) {
326a439fe51SSam Ravnborg 		tnode = prom_getchild(fd_node);
327a439fe51SSam Ravnborg 		fd_node = prom_searchsiblings(tnode, "SUNW,fdtwo");
328a439fe51SSam Ravnborg 	} else {
329a439fe51SSam Ravnborg 		fd_node = prom_searchsiblings(tnode, "fd");
330a439fe51SSam Ravnborg 	}
331a439fe51SSam Ravnborg 	if(fd_node == 0) {
332a439fe51SSam Ravnborg 		goto no_sun_fdc;
333a439fe51SSam Ravnborg 	}
334a439fe51SSam Ravnborg 
335a439fe51SSam Ravnborg 	/* The sun4m lets us know if the controller is actually usable. */
336a439fe51SSam Ravnborg 	if(sparc_cpu_model == sun4m &&
337a439fe51SSam Ravnborg 	   prom_getproperty(fd_node, "status", state, sizeof(state)) != -1) {
338a439fe51SSam Ravnborg 		if(!strcmp(state, "disabled")) {
339a439fe51SSam Ravnborg 			goto no_sun_fdc;
340a439fe51SSam Ravnborg 		}
341a439fe51SSam Ravnborg 	}
342a439fe51SSam Ravnborg 	num_regs = prom_getproperty(fd_node, "reg", (char *) fd_regs, sizeof(fd_regs));
343a439fe51SSam Ravnborg 	num_regs = (num_regs / sizeof(fd_regs[0]));
344a439fe51SSam Ravnborg 	prom_apply_obio_ranges(fd_regs, num_regs);
345a439fe51SSam Ravnborg 	memset(&r, 0, sizeof(r));
346a439fe51SSam Ravnborg 	r.flags = fd_regs[0].which_io;
347a439fe51SSam Ravnborg 	r.start = fd_regs[0].phys_addr;
348a439fe51SSam Ravnborg 	sun_fdc = (struct sun_flpy_controller *)
349*454eeb2dSDavid S. Miller 	    of_ioremap(&r, 0, fd_regs[0].reg_size, "floppy");
350a439fe51SSam Ravnborg 
351a439fe51SSam Ravnborg 	/* Last minute sanity check... */
352a439fe51SSam Ravnborg 	if(sun_fdc->status_82072 == 0xff) {
353a439fe51SSam Ravnborg 		sun_fdc = NULL;
354a439fe51SSam Ravnborg 		goto no_sun_fdc;
355a439fe51SSam Ravnborg 	}
356a439fe51SSam Ravnborg 
357a439fe51SSam Ravnborg 	sun_fdops.fd_inb = sun_82077_fd_inb;
358a439fe51SSam Ravnborg 	sun_fdops.fd_outb = sun_82077_fd_outb;
359a439fe51SSam Ravnborg 	fdc_status = &sun_fdc->status_82077;
360a439fe51SSam Ravnborg 
361a439fe51SSam Ravnborg 	if (sun_fdc->dor_82077 == 0x80) {
362a439fe51SSam Ravnborg 		sun_fdc->dor_82077 = 0x02;
363a439fe51SSam Ravnborg 		if (sun_fdc->dor_82077 == 0x80) {
364a439fe51SSam Ravnborg 			sun_fdops.fd_inb = sun_82072_fd_inb;
365a439fe51SSam Ravnborg 			sun_fdops.fd_outb = sun_82072_fd_outb;
366a439fe51SSam Ravnborg 			fdc_status = &sun_fdc->status_82072;
367a439fe51SSam Ravnborg 		}
368a439fe51SSam Ravnborg 	}
369a439fe51SSam Ravnborg 
370a439fe51SSam Ravnborg 	/* Success... */
371a439fe51SSam Ravnborg 	allowed_drive_mask = 0x01;
372a439fe51SSam Ravnborg 	return (int) sun_fdc;
373a439fe51SSam Ravnborg 
374a439fe51SSam Ravnborg no_sun_fdc:
375a439fe51SSam Ravnborg 	return -1;
376a439fe51SSam Ravnborg }
377a439fe51SSam Ravnborg 
378a439fe51SSam Ravnborg static int sparc_eject(void)
379a439fe51SSam Ravnborg {
380a439fe51SSam Ravnborg 	set_dor(0x00, 0xff, 0x90);
381a439fe51SSam Ravnborg 	udelay(500);
382a439fe51SSam Ravnborg 	set_dor(0x00, 0x6f, 0x00);
383a439fe51SSam Ravnborg 	udelay(500);
384a439fe51SSam Ravnborg 	return 0;
385a439fe51SSam Ravnborg }
386a439fe51SSam Ravnborg 
387a439fe51SSam Ravnborg #define fd_eject(drive) sparc_eject()
388a439fe51SSam Ravnborg 
389a439fe51SSam Ravnborg #define EXTRA_FLOPPY_PARAMS
390a439fe51SSam Ravnborg 
391334ae614SDavid S. Miller static DEFINE_SPINLOCK(dma_spin_lock);
392334ae614SDavid S. Miller 
393334ae614SDavid S. Miller #define claim_dma_lock() \
394334ae614SDavid S. Miller ({	unsigned long flags; \
395334ae614SDavid S. Miller 	spin_lock_irqsave(&dma_spin_lock, flags); \
396334ae614SDavid S. Miller 	flags; \
397334ae614SDavid S. Miller })
398334ae614SDavid S. Miller 
399334ae614SDavid S. Miller #define release_dma_lock(__flags) \
400334ae614SDavid S. Miller 	spin_unlock_irqrestore(&dma_spin_lock, __flags);
401334ae614SDavid S. Miller 
402a439fe51SSam Ravnborg #endif /* !(__ASM_SPARC_FLOPPY_H) */
403