1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* asm/floppy.h: Sparc specific parts of the Floppy driver.
4 * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
7 #ifndef __ASM_SPARC_FLOPPY_H
8 #define __ASM_SPARC_FLOPPY_H
11 #include <linux/of_device.h>
13 #include <linux/pgtable.h>
14 #include <asm/idprom.h>
15 #include <asm/oplib.h>
16 #include <asm/auxio.h>
17 #include <asm/setup.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
;
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(base, reg) sun_fdops.fd_inb(reg)
63 #define fd_outb(value, base, reg) sun_fdops.fd_outb(value, reg)
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_request_irq() sun_fd_request_irq()
75 #define fd_free_irq() /* nothing... */
76 #if 0 /* P3: added by Alain, these cause a MMU corruption. 19960524 XXX */
77 #define fd_dma_mem_alloc(size) ((unsigned long) vmalloc(size))
78 #define fd_dma_mem_free(addr,size) (vfree((void *)(addr)))
81 /* XXX This isn't really correct. XXX */
82 #define get_dma_residue(x) (0)
84 #define FLOPPY0_TYPE 4
85 #define FLOPPY1_TYPE 0
87 /* Super paranoid... */
88 #undef HAVE_DISABLE_HLT
90 /* Here is where we catch the floppy driver trying to initialize,
91 * therefore this is where we call the PROM device tree probing
92 * routine etc. on the Sparc.
94 #define FDC1 sun_floppy_init()
99 /* No 64k boundary crossing problems on the Sparc. */
100 #define CROSS_64KB(a,s) (0)
102 /* Routines unique to each controller type on a Sun. */
103 static void sun_set_dor(unsigned char value
, int fdc_82077
)
106 sun_fdc
->dor_82077
= value
;
109 static unsigned char sun_read_dir(void)
111 return sun_fdc
->dir_82077
;
114 static unsigned char sun_82072_fd_inb(int port
)
119 printk("floppy: Asked to read unknown port %d\n", port
);
120 panic("floppy: Port bolixed.");
122 return sun_fdc
->status_82072
& ~STATUS_DMA
;
124 return sun_fdc
->data_82072
;
126 return sun_read_dir();
128 panic("sun_82072_fd_inb: How did I get here?");
131 static void sun_82072_fd_outb(unsigned char value
, int port
)
136 printk("floppy: Asked to write to unknown port %d\n", port
);
137 panic("floppy: Port bolixed.");
139 sun_set_dor(value
, 0);
142 sun_fdc
->data_82072
= value
;
145 sun_fdc
->dcr_82072
= value
;
148 sun_fdc
->status_82072
= value
;
154 static unsigned char sun_82077_fd_inb(int port
)
159 printk("floppy: Asked to read unknown port %d\n", port
);
160 panic("floppy: Port bolixed.");
162 return sun_fdc
->status1_82077
;
164 return sun_fdc
->status2_82077
;
166 return sun_fdc
->dor_82077
;
168 return sun_fdc
->tapectl_82077
;
170 return sun_fdc
->status_82077
& ~STATUS_DMA
;
172 return sun_fdc
->data_82077
;
174 return sun_read_dir();
176 panic("sun_82077_fd_inb: How did I get here?");
179 static void sun_82077_fd_outb(unsigned char value
, int port
)
184 printk("floppy: Asked to write to unknown port %d\n", port
);
185 panic("floppy: Port bolixed.");
187 sun_set_dor(value
, 1);
190 sun_fdc
->data_82077
= value
;
193 sun_fdc
->dcr_82077
= value
;
196 sun_fdc
->status_82077
= value
;
199 sun_fdc
->tapectl_82077
= value
;
205 /* For pseudo-dma (Sun floppy drives have no real DMA available to
206 * them so we must eat the data fifo bytes directly ourselves) we have
207 * three state variables. doing_pdma tells our inline low-level
208 * assembly floppy interrupt entry point whether it should sit and eat
209 * bytes from the fifo or just transfer control up to the higher level
210 * floppy interrupt c-code. I tried very hard but I could not get the
211 * pseudo-dma to work in c-code without getting many overruns and
212 * underruns. If non-zero, doing_pdma encodes the direction of
213 * the transfer for debugging. 1=read 2=write
216 /* Common routines to all controller types on the Sparc. */
217 static inline void virtual_dma_init(void)
222 static inline void sun_fd_disable_dma(void)
228 static inline void sun_fd_set_dma_mode(int mode
)
238 printk("Unknown dma mode %d\n", mode
);
239 panic("floppy: Giving up...");
243 static inline void sun_fd_set_dma_addr(char *buffer
)
248 static inline void sun_fd_set_dma_count(int length
)
253 static inline void sun_fd_enable_dma(void)
255 pdma_base
= pdma_vaddr
;
256 pdma_areasize
= pdma_size
;
259 int sparc_floppy_request_irq(unsigned int irq
, irq_handler_t irq_handler
);
261 static int sun_fd_request_irq(void)
267 return sparc_floppy_request_irq(FLOPPY_IRQ
, floppy_interrupt
);
273 static struct linux_prom_registers fd_regs
[2];
275 static int sun_floppy_init(void)
277 struct platform_device
*op
;
278 struct device_node
*dp
;
287 /* Forget it if we aren't on a machine that could possibly
288 * ever have a floppy drive.
290 if (sparc_cpu_model
!= sun4m
) {
291 /* We certainly don't have a floppy controller. */
294 /* Well, try to find one. */
295 tnode
= prom_getchild(prom_root_node
);
296 fd_node
= prom_searchsiblings(tnode
, "obio");
298 tnode
= prom_getchild(fd_node
);
299 fd_node
= prom_searchsiblings(tnode
, "SUNW,fdtwo");
301 fd_node
= prom_searchsiblings(tnode
, "fd");
307 /* The sun4m lets us know if the controller is actually usable. */
308 if (prom_getproperty(fd_node
, "status", state
, sizeof(state
)) != -1) {
309 if(!strcmp(state
, "disabled")) {
313 num_regs
= prom_getproperty(fd_node
, "reg", (char *) fd_regs
, sizeof(fd_regs
));
314 num_regs
= (num_regs
/ sizeof(fd_regs
[0]));
315 prom_apply_obio_ranges(fd_regs
, num_regs
);
316 memset(&r
, 0, sizeof(r
));
317 r
.flags
= fd_regs
[0].which_io
;
318 r
.start
= fd_regs
[0].phys_addr
;
319 sun_fdc
= of_ioremap(&r
, 0, fd_regs
[0].reg_size
, "floppy");
321 /* Look up irq in platform_device.
322 * We try "SUNW,fdtwo" and "fd"
325 for_each_node_by_name(dp
, "SUNW,fdtwo") {
326 op
= of_find_device_by_node(dp
);
331 for_each_node_by_name(dp
, "fd") {
332 op
= of_find_device_by_node(dp
);
340 FLOPPY_IRQ
= op
->archdata
.irqs
[0];
342 /* Last minute sanity check... */
343 if (sun_fdc
->status_82072
== 0xff) {
348 sun_fdops
.fd_inb
= sun_82077_fd_inb
;
349 sun_fdops
.fd_outb
= sun_82077_fd_outb
;
350 fdc_status
= &sun_fdc
->status_82077
;
352 if (sun_fdc
->dor_82077
== 0x80) {
353 sun_fdc
->dor_82077
= 0x02;
354 if (sun_fdc
->dor_82077
== 0x80) {
355 sun_fdops
.fd_inb
= sun_82072_fd_inb
;
356 sun_fdops
.fd_outb
= sun_82072_fd_outb
;
357 fdc_status
= &sun_fdc
->status_82072
;
362 allowed_drive_mask
= 0x01;
363 return (int) sun_fdc
;
369 static int sparc_eject(void)
371 set_dor(0x00, 0xff, 0x90);
373 set_dor(0x00, 0x6f, 0x00);
378 #define fd_eject(drive) sparc_eject()
380 #define EXTRA_FLOPPY_PARAMS
382 static DEFINE_SPINLOCK(dma_spin_lock
);
384 #define claim_dma_lock() \
385 ({ unsigned long flags; \
386 spin_lock_irqsave(&dma_spin_lock, flags); \
390 #define release_dma_lock(__flags) \
391 spin_unlock_irqrestore(&dma_spin_lock, __flags);
393 #endif /* !(__ASM_SPARC_FLOPPY_H) */