Linux Audio

Check our new training course

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