aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-sparc/floppy.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-sparc/floppy.h')
-rw-r--r--include/asm-sparc/floppy.h369
1 files changed, 369 insertions, 0 deletions
diff --git a/include/asm-sparc/floppy.h b/include/asm-sparc/floppy.h
new file mode 100644
index 000000000000..780ee7ff9dc3
--- /dev/null
+++ b/include/asm-sparc/floppy.h
@@ -0,0 +1,369 @@
1/* asm-sparc/floppy.h: Sparc specific parts of the Floppy driver.
2 *
3 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
4 */
5
6#ifndef __ASM_SPARC_FLOPPY_H
7#define __ASM_SPARC_FLOPPY_H
8
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>
17
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)
25
26/* References:
27 * 1) Netbsd Sun floppy driver.
28 * 2) NCR 82077 controller manual
29 * 3) Intel 82077 controller manual
30 */
31struct 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 */
35
36 volatile unsigned char data_82072; /* Data fifo. */
37#define status2_82077 data_82072 /* Auxiliary Status reg. 2 */
38
39 volatile unsigned char dor_82077; /* Digital Output reg. */
40 volatile unsigned char tapectl_82077; /* What the? Tape control reg? */
41
42 volatile unsigned char status_82077; /* Main Status Register. */
43#define drs_82077 status_82077 /* Digital Rate Select reg. */
44
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 a SparcStation anyways. */
52static struct sun_flpy_controller *sun_fdc = NULL;
53volatile unsigned char *fdc_status;
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(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
81
82#define FLOPPY_MOTOR_MASK 0x10
83
84/* XXX This isn't really correct. XXX */
85#define get_dma_residue(x) (0)
86
87#define FLOPPY0_TYPE 4
88#define FLOPPY1_TYPE 0
89
90/* Super paranoid... */
91#undef HAVE_DISABLE_HLT
92
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.
96 */
97#define FDC1 sun_floppy_init()
98
99#define N_FDC 1
100#define N_DRIVE 8
101
102/* No 64k boundary crossing problems on the Sparc. */
103#define CROSS_64KB(a,s) (0)
104
105/* Routines unique to each controller type on a Sun. */
106static unsigned char sun_82072_fd_inb(int port)
107{
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;
119 };
120 panic("sun_82072_fd_inb: How did I get here?");
121}
122
123static void sun_82072_fd_outb(unsigned char value, int port)
124{
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.
134 *
135 * ASSUMPTIONS: There will only ever be one floppy
136 * drive attached to a Sun controller
137 * and it will be at drive zero.
138 */
139 {
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));
144 }
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;
155 };
156 return;
157}
158
159static unsigned char sun_82077_fd_inb(int port)
160{
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;
173 };
174 panic("sun_82072_fd_inb: How did I get here?");
175}
176
177static void sun_82077_fd_outb(unsigned char value, int port)
178{
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;
197 };
198 return;
199}
200
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
210 */
211char *pdma_vaddr;
212unsigned long pdma_size;
213volatile int doing_pdma = 0;
214
215/* This is software state */
216char *pdma_base = NULL;
217unsigned long pdma_areasize;
218
219/* Common routines to all controller types on the Sparc. */
220static __inline__ void virtual_dma_init(void)
221{
222 /* nothing... */
223}
224
225static __inline__ void sun_fd_disable_dma(void)
226{
227 doing_pdma = 0;
228 if (pdma_base) {
229 mmu_unlockarea(pdma_base, pdma_areasize);
230 pdma_base = 0;
231 }
232}
233
234static __inline__ void sun_fd_set_dma_mode(int mode)
235{
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...");
246 }
247}
248
249static __inline__ void sun_fd_set_dma_addr(char *buffer)
250{
251 pdma_vaddr = buffer;
252}
253
254static __inline__ void sun_fd_set_dma_count(int length)
255{
256 pdma_size = length;
257}
258
259static __inline__ void sun_fd_enable_dma(void)
260{
261 pdma_vaddr = mmu_lockarea(pdma_vaddr, pdma_size);
262 pdma_base = pdma_vaddr;
263 pdma_areasize = pdma_size;
264}
265
266/* Our low-level entry point in arch/sparc/kernel/entry.S */
267irqreturn_t floppy_hardint(int irq, void *unused, struct pt_regs *regs);
268
269static int sun_fd_request_irq(void)
270{
271 static int once = 0;
272 int error;
273
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;
279}
280
281static struct linux_prom_registers fd_regs[2];
282
283static int sun_floppy_init(void)
284{
285 char state[128];
286 int tnode, fd_node, num_regs;
287 struct resource r;
288
289 use_virtual_dma = 1;
290
291 FLOPPY_IRQ = 11;
292 /* Forget it if we aren't on a machine that could possibly
293 * ever have a floppy drive.
294 */
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;
300 }
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");
309 }
310 if(fd_node == 0) {
311 goto no_sun_fdc;
312 }
313
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;
319 }
320 }
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");
329
330 /* Last minute sanity check... */
331 if(sun_fdc->status_82072 == 0xff) {
332 sun_fdc = NULL;
333 goto no_sun_fdc;
334 }
335
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 */
346 }
347
348 /* Success... */
349 allowed_drive_mask = 0x01;
350 return (int) sun_fdc;
351
352no_sun_fdc:
353 return -1;
354}
355
356static int sparc_eject(void)
357{
358 set_dor(0x00, 0xff, 0x90);
359 udelay(500);
360 set_dor(0x00, 0x6f, 0x00);
361 udelay(500);
362 return 0;
363}
364
365#define fd_eject(drive) sparc_eject()
366
367#define EXTRA_FLOPPY_PARAMS
368
369#endif /* !(__ASM_SPARC_FLOPPY_H) */