blob: 45dc908932a3993a8295dd0a27575b07415b640a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Implementation independent bits of the Floppy driver.
3 *
4 * much of this file is derived from what was originally the Q40 floppy driver.
5 *
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
8 * for more details.
9 *
10 * Copyright (C) 1999, 2000, 2001
11 *
12 * Sun3x support added 2/4/2000 Sam Creasey (sammy@sammy.net)
13 *
14 */
15
16#include <asm/io.h>
17
18#include <linux/vmalloc.h>
19
Al Viro2850bc22006-10-07 14:16:45 +010020asmlinkage irqreturn_t floppy_hardint(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22/* constants... */
23
24#undef MAX_DMA_ADDRESS
25#define MAX_DMA_ADDRESS 0x00 /* nothing like that */
26
27
28/*
29 * Again, the CMOS information doesn't work on m68k..
30 */
31#define FLOPPY0_TYPE (MACH_IS_Q40 ? 6 : 4)
32#define FLOPPY1_TYPE 0
33
34#define FLOPPY_MOTOR_MASK 0xf0
35
36
37/* basically PC init + set use_virtual_dma */
38#define FDC1 m68k_floppy_init()
39
40#define N_FDC 1
41#define N_DRIVE 8
42
43
44/* vdma globals adapted from asm-i386/floppy.h */
45
46static int virtual_dma_count=0;
47static int virtual_dma_residue=0;
Al Viroa5d361f2006-01-12 01:06:34 -080048static char *virtual_dma_addr=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static int virtual_dma_mode=0;
50static int doing_pdma=0;
51
52#include <asm/sun3xflop.h>
53
54extern spinlock_t dma_spin_lock;
55
56static __inline__ unsigned long claim_dma_lock(void)
57{
58 unsigned long flags;
59 spin_lock_irqsave(&dma_spin_lock, flags);
60 return flags;
61}
62
63static __inline__ void release_dma_lock(unsigned long flags)
64{
65 spin_unlock_irqrestore(&dma_spin_lock, flags);
66}
67
68
69static __inline__ unsigned char fd_inb(int port)
70{
71 if(MACH_IS_Q40)
72 return inb_p(port);
73 else if(MACH_IS_SUN3X)
74 return sun3x_82072_fd_inb(port);
75 return 0;
76}
77
78static __inline__ void fd_outb(unsigned char value, int port)
79{
80 if(MACH_IS_Q40)
81 outb_p(value, port);
82 else if(MACH_IS_SUN3X)
83 sun3x_82072_fd_outb(value, port);
84}
85
86
87static int fd_request_irq(void)
88{
89 if(MACH_IS_Q40)
Thomas Gleixnerb0b9fdc2006-07-01 19:29:19 -070090 return request_irq(FLOPPY_IRQ, floppy_hardint,
91 IRQF_DISABLED, "floppy", floppy_hardint);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 else if(MACH_IS_SUN3X)
93 return sun3xflop_request_irq();
94 return -ENXIO;
95}
96
97static void fd_free_irq(void)
98{
99 if(MACH_IS_Q40)
100 free_irq(FLOPPY_IRQ, floppy_hardint);
101}
102
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)
107
108#define fd_enable_irq() /* nothing... */
109#define fd_disable_irq() /* nothing... */
110
111#define fd_free_dma() /* nothing */
112
113/* No 64k boundary crossing problems on Q40 - no DMA at all */
114#define CROSS_64KB(a,s) (0)
115
116#define DMA_MODE_READ 0x44 /* i386 look-alike */
117#define DMA_MODE_WRITE 0x48
118
119
120static int m68k_floppy_init(void)
121{
122 use_virtual_dma =1;
123 can_use_virtual_dma = 1;
124
125
126 if (MACH_IS_Q40)
127 return 0x3f0;
128 else if(MACH_IS_SUN3X)
129 return sun3xflop_init();
130 else
131 return -1;
132}
133
134
135static int vdma_request_dma(unsigned int dmanr, const char * device_id)
136{
137 return 0;
138}
139
140
141static int vdma_get_dma_residue(unsigned int dummy)
142{
143 return virtual_dma_count + virtual_dma_residue;
144}
145
146
147static unsigned long vdma_mem_alloc(unsigned long size)
148{
149 return (unsigned long) vmalloc(size);
150
151}
152
153static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
154{
155 vfree((void *)addr);
156}
157#define fd_dma_mem_free(addr,size) _fd_dma_mem_free(addr, size)
158
159
160/* choose_dma_mode ???*/
161
162static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
163{
164 doing_pdma = 1;
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;
170 return 0;
171}
172
173
174
175static void fd_disable_dma(void)
176{
177 doing_pdma = 0;
178 virtual_dma_residue += virtual_dma_count;
179 virtual_dma_count=0;
180}
181
182
183
184/* this is the only truly Q40 specific function */
185
Al Viro2850bc22006-10-07 14:16:45 +0100186asmlinkage irqreturn_t floppy_hardint(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 register unsigned char st;
189
190#undef TRACE_FLPY_INT
191#define NO_FLOPPY_ASSEMBLER
192
193#ifdef TRACE_FLPY_INT
194 static int calls=0;
195 static int bytes=0;
196 static int dma_wait=0;
197#endif
198 if(!doing_pdma) {
Al Viro2850bc22006-10-07 14:16:45 +0100199 floppy_interrupt(irq, dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 return IRQ_HANDLED;
201 }
202
203#ifdef TRACE_FLPY_INT
204 if(!calls)
205 bytes = virtual_dma_count;
206#endif
207
208 {
209 register int lcount;
210 register char *lptr;
211
212 /* serve 1st byte fast: */
213
214 st=1;
215 for(lcount=virtual_dma_count, lptr=virtual_dma_addr;
216 lcount; lcount--, lptr++) {
217 st=inb(virtual_dma_port+4) & 0xa0 ;
218 if(st != 0xa0)
219 break;
220 if(virtual_dma_mode)
221 outb_p(*lptr, virtual_dma_port+5);
222 else
223 *lptr = inb_p(virtual_dma_port+5);
224 }
225
226 virtual_dma_count = lcount;
227 virtual_dma_addr = lptr;
228 st = inb(virtual_dma_port+4);
229 }
230
231#ifdef TRACE_FLPY_INT
232 calls++;
233#endif
234 if(st == 0x20)
235 return IRQ_HANDLED;
236 if(!(st & 0x20)) {
237 virtual_dma_residue += virtual_dma_count;
238 virtual_dma_count=0;
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,
242 dma_wait);
243 calls = 0;
244 dma_wait=0;
245#endif
246 doing_pdma = 0;
Al Viro2850bc22006-10-07 14:16:45 +0100247 floppy_interrupt(irq, dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 return IRQ_HANDLED;
249 }
250#ifdef TRACE_FLPY_INT
251 if(!virtual_dma_count)
252 dma_wait++;
253#endif
254 return IRQ_HANDLED;
255}
256
257#define EXTRA_FLOPPY_PARAMS