[PATCH] fix semaphore handling in __unregister_chrdev_region
[linux/fpc-iii.git] / include / asm-sparc / floppy.h
blobcaf926116506a2d0980e1e13b30c6c600b02b120
1 /* asm-sparc/floppy.h: Sparc specific parts of the Floppy driver.
3 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
4 */
6 #ifndef __ASM_SPARC_FLOPPY_H
7 #define __ASM_SPARC_FLOPPY_H
9 #include <asm/page.h>
10 #include <asm/pgtable.h>
11 #include <asm/system.h>
12 #include <asm/idprom.h>
13 #include <asm/machines.h>
14 #include <asm/oplib.h>
15 #include <asm/auxio.h>
16 #include <asm/irq.h>
18 /* We don't need no stinkin' I/O port allocation crap. */
19 #undef release_region
20 #undef check_region
21 #undef request_region
22 #define release_region(X, Y) do { } while(0)
23 #define check_region(X, Y) (0)
24 #define request_region(X, Y, Z) (1)
26 /* References:
27 * 1) Netbsd Sun floppy driver.
28 * 2) NCR 82077 controller manual
29 * 3) Intel 82077 controller manual
31 struct sun_flpy_controller {
32 volatile unsigned char status_82072; /* Main Status reg. */
33 #define dcr_82072 status_82072 /* Digital Control reg. */
34 #define status1_82077 status_82072 /* Auxiliary Status reg. 1 */
36 volatile unsigned char data_82072; /* Data fifo. */
37 #define status2_82077 data_82072 /* Auxiliary Status reg. 2 */
39 volatile unsigned char dor_82077; /* Digital Output reg. */
40 volatile unsigned char tapectl_82077; /* What the? Tape control reg? */
42 volatile unsigned char status_82077; /* Main Status Register. */
43 #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. */
51 /* You'll only ever find one controller on a SparcStation anyways. */
52 static struct sun_flpy_controller *sun_fdc = NULL;
53 volatile unsigned char *fdc_status;
55 struct sun_floppy_ops {
56 unsigned char (*fd_inb)(int port);
57 void (*fd_outb)(unsigned char value, int port);
60 static struct sun_floppy_ops sun_fdops;
62 #define fd_inb(port) sun_fdops.fd_inb(port)
63 #define fd_outb(value,port) sun_fdops.fd_outb(value,port)
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_cacheflush(addr, size) /* nothing... */
75 #define fd_request_irq() sun_fd_request_irq()
76 #define fd_free_irq() /* nothing... */
77 #if 0 /* P3: added by Alain, these cause a MMU corruption. 19960524 XXX */
78 #define fd_dma_mem_alloc(size) ((unsigned long) vmalloc(size))
79 #define fd_dma_mem_free(addr,size) (vfree((void *)(addr)))
80 #endif
82 #define FLOPPY_MOTOR_MASK 0x10
84 /* XXX This isn't really correct. XXX */
85 #define get_dma_residue(x) (0)
87 #define FLOPPY0_TYPE 4
88 #define FLOPPY1_TYPE 0
90 /* Super paranoid... */
91 #undef HAVE_DISABLE_HLT
93 /* Here is where we catch the floppy driver trying to initialize,
94 * therefore this is where we call the PROM device tree probing
95 * routine etc. on the Sparc.
97 #define FDC1 sun_floppy_init()
99 #define N_FDC 1
100 #define N_DRIVE 8
102 /* No 64k boundary crossing problems on the Sparc. */
103 #define CROSS_64KB(a,s) (0)
105 /* Routines unique to each controller type on a Sun. */
106 static unsigned char sun_82072_fd_inb(int port)
108 udelay(5);
109 switch(port & 7) {
110 default:
111 printk("floppy: Asked to read unknown port %d\n", port);
112 panic("floppy: Port bolixed.");
113 case 4: /* FD_STATUS */
114 return sun_fdc->status_82072 & ~STATUS_DMA;
115 case 5: /* FD_DATA */
116 return sun_fdc->data_82072;
117 case 7: /* FD_DIR */
118 return (get_auxio() & AUXIO_FLPY_DCHG)? 0x80: 0;
120 panic("sun_82072_fd_inb: How did I get here?");
123 static void sun_82072_fd_outb(unsigned char value, int port)
125 udelay(5);
126 switch(port & 7) {
127 default:
128 printk("floppy: Asked to write to unknown port %d\n", port);
129 panic("floppy: Port bolixed.");
130 case 2: /* FD_DOR */
131 /* Oh geese, 82072 on the Sun has no DOR register,
132 * the functionality is implemented via the AUXIO
133 * I/O register. So we must emulate the behavior.
135 * ASSUMPTIONS: There will only ever be one floppy
136 * drive attached to a Sun controller
137 * and it will be at drive zero.
140 unsigned bits = 0;
141 if (value & 0x10) bits |= AUXIO_FLPY_DSEL;
142 if ((value & 0x80) == 0) bits |= AUXIO_FLPY_EJCT;
143 set_auxio(bits, (~bits) & (AUXIO_FLPY_DSEL|AUXIO_FLPY_EJCT));
145 break;
146 case 5: /* FD_DATA */
147 sun_fdc->data_82072 = value;
148 break;
149 case 7: /* FD_DCR */
150 sun_fdc->dcr_82072 = value;
151 break;
152 case 4: /* FD_STATUS */
153 sun_fdc->status_82072 = value;
154 break;
156 return;
159 static unsigned char sun_82077_fd_inb(int port)
161 udelay(5);
162 switch(port & 7) {
163 default:
164 printk("floppy: Asked to read unknown port %d\n", port);
165 panic("floppy: Port bolixed.");
166 case 4: /* FD_STATUS */
167 return sun_fdc->status_82077 & ~STATUS_DMA;
168 case 5: /* FD_DATA */
169 return sun_fdc->data_82077;
170 case 7: /* FD_DIR */
171 /* XXX: Is DCL on 0x80 in sun4m? */
172 return sun_fdc->dir_82077;
174 panic("sun_82072_fd_inb: How did I get here?");
177 static void sun_82077_fd_outb(unsigned char value, int port)
179 udelay(5);
180 switch(port & 7) {
181 default:
182 printk("floppy: Asked to write to unknown port %d\n", port);
183 panic("floppy: Port bolixed.");
184 case 2: /* FD_DOR */
185 /* Happily, the 82077 has a real DOR register. */
186 sun_fdc->dor_82077 = value;
187 break;
188 case 5: /* FD_DATA */
189 sun_fdc->data_82077 = value;
190 break;
191 case 7: /* FD_DCR */
192 sun_fdc->dcr_82077 = value;
193 break;
194 case 4: /* FD_STATUS */
195 sun_fdc->status_82077 = value;
196 break;
198 return;
201 /* For pseudo-dma (Sun floppy drives have no real DMA available to
202 * them so we must eat the data fifo bytes directly ourselves) we have
203 * three state variables. doing_pdma tells our inline low-level
204 * assembly floppy interrupt entry point whether it should sit and eat
205 * bytes from the fifo or just transfer control up to the higher level
206 * floppy interrupt c-code. I tried very hard but I could not get the
207 * pseudo-dma to work in c-code without getting many overruns and
208 * underruns. If non-zero, doing_pdma encodes the direction of
209 * the transfer for debugging. 1=read 2=write
211 char *pdma_vaddr;
212 unsigned long pdma_size;
213 volatile int doing_pdma = 0;
215 /* This is software state */
216 char *pdma_base = NULL;
217 unsigned long pdma_areasize;
219 /* Common routines to all controller types on the Sparc. */
220 static __inline__ void virtual_dma_init(void)
222 /* nothing... */
225 static __inline__ void sun_fd_disable_dma(void)
227 doing_pdma = 0;
228 if (pdma_base) {
229 mmu_unlockarea(pdma_base, pdma_areasize);
230 pdma_base = NULL;
234 static __inline__ void sun_fd_set_dma_mode(int mode)
236 switch(mode) {
237 case DMA_MODE_READ:
238 doing_pdma = 1;
239 break;
240 case DMA_MODE_WRITE:
241 doing_pdma = 2;
242 break;
243 default:
244 printk("Unknown dma mode %d\n", mode);
245 panic("floppy: Giving up...");
249 static __inline__ void sun_fd_set_dma_addr(char *buffer)
251 pdma_vaddr = buffer;
254 static __inline__ void sun_fd_set_dma_count(int length)
256 pdma_size = length;
259 static __inline__ void sun_fd_enable_dma(void)
261 pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
262 pdma_base = pdma_vaddr;
263 pdma_areasize = pdma_size;
266 /* Our low-level entry point in arch/sparc/kernel/entry.S */
267 irqreturn_t floppy_hardint(int irq, void *unused, struct pt_regs *regs);
269 static int sun_fd_request_irq(void)
271 static int once = 0;
272 int error;
274 if(!once) {
275 once = 1;
276 error = request_fast_irq(FLOPPY_IRQ, floppy_hardint, SA_INTERRUPT, "floppy");
277 return ((error == 0) ? 0 : -1);
278 } else return 0;
281 static struct linux_prom_registers fd_regs[2];
283 static int sun_floppy_init(void)
285 char state[128];
286 int tnode, fd_node, num_regs;
287 struct resource r;
289 use_virtual_dma = 1;
291 FLOPPY_IRQ = 11;
292 /* Forget it if we aren't on a machine that could possibly
293 * ever have a floppy drive.
295 if((sparc_cpu_model != sun4c && sparc_cpu_model != sun4m) ||
296 ((idprom->id_machtype == (SM_SUN4C | SM_4C_SLC)) ||
297 (idprom->id_machtype == (SM_SUN4C | SM_4C_ELC)))) {
298 /* We certainly don't have a floppy controller. */
299 goto no_sun_fdc;
301 /* Well, try to find one. */
302 tnode = prom_getchild(prom_root_node);
303 fd_node = prom_searchsiblings(tnode, "obio");
304 if(fd_node != 0) {
305 tnode = prom_getchild(fd_node);
306 fd_node = prom_searchsiblings(tnode, "SUNW,fdtwo");
307 } else {
308 fd_node = prom_searchsiblings(tnode, "fd");
310 if(fd_node == 0) {
311 goto no_sun_fdc;
314 /* The sun4m lets us know if the controller is actually usable. */
315 if(sparc_cpu_model == sun4m &&
316 prom_getproperty(fd_node, "status", state, sizeof(state)) != -1) {
317 if(!strcmp(state, "disabled")) {
318 goto no_sun_fdc;
321 num_regs = prom_getproperty(fd_node, "reg", (char *) fd_regs, sizeof(fd_regs));
322 num_regs = (num_regs / sizeof(fd_regs[0]));
323 prom_apply_obio_ranges(fd_regs, num_regs);
324 memset(&r, 0, sizeof(r));
325 r.flags = fd_regs[0].which_io;
326 r.start = fd_regs[0].phys_addr;
327 sun_fdc = (struct sun_flpy_controller *)
328 sbus_ioremap(&r, 0, fd_regs[0].reg_size, "floppy");
330 /* Last minute sanity check... */
331 if(sun_fdc->status_82072 == 0xff) {
332 sun_fdc = NULL;
333 goto no_sun_fdc;
336 if(sparc_cpu_model == sun4c) {
337 sun_fdops.fd_inb = sun_82072_fd_inb;
338 sun_fdops.fd_outb = sun_82072_fd_outb;
339 fdc_status = &sun_fdc->status_82072;
340 /* printk("AUXIO @0x%lx\n", auxio_register); */ /* P3 */
341 } else {
342 sun_fdops.fd_inb = sun_82077_fd_inb;
343 sun_fdops.fd_outb = sun_82077_fd_outb;
344 fdc_status = &sun_fdc->status_82077;
345 /* printk("DOR @0x%p\n", &sun_fdc->dor_82077); */ /* P3 */
348 /* Success... */
349 allowed_drive_mask = 0x01;
350 return (int) sun_fdc;
352 no_sun_fdc:
353 return -1;
356 static int sparc_eject(void)
358 set_dor(0x00, 0xff, 0x90);
359 udelay(500);
360 set_dor(0x00, 0x6f, 0x00);
361 udelay(500);
362 return 0;
365 #define fd_eject(drive) sparc_eject()
367 #define EXTRA_FLOPPY_PARAMS
369 #endif /* !(__ASM_SPARC_FLOPPY_H) */