File Index
Files and directories
Sign in
FILE

floppy.h

File preview with syntax highlighting.

linux-6.19.14/arch/m68k/include/asm/floppy.h C
  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@sammy.net)
 13 *
 14 */
 15
 16#include <asm/io.h>
 17
 18#include <linux/vmalloc.h>
 19
 20asmlinkage irqreturn_t floppy_hardint(int irq, void *dev_id);
 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/* basically PC init + set use_virtual_dma */
 35#define  FDC1 m68k_floppy_init()
 36
 37#define N_FDC 1
 38#define N_DRIVE 8
 39
 40
 41/* vdma globals adapted from asm-i386/floppy.h */
 42
 43static int virtual_dma_count=0;
 44static int virtual_dma_residue=0;
 45static char *virtual_dma_addr=NULL;
 46static int virtual_dma_mode=0;
 47static int doing_pdma=0;
 48
 49#include <asm/sun3xflop.h>
 50
 51extern spinlock_t  dma_spin_lock;
 52
 53static __inline__ unsigned long claim_dma_lock(void)
 54{
 55	unsigned long flags;
 56	spin_lock_irqsave(&dma_spin_lock, flags);
 57	return flags;
 58}
 59
 60static __inline__ void release_dma_lock(unsigned long flags)
 61{
 62	spin_unlock_irqrestore(&dma_spin_lock, flags);
 63}
 64
 65
 66static __inline__ unsigned char fd_inb(int base, int reg)
 67{
 68	if(MACH_IS_Q40)
 69		return inb_p(base + reg);
 70	else if(MACH_IS_SUN3X)
 71		return sun3x_82072_fd_inb(base + reg);
 72	return 0;
 73}
 74
 75static __inline__ void fd_outb(unsigned char value, int base, int reg)
 76{
 77	if(MACH_IS_Q40)
 78		outb_p(value, base + reg);
 79	else if(MACH_IS_SUN3X)
 80		sun3x_82072_fd_outb(value, base + reg);
 81}
 82
 83
 84static int fd_request_irq(void)
 85{
 86	if(MACH_IS_Q40)
 87		return request_irq(FLOPPY_IRQ, floppy_hardint,
 88				   0, "floppy", floppy_hardint);
 89	else if(MACH_IS_SUN3X)
 90		return sun3xflop_request_irq();
 91	return -ENXIO;
 92}
 93
 94static void fd_free_irq(void)
 95{
 96	if(MACH_IS_Q40)
 97		free_irq(FLOPPY_IRQ, floppy_hardint);
 98}
 99
100#define fd_request_dma()        vdma_request_dma(FLOPPY_DMA,"floppy")
101#define fd_get_dma_residue()    vdma_get_dma_residue(FLOPPY_DMA)
102#define fd_dma_mem_alloc(size)	vdma_mem_alloc(size)
103#define fd_dma_setup(addr, size, mode, io) vdma_dma_setup(addr, size, mode, io)
104
105#define fd_enable_irq()           /* nothing... */
106#define fd_disable_irq()          /* nothing... */
107
108#define fd_free_dma()             /* nothing */
109
110#define DMA_MODE_READ  0x44    /* i386 look-alike */
111#define DMA_MODE_WRITE 0x48
112
113static int m68k_floppy_init(void)
114{
115  use_virtual_dma =1;
116  can_use_virtual_dma = 1;
117
118
119  if (MACH_IS_Q40)
120	  return 0x3f0;
121  else if(MACH_IS_SUN3X)
122	  return sun3xflop_init();
123  else
124    return -1;
125}
126
127
128static int vdma_request_dma(unsigned int dmanr, const char * device_id)
129{
130	return 0;
131}
132
133
134static int vdma_get_dma_residue(unsigned int dummy)
135{
136	return virtual_dma_count + virtual_dma_residue;
137}
138
139
140static unsigned long vdma_mem_alloc(unsigned long size)
141{
142	return (unsigned long) vmalloc(size);
143
144}
145
146static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
147{
148        vfree((void *)addr);
149}
150#define fd_dma_mem_free(addr,size) _fd_dma_mem_free(addr, size)
151
152
153/* choose_dma_mode ???*/
154
155static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
156{
157	doing_pdma = 1;
158	virtual_dma_port = (MACH_IS_Q40 ? io : 0);
159	virtual_dma_mode = (mode  == DMA_MODE_WRITE);
160	virtual_dma_addr = addr;
161	virtual_dma_count = size;
162	virtual_dma_residue = 0;
163	return 0;
164}
165
166
167
168static void fd_disable_dma(void)
169{
170	doing_pdma = 0;
171	virtual_dma_residue += virtual_dma_count;
172	virtual_dma_count=0;
173}
174
175
176
177/* this is the only truly Q40 specific function */
178
179asmlinkage irqreturn_t floppy_hardint(int irq, void *dev_id)
180{
181	register unsigned char st;
182
183#undef TRACE_FLPY_INT
184#define NO_FLOPPY_ASSEMBLER
185
186#ifdef TRACE_FLPY_INT
187	static int calls=0;
188	static int bytes=0;
189	static int dma_wait=0;
190#endif
191	if(!doing_pdma) {
192		floppy_interrupt(irq, dev_id);
193		return IRQ_HANDLED;
194	}
195
196#ifdef TRACE_FLPY_INT
197	if(!calls)
198		bytes = virtual_dma_count;
199#endif
200
201	{
202		register int lcount;
203		register char *lptr;
204
205		/* serve 1st byte fast: */
206
207		st=1;
208		for(lcount=virtual_dma_count, lptr=virtual_dma_addr;
209		    lcount; lcount--, lptr++) {
210			st = inb(virtual_dma_port + FD_STATUS);
211			st &= STATUS_DMA | STATUS_READY;
212			if (st != (STATUS_DMA | STATUS_READY))
213				break;
214			if(virtual_dma_mode)
215				outb_p(*lptr, virtual_dma_port + FD_DATA);
216			else
217				*lptr = inb_p(virtual_dma_port + FD_DATA);
218		}
219
220		virtual_dma_count = lcount;
221		virtual_dma_addr = lptr;
222		st = inb(virtual_dma_port + FD_STATUS);
223	}
224
225#ifdef TRACE_FLPY_INT
226	calls++;
227#endif
228	if (st == STATUS_DMA)
229		return IRQ_HANDLED;
230	if (!(st & STATUS_DMA)) {
231		virtual_dma_residue += virtual_dma_count;
232		virtual_dma_count=0;
233#ifdef TRACE_FLPY_INT
234		pr_info("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
235			virtual_dma_count, virtual_dma_residue, calls, bytes,
236			dma_wait);
237		calls = 0;
238		dma_wait=0;
239#endif
240		doing_pdma = 0;
241		floppy_interrupt(irq, dev_id);
242		return IRQ_HANDLED;
243	}
244#ifdef TRACE_FLPY_INT
245	if(!virtual_dma_count)
246		dma_wait++;
247#endif
248	return IRQ_HANDLED;
249}
250
251#define EXTRA_FLOPPY_PARAMS
~/ Read-only file preview.