2 * Implementation independent bits of the Floppy driver.
4 * much of this file is derived from what was originally the Q40 floppy driver.
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
10 * Copyright (C) 1999, 2000, 2001
12 * Sun3x support added 2/4/2000 Sam Creasey (sammy@sammy.net)
18 #include <linux/vmalloc.h>
20 asmlinkage irqreturn_t
floppy_hardint(int irq
, void *dev_id
);
24 #undef MAX_DMA_ADDRESS
25 #define MAX_DMA_ADDRESS 0x00 /* nothing like that */
29 * Again, the CMOS information doesn't work on m68k..
31 #define FLOPPY0_TYPE (MACH_IS_Q40 ? 6 : 4)
32 #define FLOPPY1_TYPE 0
34 #define FLOPPY_MOTOR_MASK 0xf0
37 /* basically PC init + set use_virtual_dma */
38 #define FDC1 m68k_floppy_init()
44 /* vdma globals adapted from asm-i386/floppy.h */
46 static int virtual_dma_count
=0;
47 static int virtual_dma_residue
=0;
48 static char *virtual_dma_addr
=NULL
;
49 static int virtual_dma_mode
=0;
50 static int doing_pdma
=0;
52 #include <asm/sun3xflop.h>
54 extern spinlock_t dma_spin_lock
;
56 static __inline__
unsigned long claim_dma_lock(void)
59 spin_lock_irqsave(&dma_spin_lock
, flags
);
63 static __inline__
void release_dma_lock(unsigned long flags
)
65 spin_unlock_irqrestore(&dma_spin_lock
, flags
);
69 static __inline__
unsigned char fd_inb(int port
)
73 else if(MACH_IS_SUN3X
)
74 return sun3x_82072_fd_inb(port
);
78 static __inline__
void fd_outb(unsigned char value
, int port
)
82 else if(MACH_IS_SUN3X
)
83 sun3x_82072_fd_outb(value
, port
);
87 static int fd_request_irq(void)
90 return request_irq(FLOPPY_IRQ
, floppy_hardint
,
91 IRQF_DISABLED
, "floppy", floppy_hardint
);
92 else if(MACH_IS_SUN3X
)
93 return sun3xflop_request_irq();
97 static void fd_free_irq(void)
100 free_irq(FLOPPY_IRQ
, floppy_hardint
);
103 #define fd_request_dma() vdma_request_dma(FLOPPY_DMA,"floppy")
104 #define fd_get_dma_residue() vdma_get_dma_residue(FLOPPY_DMA)
105 #define fd_dma_mem_alloc(size) vdma_mem_alloc(size)
106 #define fd_dma_setup(addr, size, mode, io) vdma_dma_setup(addr, size, mode, io)
108 #define fd_enable_irq() /* nothing... */
109 #define fd_disable_irq() /* nothing... */
111 #define fd_free_dma() /* nothing */
113 /* No 64k boundary crossing problems on Q40 - no DMA at all */
114 #define CROSS_64KB(a,s) (0)
116 #define DMA_MODE_READ 0x44 /* i386 look-alike */
117 #define DMA_MODE_WRITE 0x48
120 static int m68k_floppy_init(void)
123 can_use_virtual_dma
= 1;
128 else if(MACH_IS_SUN3X
)
129 return sun3xflop_init();
135 static int vdma_request_dma(unsigned int dmanr
, const char * device_id
)
141 static int vdma_get_dma_residue(unsigned int dummy
)
143 return virtual_dma_count
+ virtual_dma_residue
;
147 static unsigned long vdma_mem_alloc(unsigned long size
)
149 return (unsigned long) vmalloc(size
);
153 static void _fd_dma_mem_free(unsigned long addr
, unsigned long size
)
157 #define fd_dma_mem_free(addr,size) _fd_dma_mem_free(addr, size)
160 /* choose_dma_mode ???*/
162 static int vdma_dma_setup(char *addr
, unsigned long size
, int mode
, int io
)
165 virtual_dma_port
= (MACH_IS_Q40
? io
: 0);
166 virtual_dma_mode
= (mode
== DMA_MODE_WRITE
);
167 virtual_dma_addr
= addr
;
168 virtual_dma_count
= size
;
169 virtual_dma_residue
= 0;
175 static void fd_disable_dma(void)
178 virtual_dma_residue
+= virtual_dma_count
;
184 /* this is the only truly Q40 specific function */
186 asmlinkage irqreturn_t
floppy_hardint(int irq
, void *dev_id
)
188 register unsigned char st
;
190 #undef TRACE_FLPY_INT
191 #define NO_FLOPPY_ASSEMBLER
193 #ifdef TRACE_FLPY_INT
196 static int dma_wait
=0;
199 floppy_interrupt(irq
, dev_id
);
203 #ifdef TRACE_FLPY_INT
205 bytes
= virtual_dma_count
;
212 /* serve 1st byte fast: */
215 for(lcount
=virtual_dma_count
, lptr
=virtual_dma_addr
;
216 lcount
; lcount
--, lptr
++) {
217 st
=inb(virtual_dma_port
+4) & 0xa0 ;
221 outb_p(*lptr
, virtual_dma_port
+5);
223 *lptr
= inb_p(virtual_dma_port
+5);
226 virtual_dma_count
= lcount
;
227 virtual_dma_addr
= lptr
;
228 st
= inb(virtual_dma_port
+4);
231 #ifdef TRACE_FLPY_INT
237 virtual_dma_residue
+= virtual_dma_count
;
239 #ifdef TRACE_FLPY_INT
240 printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
241 virtual_dma_count
, virtual_dma_residue
, calls
, bytes
,
247 floppy_interrupt(irq
, dev_id
);
250 #ifdef TRACE_FLPY_INT
251 if(!virtual_dma_count
)
257 #define EXTRA_FLOPPY_PARAMS