blob: 167c44b588487005e07f2bb5ae9e2db5290277ad [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)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#define fd_free_irq() free_irq(FLOPPY_IRQ, NULL);
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/pci.h>
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +100031#include <asm/ppc-pci.h> /* for isa_bridge_pcidev */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +030033#define fd_dma_setup(addr,size,mode,io) fd_ops->_dma_setup(addr,size,mode,io)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +030035static int fd_request_dma(void);
36
37struct fd_dma_ops {
38 void (*_disable_dma)(unsigned int dmanr);
39 void (*_free_dma)(unsigned int dmanr);
40 int (*_get_dma_residue)(unsigned int dummy);
41 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
42};
43
44static int virtual_dma_count;
45static int virtual_dma_residue;
46static char *virtual_dma_addr;
47static int virtual_dma_mode;
48static int doing_vdma;
49static struct fd_dma_ops *fd_ops;
50
51static irqreturn_t floppy_hardint(int irq, void *dev_id)
52{
53 unsigned char st;
54 int lcount;
55 char *lptr;
56
57 if (!doing_vdma)
58 return floppy_interrupt(irq, dev_id);
59
60
61 st = 1;
62 for (lcount=virtual_dma_count, lptr=virtual_dma_addr;
63 lcount; lcount--, lptr++) {
64 st=inb(virtual_dma_port+4) & 0xa0 ;
65 if (st != 0xa0)
66 break;
67 if (virtual_dma_mode)
68 outb_p(*lptr, virtual_dma_port+5);
69 else
70 *lptr = inb_p(virtual_dma_port+5);
71 }
72 virtual_dma_count = lcount;
73 virtual_dma_addr = lptr;
74 st = inb(virtual_dma_port+4);
75
76 if (st == 0x20)
77 return IRQ_HANDLED;
78 if (!(st & 0x20)) {
79 virtual_dma_residue += virtual_dma_count;
80 virtual_dma_count=0;
81 doing_vdma = 0;
82 floppy_interrupt(irq, dev_id);
83 return IRQ_HANDLED;
84 }
85 return IRQ_HANDLED;
86}
87
88static void vdma_disable_dma(unsigned int dummy)
89{
90 doing_vdma = 0;
91 virtual_dma_residue += virtual_dma_count;
92 virtual_dma_count=0;
93}
94
95static void vdma_nop(unsigned int dummy)
96{
97}
98
99
100static int vdma_get_dma_residue(unsigned int dummy)
101{
102 return virtual_dma_count + virtual_dma_residue;
103}
104
105
106static int fd_request_irq(void)
107{
108 if (can_use_virtual_dma)
109 return request_irq(FLOPPY_IRQ, floppy_hardint,
Yong Zhanga3a9f3b2011-10-21 23:56:27 +0000110 0, "floppy", NULL);
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +0300111 else
112 return request_irq(FLOPPY_IRQ, floppy_interrupt,
Yong Zhanga3a9f3b2011-10-21 23:56:27 +0000113 0, "floppy", NULL);
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +0300114}
115
116static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
117{
118 doing_vdma = 1;
119 virtual_dma_port = io;
120 virtual_dma_mode = (mode == DMA_MODE_WRITE);
121 virtual_dma_addr = addr;
122 virtual_dma_count = size;
123 virtual_dma_residue = 0;
124 return 0;
125}
126
127static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 static unsigned long prev_size;
130 static dma_addr_t bus_addr = 0;
131 static char *prev_addr;
132 static int prev_dir;
133 int dir;
134
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +0300135 doing_vdma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 dir = (mode == DMA_MODE_READ) ? PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE;
137
138 if (bus_addr
139 && (addr != prev_addr || size != prev_size || dir != prev_dir)) {
140 /* different from last time -- unmap prev */
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000141 pci_unmap_single(isa_bridge_pcidev, bus_addr, prev_size, prev_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 bus_addr = 0;
143 }
144
Paul Mackerrasc55377e2005-11-14 17:22:01 +1100145 if (!bus_addr) /* need to map it */
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000146 bus_addr = pci_map_single(isa_bridge_pcidev, addr, size, dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /* remember this one as prev */
149 prev_addr = addr;
150 prev_size = size;
151 prev_dir = dir;
152
153 fd_clear_dma_ff();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 fd_set_dma_mode(mode);
155 set_dma_addr(FLOPPY_DMA, bus_addr);
156 fd_set_dma_count(size);
157 virtual_dma_port = io;
158 fd_enable_dma();
159
160 return 0;
161}
162
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +0300163static struct fd_dma_ops real_dma_ops =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +0300165 ._disable_dma = disable_dma,
166 ._free_dma = free_dma,
167 ._get_dma_residue = get_dma_residue,
168 ._dma_setup = hard_dma_setup
169};
170
171static struct fd_dma_ops virt_dma_ops =
172{
173 ._disable_dma = vdma_disable_dma,
174 ._free_dma = vdma_nop,
175 ._get_dma_residue = vdma_get_dma_residue,
176 ._dma_setup = vdma_dma_setup
177};
178
Al Viro1be9ab02007-03-14 09:20:00 +0000179static int fd_request_dma(void)
Pavel Fedin9ea8b7c2007-01-29 15:13:03 +0300180{
181 if (can_use_virtual_dma & 1) {
182 fd_ops = &virt_dma_ops;
183 return 0;
184 }
185 else {
186 fd_ops = &real_dma_ops;
187 return request_dma(FLOPPY_DMA, "floppy");
188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
190
191static int FDC1 = 0x3f0;
192static int FDC2 = -1;
193
194/*
195 * Again, the CMOS information not available
196 */
197#define FLOPPY0_TYPE 6
198#define FLOPPY1_TYPE 0
199
200#define N_FDC 2 /* Don't change this! */
201#define N_DRIVE 8
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203/*
204 * The PowerPC has no problems with floppy DMA crossing 64k borders.
205 */
206#define CROSS_64KB(a,s) (0)
207
208#define EXTRA_FLOPPY_PARAMS
209
Arnd Bergmann88ced032005-12-16 22:43:46 +0100210#endif /* __KERNEL__ */
Paul Mackerrasc55377e2005-11-14 17:22:01 +1100211#endif /* __ASM_POWERPC_FLOPPY_H */