setup enviroment for compilation
[linux-2.4.21-pre4.git] / include / asm-m68k / floppy.h
1 /*
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@oh.verio.com)
13  *
14  */
15
16 #include <asm/io.h>
17
18 #include <linux/vmalloc.h>
19
20 asmlinkage void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs);
21
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
46 static int virtual_dma_count=0;
47 static int virtual_dma_residue=0;
48 static char *virtual_dma_addr=0;
49 static int virtual_dma_mode=0;
50 static int doing_pdma=0;
51
52 #include <asm/sun3xflop.h>
53
54 extern spinlock_t  dma_spin_lock;
55
56 static __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
63 static __inline__ void release_dma_lock(unsigned long flags)
64 {
65         spin_unlock_irqrestore(&dma_spin_lock, flags);
66 }
67
68
69 static __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 }
76
77 static __inline__ void fd_outb(unsigned char value, int port)
78 {
79         if(MACH_IS_Q40)
80                 outb_p(value, port);
81         else if(MACH_IS_SUN3X)
82                 sun3x_82072_fd_outb(value, port);
83 }
84
85
86 static int fd_request_irq(void)
87 {
88         if(MACH_IS_Q40)
89                 return request_irq(FLOPPY_IRQ, floppy_hardint,SA_INTERRUPT,
90                                                    "floppy", floppy_hardint);
91         else if(MACH_IS_SUN3X) 
92                 return sun3xflop_request_irq();
93         
94 }
95
96 static void fd_free_irq(void)
97 {
98         if(MACH_IS_Q40)
99                 free_irq(FLOPPY_IRQ, floppy_hardint);
100 }
101
102 #define fd_request_dma()        vdma_request_dma(FLOPPY_DMA,"floppy")
103 #define fd_get_dma_residue()    vdma_get_dma_residue(FLOPPY_DMA)
104 #define fd_dma_mem_alloc(size)  vdma_mem_alloc(size)
105 #define fd_dma_setup(addr, size, mode, io) vdma_dma_setup(addr, size, mode, io)
106
107 #define fd_enable_irq()           /* nothing... */
108 #define fd_disable_irq()          /* nothing... */
109
110 #define fd_free_dma()             /* nothing */
111
112 /* No 64k boundary crossing problems on Q40 - no DMA at all */
113 #define CROSS_64KB(a,s) (0)
114
115 #define DMA_MODE_READ  0x44    /* i386 look-alike */
116 #define DMA_MODE_WRITE 0x48
117
118
119 static int m68k_floppy_init(void)
120 {
121   use_virtual_dma =1;
122   can_use_virtual_dma = 1;
123  
124   
125   if (MACH_IS_Q40)  
126           return 0x3f0;
127   else if(MACH_IS_SUN3X)
128           return sun3xflop_init();
129   else
130     return -1;
131 }
132
133
134 static int vdma_request_dma(unsigned int dmanr, const char * device_id)
135 {
136         return 0;
137 }
138
139
140 static int vdma_get_dma_residue(unsigned int dummy)
141 {
142         return virtual_dma_count + virtual_dma_residue;
143 }
144
145
146 static unsigned long vdma_mem_alloc(unsigned long size)
147 {
148         return (unsigned long) vmalloc(size);
149
150 }
151
152 static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
153 {
154         vfree((void *)addr);
155 }
156 #define fd_dma_mem_free(addr,size) _fd_dma_mem_free(addr, size)
157
158
159 /* choose_dma_mode ???*/
160
161 static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
162 {
163         doing_pdma = 1;
164         virtual_dma_port = (MACH_IS_Q40 ? io : 0);
165         virtual_dma_mode = (mode  == DMA_MODE_WRITE);
166         virtual_dma_addr = addr;
167         virtual_dma_count = size;
168         virtual_dma_residue = 0;
169         return 0;
170 }
171
172
173
174 static void fd_disable_dma(void)
175 {
176         doing_pdma = 0;
177         virtual_dma_residue += virtual_dma_count;
178         virtual_dma_count=0;
179 }
180
181
182
183 /* this is the only truly Q40 specific function */
184
185 asmlinkage void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
186 {
187         register unsigned char st;
188
189 #undef TRACE_FLPY_INT
190 #define NO_FLOPPY_ASSEMBLER
191
192 #ifdef TRACE_FLPY_INT 
193         static int calls=0;
194         static int bytes=0;
195         static int dma_wait=0;
196 #endif
197         if(!doing_pdma) {
198                 floppy_interrupt(irq, dev_id, regs);
199                 return;
200         }
201
202 #ifdef TRACE_FLPY_INT
203         if(!calls)
204                 bytes = virtual_dma_count;
205 #endif
206
207         {
208                 register int lcount;
209                 register char *lptr;
210
211                 /* serve 1st byte fast: */
212
213                 st=1;
214                 for(lcount=virtual_dma_count, lptr=virtual_dma_addr; 
215                     lcount; lcount--, lptr++) {
216                         st=inb(virtual_dma_port+4) & 0xa0 ;
217                         if(st != 0xa0) 
218                                 break;
219                         if(virtual_dma_mode)
220                                 outb_p(*lptr, virtual_dma_port+5);
221                         else
222                                 *lptr = inb_p(virtual_dma_port+5);
223                 }
224
225                 virtual_dma_count = lcount;
226                 virtual_dma_addr = lptr;
227                 st = inb(virtual_dma_port+4);
228         }
229
230 #ifdef TRACE_FLPY_INT
231         calls++;
232 #endif
233         if(st == 0x20)
234                 return;
235         if(!(st & 0x20)) {
236                 virtual_dma_residue += virtual_dma_count;
237                 virtual_dma_count=0;
238 #ifdef TRACE_FLPY_INT
239                 printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n", 
240                        virtual_dma_count, virtual_dma_residue, calls, bytes,
241                        dma_wait);
242                 calls = 0;
243                 dma_wait=0;
244 #endif
245                 doing_pdma = 0;
246                 floppy_interrupt(irq, dev_id, regs);
247                 return;
248         }
249 #ifdef TRACE_FLPY_INT
250         if(!virtual_dma_count)
251                 dma_wait++;
252 #endif
253 }
254
255 #define EXTRA_FLOPPY_PARAMS