1 /* asm-sparc/floppy.h: Sparc specific parts of the Floppy driver.
3 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 #ifndef __ASM_SPARC_FLOPPY_H
7 #define __ASM_SPARC_FLOPPY_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>
18 /* We don't need no stinkin' I/O port allocation crap. */
22 #define release_region(X, Y) do { } while(0)
23 #define check_region(X, Y) (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
;
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)))
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()
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
)
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
;
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
)
128 printk("floppy: Asked to write to unknown port %d\n", port
);
129 panic("floppy: Port bolixed.");
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.
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
));
146 case 5: /* FD_DATA */
147 sun_fdc
->data_82072
= value
;
150 sun_fdc
->dcr_82072
= value
;
152 case 4: /* FD_STATUS */
153 sun_fdc
->status_82072
= value
;
159 static unsigned char sun_82077_fd_inb(int port
)
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
;
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
)
182 printk("floppy: Asked to write to unknown port %d\n", port
);
183 panic("floppy: Port bolixed.");
185 /* Happily, the 82077 has a real DOR register. */
186 sun_fdc
->dor_82077
= value
;
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
;
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
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)
225 static __inline__
void sun_fd_disable_dma(void)
229 mmu_unlockarea(pdma_base
, pdma_areasize
);
234 static __inline__
void sun_fd_set_dma_mode(int mode
)
244 printk("Unknown dma mode %d\n", mode
);
245 panic("floppy: Giving up...");
249 static __inline__
void sun_fd_set_dma_addr(char *buffer
)
254 static __inline__
void sun_fd_set_dma_count(int 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)
276 error
= request_fast_irq(FLOPPY_IRQ
, floppy_hardint
, SA_INTERRUPT
, "floppy");
277 return ((error
== 0) ? 0 : -1);
281 static struct linux_prom_registers fd_regs
[2];
283 static int sun_floppy_init(void)
286 int tnode
, fd_node
, num_regs
;
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. */
301 /* Well, try to find one. */
302 tnode
= prom_getchild(prom_root_node
);
303 fd_node
= prom_searchsiblings(tnode
, "obio");
305 tnode
= prom_getchild(fd_node
);
306 fd_node
= prom_searchsiblings(tnode
, "SUNW,fdtwo");
308 fd_node
= prom_searchsiblings(tnode
, "fd");
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")) {
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) {
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 */
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 */
349 allowed_drive_mask
= 0x01;
350 return (int) sun_fdc
;
356 static int sparc_eject(void)
358 set_dor(0x00, 0xff, 0x90);
360 set_dor(0x00, 0x6f, 0x00);
365 #define fd_eject(drive) sparc_eject()
367 #define EXTRA_FLOPPY_PARAMS
369 #endif /* !(__ASM_SPARC_FLOPPY_H) */