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>
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>
21 /* We don't need no stinkin' I/O port allocation crap. */
24 #define release_region(X, Y) do { } while(0)
25 #define request_region(X, Y, Z) (1)
28 * 1) Netbsd Sun floppy driver.
29 * 2) NCR 82077 controller manual
30 * 3) Intel 82077 controller manual
32 struct 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 */
37 volatile unsigned char data_82072
; /* Data fifo. */
38 #define status2_82077 data_82072 /* Auxiliary Status reg. 2 */
40 volatile unsigned char dor_82077
; /* Digital Output reg. */
41 volatile unsigned char tapectl_82077
; /* What the? Tape control reg? */
43 volatile unsigned char status_82077
; /* Main Status Register. */
44 #define drs_82077 status_82077 /* Digital Rate Select reg. */
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. */
52 /* You'll only ever find one controller on a SparcStation anyways. */
53 static struct sun_flpy_controller
*sun_fdc
= NULL
;
54 extern volatile unsigned char *fdc_status
;
56 struct sun_floppy_ops
{
57 unsigned char (*fd_inb
)(int port
);
58 void (*fd_outb
)(unsigned char value
, int port
);
61 static struct sun_floppy_ops sun_fdops
;
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)))
83 /* XXX This isn't really correct. XXX */
84 #define get_dma_residue(x) (0)
86 #define FLOPPY0_TYPE 4
87 #define FLOPPY1_TYPE 0
89 /* Super paranoid... */
90 #undef HAVE_DISABLE_HLT
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.
96 #define FDC1 sun_floppy_init()
101 /* No 64k boundary crossing problems on the Sparc. */
102 #define CROSS_64KB(a,s) (0)
104 /* Routines unique to each controller type on a Sun. */
105 static void sun_set_dor(unsigned char value
, int fdc_82077
)
107 if (sparc_cpu_model
== sun4c
) {
108 unsigned int bits
= 0;
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
));
116 sun_fdc
->dor_82077
= value
;
120 static unsigned char sun_read_dir(void)
122 if (sparc_cpu_model
== sun4c
)
123 return (get_auxio() & AUXIO_FLPY_DCHG
) ? 0x80 : 0;
125 return sun_fdc
->dir_82077
;
128 static unsigned char sun_82072_fd_inb(int port
)
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
;
140 return sun_read_dir();
142 panic("sun_82072_fd_inb: How did I get here?");
145 static void sun_82072_fd_outb(unsigned char value
, int port
)
150 printk("floppy: Asked to write to unknown port %d\n", port
);
151 panic("floppy: Port bolixed.");
153 sun_set_dor(value
, 0);
155 case 5: /* FD_DATA */
156 sun_fdc
->data_82072
= value
;
159 sun_fdc
->dcr_82072
= value
;
161 case 4: /* FD_STATUS */
162 sun_fdc
->status_82072
= value
;
168 static unsigned char sun_82077_fd_inb(int port
)
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
;
180 return sun_fdc
->dor_82077
;
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
;
188 return sun_read_dir();
190 panic("sun_82077_fd_inb: How did I get here?");
193 static void sun_82077_fd_outb(unsigned char value
, int port
)
198 printk("floppy: Asked to write to unknown port %d\n", port
);
199 panic("floppy: Port bolixed.");
201 sun_set_dor(value
, 1);
203 case 5: /* FD_DATA */
204 sun_fdc
->data_82077
= value
;
207 sun_fdc
->dcr_82077
= value
;
209 case 4: /* FD_STATUS */
210 sun_fdc
->status_82077
= value
;
213 sun_fdc
->tapectl_82077
= value
;
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
229 extern char *pdma_vaddr
;
230 extern unsigned long pdma_size
;
231 extern volatile int doing_pdma
;
233 /* This is software state */
234 extern char *pdma_base
;
235 extern unsigned long pdma_areasize
;
237 /* Common routines to all controller types on the Sparc. */
238 static inline void virtual_dma_init(void)
243 static inline void sun_fd_disable_dma(void)
247 mmu_unlockarea(pdma_base
, pdma_areasize
);
252 static inline void sun_fd_set_dma_mode(int mode
)
262 printk("Unknown dma mode %d\n", mode
);
263 panic("floppy: Giving up...");
267 static inline void sun_fd_set_dma_addr(char *buffer
)
272 static inline void sun_fd_set_dma_count(int length
)
277 static inline void sun_fd_enable_dma(void)
279 pdma_vaddr
= mmu_lockarea(pdma_vaddr
, pdma_size
);
280 pdma_base
= pdma_vaddr
;
281 pdma_areasize
= pdma_size
;
284 extern int sparc_floppy_request_irq(unsigned int irq
,
285 irq_handler_t irq_handler
);
287 static int sun_fd_request_irq(void)
293 return sparc_floppy_request_irq(FLOPPY_IRQ
, floppy_interrupt
);
299 static struct linux_prom_registers fd_regs
[2];
301 static int sun_floppy_init(void)
303 struct platform_device
*op
;
304 struct device_node
*dp
;
306 phandle tnode
, fd_node
;
312 /* Forget it if we aren't on a machine that could possibly
313 * ever have a floppy drive.
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. */
321 /* Well, try to find one. */
322 tnode
= prom_getchild(prom_root_node
);
323 fd_node
= prom_searchsiblings(tnode
, "obio");
325 tnode
= prom_getchild(fd_node
);
326 fd_node
= prom_searchsiblings(tnode
, "SUNW,fdtwo");
328 fd_node
= prom_searchsiblings(tnode
, "fd");
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")) {
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");
350 /* Look up irq in platform_device.
351 * We try "SUNW,fdtwo" and "fd"
353 for_each_node_by_name(dp
, "SUNW,fdtwo") {
354 op
= of_find_device_by_node(dp
);
359 for_each_node_by_name(dp
, "fd") {
360 op
= of_find_device_by_node(dp
);
368 FLOPPY_IRQ
= op
->archdata
.irqs
[0];
370 /* Last minute sanity check... */
371 if(sun_fdc
->status_82072
== 0xff) {
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
;
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
;
390 allowed_drive_mask
= 0x01;
391 return (int) sun_fdc
;
397 static int sparc_eject(void)
399 set_dor(0x00, 0xff, 0x90);
401 set_dor(0x00, 0x6f, 0x00);
406 #define fd_eject(drive) sparc_eject()
408 #define EXTRA_FLOPPY_PARAMS
410 static DEFINE_SPINLOCK(dma_spin_lock
);
412 #define claim_dma_lock() \
413 ({ unsigned long flags; \
414 spin_lock_irqsave(&dma_spin_lock, flags); \
418 #define release_dma_lock(__flags) \
419 spin_unlock_irqrestore(&dma_spin_lock, __flags);
421 #endif /* !(__ASM_SPARC_FLOPPY_H) */