rc80211-pid: add MAINTAINERS entry
[wrt350n-kernel.git] / include / asm-sparc64 / parport.h
blobe9555b246c8d0ea909cfa5c9811b844688f42ca2
1 /* parport.h: sparc64 specific parport initialization and dma.
3 * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be)
4 */
6 #ifndef _ASM_SPARC64_PARPORT_H
7 #define _ASM_SPARC64_PARPORT_H 1
9 #include <asm/ebus.h>
10 #include <asm/ns87303.h>
11 #include <asm/of_device.h>
12 #include <asm/prom.h>
14 #define PARPORT_PC_MAX_PORTS PARPORT_MAX
17 * While sparc64 doesn't have an ISA DMA API, we provide something that looks
18 * close enough to make parport_pc happy
20 #define HAS_DMA
22 static DEFINE_SPINLOCK(dma_spin_lock);
24 #define claim_dma_lock() \
25 ({ unsigned long flags; \
26 spin_lock_irqsave(&dma_spin_lock, flags); \
27 flags; \
30 #define release_dma_lock(__flags) \
31 spin_unlock_irqrestore(&dma_spin_lock, __flags);
33 static struct sparc_ebus_info {
34 struct ebus_dma_info info;
35 unsigned int addr;
36 unsigned int count;
37 int lock;
39 struct parport *port;
40 } sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
42 static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS);
44 static inline int request_dma(unsigned int dmanr, const char *device_id)
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;
53 static inline void free_dma(unsigned int dmanr)
55 if (dmanr >= PARPORT_PC_MAX_PORTS) {
56 printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
57 return;
59 if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
60 printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
61 return;
65 static inline void enable_dma(unsigned int dmanr)
67 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
69 if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
70 sparc_ebus_dmas[dmanr].addr,
71 sparc_ebus_dmas[dmanr].count))
72 BUG();
75 static inline void disable_dma(unsigned int dmanr)
77 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
80 static inline void clear_dma_ff(unsigned int dmanr)
82 /* nothing */
85 static inline void set_dma_mode(unsigned int dmanr, char mode)
87 ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
90 static inline void set_dma_addr(unsigned int dmanr, unsigned int addr)
92 sparc_ebus_dmas[dmanr].addr = addr;
95 static inline void set_dma_count(unsigned int dmanr, unsigned int count)
97 sparc_ebus_dmas[dmanr].count = count;
100 static inline unsigned int get_dma_residue(unsigned int dmanr)
102 return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
105 static int __devinit ecpp_probe(struct of_device *op, const struct of_device_id *match)
107 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;
115 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,
119 op->dev.parent->parent);
120 if (!p)
121 return -ENOMEM;
122 dev_set_drvdata(&op->dev, p);
123 return 0;
126 for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) {
127 if (!test_and_set_bit(slot, dma_slot_map))
128 break;
130 err = -ENODEV;
131 if (slot >= PARPORT_PC_MAX_PORTS)
132 goto out_err;
134 spin_lock_init(&sparc_ebus_dmas[slot].info.lock);
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");
140 if (!sparc_ebus_dmas[slot].info.regs)
141 goto out_clear_map;
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;
151 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1);
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);
163 /* CTR bit 5 controls direction of port */
164 ns87303_modify(config, PTR,
165 0, PTR_LPT_REG_DIR);
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;
175 dev_set_drvdata(&op->dev, p);
177 return 0;
179 out_disable_irq:
180 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
181 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
183 out_unmap_regs:
184 of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len);
186 out_clear_map:
187 clear_bit(slot, dma_slot_map);
189 out_err:
190 return err;
193 static int __devexit ecpp_remove(struct of_device *op)
195 struct parport *p = dev_get_drvdata(&op->dev);
196 int slot = p->dma;
198 parport_pc_unregister_port(p);
200 if (slot != PARPORT_DMA_NOFIFO) {
201 unsigned long d_base = op->resource[2].start;
202 unsigned long d_len;
204 d_len = (op->resource[2].end - d_base) + 1UL;
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);
214 return 0;
217 static struct of_device_id ecpp_match[] = {
219 .name = "ecpp",
222 .name = "parallel",
223 .compatible = "ecpp",
226 .name = "parallel",
227 .compatible = "ns87317-ecpp",
232 static struct of_platform_driver ecpp_driver = {
233 .name = "ecpp",
234 .match_table = ecpp_match,
235 .probe = ecpp_probe,
236 .remove = __devexit_p(ecpp_remove),
239 static int parport_pc_find_nonpci_ports(int autoirq, int autodma)
241 of_register_driver(&ecpp_driver, &of_bus_type);
243 return 0;
246 #endif /* !(_ASM_SPARC64_PARPORT_H */