blob: 34146f0eea63c7af99dd9687478c1d1b329da5b0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Architecture specific parts of the Floppy driver
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1995
9 */
Paul Mackerrasc55377e2005-11-14 17:22:01 +110010#ifndef __ASM_POWERPC_FLOPPY_H
11#define __ASM_POWERPC_FLOPPY_H
Arnd Bergmann88ced032005-12-16 22:43:46 +010012#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/machdep.h>
15
Paul Mackerrasc55377e2005-11-14 17:22:01 +110016#define fd_inb(port) inb_p(port)
17#define fd_outb(value,port) outb_p(value,port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#define fd_enable_dma() enable_dma(FLOPPY_DMA)
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +030020#define fd_disable_dma() fd_ops->_disable_dma(FLOPPY_DMA)
21#define fd_free_dma() fd_ops->_free_dma(FLOPPY_DMA)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#define fd_clear_dma_ff() clear_dma_ff(FLOPPY_DMA)
Paul Mackerrasc55377e2005-11-14 17:22:01 +110023#define fd_set_dma_mode(mode) set_dma_mode(FLOPPY_DMA, mode)
24#define fd_set_dma_count(count) set_dma_count(FLOPPY_DMA, count)
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +030025#define fd_get_dma_residue() fd_ops->_get_dma_residue(FLOPPY_DMA)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#define fd_enable_irq() enable_irq(FLOPPY_IRQ)
27#define fd_disable_irq() disable_irq(FLOPPY_IRQ)
28#define fd_cacheflush(addr,size) /* nothing */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#define fd_free_irq() free_irq(FLOPPY_IRQ, NULL);
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/pci.h>
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +100032#include <asm/ppc-pci.h> /* for isa_bridge_pcidev */
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +030034#define fd_dma_setup(addr,size,mode,io) fd_ops->_dma_setup(addr,size,mode,io)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +030036static int fd_request_dma(void);
37
38struct fd_dma_ops {
39 void (*_disable_dma)(unsigned int dmanr);
40 void (*_free_dma)(unsigned int dmanr);
41 int (*_get_dma_residue)(unsigned int dummy);
42 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
43};
44
45static int virtual_dma_count;
46static int virtual_dma_residue;
47static char *virtual_dma_addr;
48static int virtual_dma_mode;
49static int doing_vdma;
50static struct fd_dma_ops *fd_ops;
51
52static irqreturn_t floppy_hardint(int irq, void *dev_id)
53{
54 unsigned char st;
55 int lcount;
56 char *lptr;
57
58 if (!doing_vdma)
59 return floppy_interrupt(irq, dev_id);
60
61
62 st = 1;
63 for (lcount=virtual_dma_count, lptr=virtual_dma_addr;
64 lcount; lcount--, lptr++) {
65 st=inb(virtual_dma_port+4) & 0xa0 ;
66 if (st != 0xa0)
67 break;
68 if (virtual_dma_mode)
69 outb_p(*lptr, virtual_dma_port+5);
70 else
71 *lptr = inb_p(virtual_dma_port+5);
72 }
73 virtual_dma_count = lcount;
74 virtual_dma_addr = lptr;
75 st = inb(virtual_dma_port+4);
76
77 if (st == 0x20)
78 return IRQ_HANDLED;
79 if (!(st & 0x20)) {
80 virtual_dma_residue += virtual_dma_count;
81 virtual_dma_count=0;
82 doing_vdma = 0;
83 floppy_interrupt(irq, dev_id);
84 return IRQ_HANDLED;
85 }
86 return IRQ_HANDLED;
87}
88
89static void vdma_disable_dma(unsigned int dummy)
90{
91 doing_vdma = 0;
92 virtual_dma_residue += virtual_dma_count;
93 virtual_dma_count=0;
94}
95
96static void vdma_nop(unsigned int dummy)
97{
98}
99
100
101static int vdma_get_dma_residue(unsigned int dummy)
102{
103 return virtual_dma_count + virtual_dma_residue;
104}
105
106
107static int fd_request_irq(void)
108{
109 if (can_use_virtual_dma)
110 return request_irq(FLOPPY_IRQ, floppy_hardint,
111 IRQF_DISABLED, "floppy", NULL);
112 else
113 return request_irq(FLOPPY_IRQ, floppy_interrupt,
114 IRQF_DISABLED, "floppy", NULL);
115}
116
117static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
118{
119 doing_vdma = 1;
120 virtual_dma_port = io;
121 virtual_dma_mode = (mode == DMA_MODE_WRITE);
122 virtual_dma_addr = addr;
123 virtual_dma_count = size;
124 virtual_dma_residue = 0;
125 return 0;
126}
127
128static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 static unsigned long prev_size;
131 static dma_addr_t bus_addr = 0;
132 static char *prev_addr;
133 static int prev_dir;
134 int dir;
135
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +0300136 doing_vdma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 dir = (mode == DMA_MODE_READ) ? PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE;
138
139 if (bus_addr
140 && (addr != prev_addr || size != prev_size || dir != prev_dir)) {
141 /* different from last time -- unmap prev */
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000142 pci_unmap_single(isa_bridge_pcidev, bus_addr, prev_size, prev_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 bus_addr = 0;
144 }
145
Paul Mackerrasc55377e2005-11-14 17:22:01 +1100146 if (!bus_addr) /* need to map it */
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000147 bus_addr = pci_map_single(isa_bridge_pcidev, addr, size, dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 /* remember this one as prev */
150 prev_addr = addr;
151 prev_size = size;
152 prev_dir = dir;
153
154 fd_clear_dma_ff();
155 fd_cacheflush(addr, size);
156 fd_set_dma_mode(mode);
157 set_dma_addr(FLOPPY_DMA, bus_addr);
158 fd_set_dma_count(size);
159 virtual_dma_port = io;
160 fd_enable_dma();
161
162 return 0;
163}
164
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +0300165static struct fd_dma_ops real_dma_ops =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +0300167 ._disable_dma = disable_dma,
168 ._free_dma = free_dma,
169 ._get_dma_residue = get_dma_residue,
170 ._dma_setup = hard_dma_setup
171};
172
173static struct fd_dma_ops virt_dma_ops =
174{
175 ._disable_dma = vdma_disable_dma,
176 ._free_dma = vdma_nop,
177 ._get_dma_residue = vdma_get_dma_residue,
178 ._dma_setup = vdma_dma_setup
179};
180
Al Viro1be9ab02007-03-14 09:20:00 +0000181static int fd_request_dma(void)
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +0300182{
183 if (can_use_virtual_dma & 1) {
184 fd_ops = &virt_dma_ops;
185 return 0;
186 }
187 else {
188 fd_ops = &real_dma_ops;
189 return request_dma(FLOPPY_DMA, "floppy");
190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
192
193static int FDC1 = 0x3f0;
194static int FDC2 = -1;
195
196/*
197 * Again, the CMOS information not available
198 */
199#define FLOPPY0_TYPE 6
200#define FLOPPY1_TYPE 0
201
202#define N_FDC 2 /* Don't change this! */
203#define N_DRIVE 8
204
205#define FLOPPY_MOTOR_MASK 0xf0
206
207/*
208 * The PowerPC has no problems with floppy DMA crossing 64k borders.
209 */
210#define CROSS_64KB(a,s) (0)
211
212#define EXTRA_FLOPPY_PARAMS
213
Arnd Bergmann88ced032005-12-16 22:43:46 +0100214#endif /* __KERNEL__ */
Paul Mackerrasc55377e2005-11-14 17:22:01 +1100215#endif /* __ASM_POWERPC_FLOPPY_H */