1 /* asm/floppy.h: Sparc specific parts of the Floppy driver.
3 * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
6 #ifndef __ASM_SPARC_FLOPPY_H
7 #define __ASM_SPARC_FLOPPY_H
10 #include <linux/of_device.h>
12 #include <asm/pgtable.h>
13 #include <asm/idprom.h>
14 #include <asm/oplib.h>
15 #include <asm/auxio.h>
16 #include <asm/setup.h>
20 /* We don't need no stinkin' I/O port allocation crap. */
23 #define release_region(X, Y) do { } while(0)
24 #define request_region(X, Y, Z) (1)
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;
54 struct sun_floppy_ops {
55 unsigned char (*fd_inb)(int port);
56 void (*fd_outb)(unsigned char value, int port);
59 static struct sun_floppy_ops sun_fdops;
61 #define fd_inb(port) sun_fdops.fd_inb(port)
62 #define fd_outb(value,port) sun_fdops.fd_outb(value,port)
63 #define fd_enable_dma() sun_fd_enable_dma()
64 #define fd_disable_dma() sun_fd_disable_dma()
65 #define fd_request_dma() (0) /* nothing... */
66 #define fd_free_dma() /* nothing... */
67 #define fd_clear_dma_ff() /* nothing... */
68 #define fd_set_dma_mode(mode) sun_fd_set_dma_mode(mode)
69 #define fd_set_dma_addr(addr) sun_fd_set_dma_addr(addr)
70 #define fd_set_dma_count(count) sun_fd_set_dma_count(count)
71 #define fd_enable_irq() /* nothing... */
72 #define fd_disable_irq() /* nothing... */
73 #define fd_request_irq() sun_fd_request_irq()
74 #define fd_free_irq() /* nothing... */
75 #if 0 /* P3: added by Alain, these cause a MMU corruption. 19960524 XXX */
76 #define fd_dma_mem_alloc(size) ((unsigned long) vmalloc(size))
77 #define fd_dma_mem_free(addr,size) (vfree((void *)(addr)))
80 /* XXX This isn't really correct. XXX */
81 #define get_dma_residue(x) (0)
83 #define FLOPPY0_TYPE 4
84 #define FLOPPY1_TYPE 0
86 /* Super paranoid... */
87 #undef HAVE_DISABLE_HLT
89 /* Here is where we catch the floppy driver trying to initialize,
90 * therefore this is where we call the PROM device tree probing
91 * routine etc. on the Sparc.
93 #define FDC1 sun_floppy_init()
98 /* No 64k boundary crossing problems on the Sparc. */
99 #define CROSS_64KB(a,s) (0)
101 /* Routines unique to each controller type on a Sun. */
102 static void sun_set_dor(unsigned char value, int fdc_82077)
105 sun_fdc->dor_82077 = value;
108 static unsigned char sun_read_dir(void)
110 return sun_fdc->dir_82077;
113 static unsigned char sun_82072_fd_inb(int port)
118 printk("floppy: Asked to read unknown port %d\n", port);
119 panic("floppy: Port bolixed.");
120 case 4: /* FD_STATUS */
121 return sun_fdc->status_82072 & ~STATUS_DMA;
122 case 5: /* FD_DATA */
123 return sun_fdc->data_82072;
125 return sun_read_dir();
127 panic("sun_82072_fd_inb: How did I get here?");
130 static void sun_82072_fd_outb(unsigned char value, int port)
135 printk("floppy: Asked to write to unknown port %d\n", port);
136 panic("floppy: Port bolixed.");
138 sun_set_dor(value, 0);
140 case 5: /* FD_DATA */
141 sun_fdc->data_82072 = value;
144 sun_fdc->dcr_82072 = value;
146 case 4: /* FD_STATUS */
147 sun_fdc->status_82072 = value;
153 static unsigned char sun_82077_fd_inb(int port)
158 printk("floppy: Asked to read unknown port %d\n", port);
159 panic("floppy: Port bolixed.");
160 case 0: /* FD_STATUS_0 */
161 return sun_fdc->status1_82077;
162 case 1: /* FD_STATUS_1 */
163 return sun_fdc->status2_82077;
165 return sun_fdc->dor_82077;
167 return sun_fdc->tapectl_82077;
168 case 4: /* FD_STATUS */
169 return sun_fdc->status_82077 & ~STATUS_DMA;
170 case 5: /* FD_DATA */
171 return sun_fdc->data_82077;
173 return sun_read_dir();
175 panic("sun_82077_fd_inb: How did I get here?");
178 static void sun_82077_fd_outb(unsigned char value, int port)
183 printk("floppy: Asked to write to unknown port %d\n", port);
184 panic("floppy: Port bolixed.");
186 sun_set_dor(value, 1);
188 case 5: /* FD_DATA */
189 sun_fdc->data_82077 = value;
192 sun_fdc->dcr_82077 = value;
194 case 4: /* FD_STATUS */
195 sun_fdc->status_82077 = value;
198 sun_fdc->tapectl_82077 = value;
204 /* For pseudo-dma (Sun floppy drives have no real DMA available to
205 * them so we must eat the data fifo bytes directly ourselves) we have
206 * three state variables. doing_pdma tells our inline low-level
207 * assembly floppy interrupt entry point whether it should sit and eat
208 * bytes from the fifo or just transfer control up to the higher level
209 * floppy interrupt c-code. I tried very hard but I could not get the
210 * pseudo-dma to work in c-code without getting many overruns and
211 * underruns. If non-zero, doing_pdma encodes the direction of
212 * the transfer for debugging. 1=read 2=write
215 /* Common routines to all controller types on the Sparc. */
216 static inline void virtual_dma_init(void)
221 static inline void sun_fd_disable_dma(void)
227 static inline void sun_fd_set_dma_mode(int mode)
237 printk("Unknown dma mode %d\n", mode);
238 panic("floppy: Giving up...");
242 static inline void sun_fd_set_dma_addr(char *buffer)
247 static inline void sun_fd_set_dma_count(int length)
252 static inline void sun_fd_enable_dma(void)
254 pdma_base = pdma_vaddr;
255 pdma_areasize = pdma_size;
258 int sparc_floppy_request_irq(unsigned int irq, irq_handler_t irq_handler);
260 static int sun_fd_request_irq(void)
266 return sparc_floppy_request_irq(FLOPPY_IRQ, floppy_interrupt);
272 static struct linux_prom_registers fd_regs[2];
274 static int sun_floppy_init(void)
276 struct platform_device *op;
277 struct device_node *dp;
286 /* Forget it if we aren't on a machine that could possibly
287 * ever have a floppy drive.
289 if (sparc_cpu_model != sun4m) {
290 /* We certainly don't have a floppy controller. */
293 /* Well, try to find one. */
294 tnode = prom_getchild(prom_root_node);
295 fd_node = prom_searchsiblings(tnode, "obio");
297 tnode = prom_getchild(fd_node);
298 fd_node = prom_searchsiblings(tnode, "SUNW,fdtwo");
300 fd_node = prom_searchsiblings(tnode, "fd");
306 /* The sun4m lets us know if the controller is actually usable. */
307 if (prom_getproperty(fd_node, "status", state, sizeof(state)) != -1) {
308 if(!strcmp(state, "disabled")) {
312 num_regs = prom_getproperty(fd_node, "reg", (char *) fd_regs, sizeof(fd_regs));
313 num_regs = (num_regs / sizeof(fd_regs[0]));
314 prom_apply_obio_ranges(fd_regs, num_regs);
315 memset(&r, 0, sizeof(r));
316 r.flags = fd_regs[0].which_io;
317 r.start = fd_regs[0].phys_addr;
318 sun_fdc = of_ioremap(&r, 0, fd_regs[0].reg_size, "floppy");
320 /* Look up irq in platform_device.
321 * We try "SUNW,fdtwo" and "fd"
324 for_each_node_by_name(dp, "SUNW,fdtwo") {
325 op = of_find_device_by_node(dp);
330 for_each_node_by_name(dp, "fd") {
331 op = of_find_device_by_node(dp);
339 FLOPPY_IRQ = op->archdata.irqs[0];
341 /* Last minute sanity check... */
342 if (sun_fdc->status_82072 == 0xff) {
347 sun_fdops.fd_inb = sun_82077_fd_inb;
348 sun_fdops.fd_outb = sun_82077_fd_outb;
349 fdc_status = &sun_fdc->status_82077;
351 if (sun_fdc->dor_82077 == 0x80) {
352 sun_fdc->dor_82077 = 0x02;
353 if (sun_fdc->dor_82077 == 0x80) {
354 sun_fdops.fd_inb = sun_82072_fd_inb;
355 sun_fdops.fd_outb = sun_82072_fd_outb;
356 fdc_status = &sun_fdc->status_82072;
361 allowed_drive_mask = 0x01;
362 return (int) sun_fdc;
368 static int sparc_eject(void)
370 set_dor(0x00, 0xff, 0x90);
372 set_dor(0x00, 0x6f, 0x00);
377 #define fd_eject(drive) sparc_eject()
379 #define EXTRA_FLOPPY_PARAMS
381 static DEFINE_SPINLOCK(dma_spin_lock);
383 #define claim_dma_lock() \
384 ({ unsigned long flags; \
385 spin_lock_irqsave(&dma_spin_lock, flags); \
389 #define release_dma_lock(__flags) \
390 spin_unlock_irqrestore(&dma_spin_lock, __flags);
392 #endif /* !(__ASM_SPARC_FLOPPY_H) */