blob: 7d9b3f430d929594343b7518f78131161aa47795 [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 */
10#ifdef __KERNEL__
11#ifndef __ASM_PPC_FLOPPY_H
12#define __ASM_PPC_FLOPPY_H
13
14#define fd_inb(port) inb_p(port)
15#define fd_outb(value,port) outb_p(value,port)
16
17#define fd_disable_dma() fd_ops->_disable_dma(FLOPPY_DMA)
18#define fd_free_dma() fd_ops->_free_dma(FLOPPY_DMA)
19#define fd_get_dma_residue() fd_ops->_get_dma_residue(FLOPPY_DMA)
20#define fd_dma_setup(addr, size, mode, io) fd_ops->_dma_setup(addr, size, mode, io)
21#define fd_enable_irq() enable_irq(FLOPPY_IRQ)
22#define fd_disable_irq() disable_irq(FLOPPY_IRQ)
23#define fd_free_irq() free_irq(FLOPPY_IRQ, NULL);
24
25static int fd_request_dma(void);
26
27struct fd_dma_ops {
28 void (*_disable_dma)(unsigned int dmanr);
29 void (*_free_dma)(unsigned int dmanr);
30 int (*_get_dma_residue)(unsigned int dummy);
31 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
32};
33
34static int virtual_dma_count;
35static int virtual_dma_residue;
36static char *virtual_dma_addr;
37static int virtual_dma_mode;
38static int doing_vdma;
39static struct fd_dma_ops *fd_ops;
40
Paul Mackerras3211be52006-10-06 21:09:40 +100041static irqreturn_t floppy_hardint(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
43 unsigned char st;
44 int lcount;
45 char *lptr;
46
47 if (!doing_vdma)
Paul Mackerras3211be52006-10-06 21:09:40 +100048 return floppy_interrupt(irq, dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50
51 st = 1;
52 for (lcount=virtual_dma_count, lptr=virtual_dma_addr;
53 lcount; lcount--, lptr++) {
54 st=inb(virtual_dma_port+4) & 0xa0 ;
55 if (st != 0xa0)
56 break;
57 if (virtual_dma_mode)
58 outb_p(*lptr, virtual_dma_port+5);
59 else
60 *lptr = inb_p(virtual_dma_port+5);
61 }
62 virtual_dma_count = lcount;
63 virtual_dma_addr = lptr;
64 st = inb(virtual_dma_port+4);
65
66 if (st == 0x20)
67 return IRQ_HANDLED;
68 if (!(st & 0x20)) {
69 virtual_dma_residue += virtual_dma_count;
70 virtual_dma_count=0;
71 doing_vdma = 0;
Paul Mackerras3211be52006-10-06 21:09:40 +100072 floppy_interrupt(irq, dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 return IRQ_HANDLED;
74 }
75 return IRQ_HANDLED;
76}
77
78static void vdma_disable_dma(unsigned int dummy)
79{
80 doing_vdma = 0;
81 virtual_dma_residue += virtual_dma_count;
82 virtual_dma_count=0;
83}
84
85static void vdma_nop(unsigned int dummy)
86{
87}
88
89
90static int vdma_get_dma_residue(unsigned int dummy)
91{
92 return virtual_dma_count + virtual_dma_residue;
93}
94
95
96static int fd_request_irq(void)
97{
98 if (can_use_virtual_dma)
Thomas Gleixnerbc59d282006-07-01 19:29:22 -070099 return request_irq(FLOPPY_IRQ, floppy_hardint,
100 IRQF_DISABLED, "floppy", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 else
Thomas Gleixnerbc59d282006-07-01 19:29:22 -0700102 return request_irq(FLOPPY_IRQ, floppy_interrupt,
103 IRQF_DISABLED, "floppy", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
106static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
107{
108 doing_vdma = 1;
109 virtual_dma_port = io;
110 virtual_dma_mode = (mode == DMA_MODE_WRITE);
111 virtual_dma_addr = addr;
112 virtual_dma_count = size;
113 virtual_dma_residue = 0;
114 return 0;
115}
116
117static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
118{
119 /* actual, physical DMA */
120 doing_vdma = 0;
121 clear_dma_ff(FLOPPY_DMA);
122 set_dma_mode(FLOPPY_DMA,mode);
123 set_dma_addr(FLOPPY_DMA,(unsigned int)virt_to_bus(addr));
124 set_dma_count(FLOPPY_DMA,size);
125 enable_dma(FLOPPY_DMA);
126 return 0;
127}
128
129static struct fd_dma_ops real_dma_ops =
130{
131 ._disable_dma = disable_dma,
132 ._free_dma = free_dma,
133 ._get_dma_residue = get_dma_residue,
134 ._dma_setup = hard_dma_setup
135};
136
137static struct fd_dma_ops virt_dma_ops =
138{
139 ._disable_dma = vdma_disable_dma,
140 ._free_dma = vdma_nop,
141 ._get_dma_residue = vdma_get_dma_residue,
142 ._dma_setup = vdma_dma_setup
143};
144
145static int fd_request_dma()
146{
147 if (can_use_virtual_dma & 1) {
148 fd_ops = &virt_dma_ops;
149 return 0;
150 }
151 else {
152 fd_ops = &real_dma_ops;
153 return request_dma(FLOPPY_DMA, "floppy");
154 }
155}
156
157static int FDC1 = 0x3f0;
158static int FDC2 = -1;
159
160/*
161 * Again, the CMOS information not available
162 */
163#define FLOPPY0_TYPE 6
164#define FLOPPY1_TYPE 0
165
166#define N_FDC 2 /* Don't change this! */
167#define N_DRIVE 8
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169/*
170 * The PowerPC has no problems with floppy DMA crossing 64k borders.
171 */
172#define CROSS_64KB(a,s) (0)
173
174#endif /* __ASM_PPC_FLOPPY_H */
175
176#define EXTRA_FLOPPY_PARAMS
177
178#endif /* __KERNEL__ */