blob: e9555b246c8d0ea909cfa5c9811b844688f42ca2 [file] [log] [blame]
David S. Millerd979f172007-10-27 00:13:04 -07001/* parport.h: sparc64 specific parport initialization and dma.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be)
4 */
5
6#ifndef _ASM_SPARC64_PARPORT_H
7#define _ASM_SPARC64_PARPORT_H 1
8
9#include <asm/ebus.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <asm/ns87303.h>
David S. Miller0fe85d52007-07-18 23:15:04 -070011#include <asm/of_device.h>
12#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#define PARPORT_PC_MAX_PORTS PARPORT_MAX
15
Al Viro7fbacd52005-05-04 05:39:32 +010016/*
17 * While sparc64 doesn't have an ISA DMA API, we provide something that looks
18 * close enough to make parport_pc happy
19 */
20#define HAS_DMA
21
David S. Miller2ef55072007-03-08 14:48:36 -080022static DEFINE_SPINLOCK(dma_spin_lock);
23
24#define claim_dma_lock() \
25({ unsigned long flags; \
26 spin_lock_irqsave(&dma_spin_lock, flags); \
27 flags; \
28})
29
30#define release_dma_lock(__flags) \
31 spin_unlock_irqrestore(&dma_spin_lock, __flags);
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033static struct sparc_ebus_info {
34 struct ebus_dma_info info;
35 unsigned int addr;
36 unsigned int count;
David S. Miller74bd7d02007-02-28 13:09:34 -080037 int lock;
David S. Miller0fe85d52007-07-18 23:15:04 -070038
39 struct parport *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040} sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
41
David S. Miller0fe85d52007-07-18 23:15:04 -070042static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS);
43
David S. Millerd979f172007-10-27 00:13:04 -070044static inline int request_dma(unsigned int dmanr, const char *device_id)
David S. Miller74bd7d02007-02-28 13:09:34 -080045{
46 if (dmanr >= PARPORT_PC_MAX_PORTS)
47 return -EINVAL;
48 if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0)
49 return -EBUSY;
50 return 0;
51}
52
David S. Millerd979f172007-10-27 00:13:04 -070053static inline void free_dma(unsigned int dmanr)
David S. Miller74bd7d02007-02-28 13:09:34 -080054{
55 if (dmanr >= PARPORT_PC_MAX_PORTS) {
56 printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
57 return;
58 }
59 if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
60 printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
61 return;
62 }
63}
64
David S. Millerd979f172007-10-27 00:13:04 -070065static inline void enable_dma(unsigned int dmanr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Eddie C. Doste3e01d62005-07-06 15:41:54 -070067 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
70 sparc_ebus_dmas[dmanr].addr,
71 sparc_ebus_dmas[dmanr].count))
72 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
David S. Millerd979f172007-10-27 00:13:04 -070075static inline void disable_dma(unsigned int dmanr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
78}
79
David S. Millerd979f172007-10-27 00:13:04 -070080static inline void clear_dma_ff(unsigned int dmanr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
82 /* nothing */
83}
84
David S. Millerd979f172007-10-27 00:13:04 -070085static inline void set_dma_mode(unsigned int dmanr, char mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
87 ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
88}
89
David S. Millerd979f172007-10-27 00:13:04 -070090static inline void set_dma_addr(unsigned int dmanr, unsigned int addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 sparc_ebus_dmas[dmanr].addr = addr;
93}
94
David S. Millerd979f172007-10-27 00:13:04 -070095static inline void set_dma_count(unsigned int dmanr, unsigned int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
97 sparc_ebus_dmas[dmanr].count = count;
98}
99
David S. Millerd979f172007-10-27 00:13:04 -0700100static inline unsigned int get_dma_residue(unsigned int dmanr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
103}
104
David S. Miller0fe85d52007-07-18 23:15:04 -0700105static int __devinit ecpp_probe(struct of_device *op, const struct of_device_id *match)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
David S. Miller0fe85d52007-07-18 23:15:04 -0700107 unsigned long base = op->resource[0].start;
108 unsigned long config = op->resource[1].start;
109 unsigned long d_base = op->resource[2].start;
110 unsigned long d_len;
111 struct device_node *parent;
112 struct parport *p;
113 int slot, err;
David S. Miller690c8fd2006-06-22 19:12:03 -0700114
David S. Miller0fe85d52007-07-18 23:15:04 -0700115 parent = op->node->parent;
116 if (!strcmp(parent->name, "dma")) {
117 p = parport_pc_probe_port(base, base + 0x400,
118 op->irqs[0], PARPORT_DMA_NOFIFO,
David S. Millerad7ad572007-07-27 22:39:14 -0700119 op->dev.parent->parent);
David S. Miller0fe85d52007-07-18 23:15:04 -0700120 if (!p)
121 return -ENOMEM;
122 dev_set_drvdata(&op->dev, p);
123 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
David S. Miller0fe85d52007-07-18 23:15:04 -0700125
126 for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) {
127 if (!test_and_set_bit(slot, dma_slot_map))
128 break;
129 }
130 err = -ENODEV;
131 if (slot >= PARPORT_PC_MAX_PORTS)
132 goto out_err;
133
134 spin_lock_init(&sparc_ebus_dmas[slot].info.lock);
135
136 d_len = (op->resource[2].end - d_base) + 1UL;
137 sparc_ebus_dmas[slot].info.regs =
138 of_ioremap(&op->resource[2], 0, d_len, "ECPP DMA");
139
140 if (!sparc_ebus_dmas[slot].info.regs)
141 goto out_clear_map;
142
143 sparc_ebus_dmas[slot].info.flags = 0;
144 sparc_ebus_dmas[slot].info.callback = NULL;
145 sparc_ebus_dmas[slot].info.client_cookie = NULL;
146 sparc_ebus_dmas[slot].info.irq = 0xdeadbeef;
147 strcpy(sparc_ebus_dmas[slot].info.name, "parport");
148 if (ebus_dma_register(&sparc_ebus_dmas[slot].info))
149 goto out_unmap_regs;
150
151 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1);
152
153 /* Configure IRQ to Push Pull, Level Low */
154 /* Enable ECP, set bit 2 of the CTR first */
155 outb(0x04, base + 0x02);
156 ns87303_modify(config, PCR,
157 PCR_EPP_ENABLE |
158 PCR_IRQ_ODRAIN,
159 PCR_ECP_ENABLE |
160 PCR_ECP_CLK_ENA |
161 PCR_IRQ_POLAR);
162
163 /* CTR bit 5 controls direction of port */
164 ns87303_modify(config, PTR,
165 0, PTR_LPT_REG_DIR);
166
167 p = parport_pc_probe_port(base, base + 0x400,
168 op->irqs[0],
169 slot,
170 op->dev.parent);
171 err = -ENOMEM;
172 if (!p)
173 goto out_disable_irq;
174
175 dev_set_drvdata(&op->dev, p);
176
177 return 0;
178
179out_disable_irq:
180 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
181 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
182
183out_unmap_regs:
184 of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len);
185
186out_clear_map:
187 clear_bit(slot, dma_slot_map);
188
189out_err:
190 return err;
191}
192
193static int __devexit ecpp_remove(struct of_device *op)
194{
195 struct parport *p = dev_get_drvdata(&op->dev);
196 int slot = p->dma;
197
198 parport_pc_unregister_port(p);
199
200 if (slot != PARPORT_DMA_NOFIFO) {
201 unsigned long d_base = op->resource[2].start;
202 unsigned long d_len;
203
204 d_len = (op->resource[2].end - d_base) + 1UL;
205
206 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
207 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
208 of_iounmap(&op->resource[2],
209 sparc_ebus_dmas[slot].info.regs,
210 d_len);
211 clear_bit(slot, dma_slot_map);
212 }
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 return 0;
215}
216
David S. Miller0fe85d52007-07-18 23:15:04 -0700217static struct of_device_id ecpp_match[] = {
218 {
219 .name = "ecpp",
220 },
221 {
222 .name = "parallel",
223 .compatible = "ecpp",
224 },
225 {
226 .name = "parallel",
227 .compatible = "ns87317-ecpp",
228 },
229 {},
230};
231
232static struct of_platform_driver ecpp_driver = {
233 .name = "ecpp",
234 .match_table = ecpp_match,
235 .probe = ecpp_probe,
236 .remove = __devexit_p(ecpp_remove),
237};
238
239static int parport_pc_find_nonpci_ports(int autoirq, int autodma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240{
David S. Miller0fe85d52007-07-18 23:15:04 -0700241 of_register_driver(&ecpp_driver, &of_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
David S. Miller0fe85d52007-07-18 23:15:04 -0700243 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
246#endif /* !(_ASM_SPARC64_PARPORT_H */