1 /* parport.h: sparc64 specific parport initialization and dma.
2 *
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 <linux/of_device.h>
10
11 #include <asm/ebus_dma.h>
12 #include <asm/ns87303.h>
13 #include <asm/prom.h>
14
15 #define PARPORT_PC_MAX_PORTS PARPORT_MAX
16
17 /*
18 * While sparc64 doesn't have an ISA DMA API, we provide something that looks
19 * close enough to make parport_pc happy
20 */
21 #define HAS_DMA
22
23 #ifdef CONFIG_PARPORT_PC_FIFO
24 static DEFINE_SPINLOCK(dma_spin_lock);
25
26 #define claim_dma_lock() \
27 ({ unsigned long flags; \
28 spin_lock_irqsave(&dma_spin_lock, flags); \
29 flags; \
30 })
31
32 #define release_dma_lock(__flags) \
33 spin_unlock_irqrestore(&dma_spin_lock, __flags);
34 #endif
35
36 static struct sparc_ebus_info {
37 struct ebus_dma_info info;
38 unsigned int addr;
39 unsigned int count;
40 int lock;
41
42 struct parport *port;
43 } sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
44
45 static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS);
46
request_dma(unsigned int dmanr,const char * device_id)47 static inline int request_dma(unsigned int dmanr, const char *device_id)
48 {
49 if (dmanr >= PARPORT_PC_MAX_PORTS)
50 return -EINVAL;
51 if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0)
52 return -EBUSY;
53 return 0;
54 }
55
free_dma(unsigned int dmanr)56 static inline void free_dma(unsigned int dmanr)
57 {
58 if (dmanr >= PARPORT_PC_MAX_PORTS) {
59 printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
60 return;
61 }
62 if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
63 printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
64 return;
65 }
66 }
67
enable_dma(unsigned int dmanr)68 static inline void enable_dma(unsigned int dmanr)
69 {
70 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
71
72 if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
73 sparc_ebus_dmas[dmanr].addr,
74 sparc_ebus_dmas[dmanr].count))
75 BUG();
76 }
77
disable_dma(unsigned int dmanr)78 static inline void disable_dma(unsigned int dmanr)
79 {
80 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
81 }
82
clear_dma_ff(unsigned int dmanr)83 static inline void clear_dma_ff(unsigned int dmanr)
84 {
85 /* nothing */
86 }
87
set_dma_mode(unsigned int dmanr,char mode)88 static inline void set_dma_mode(unsigned int dmanr, char mode)
89 {
90 ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
91 }
92
set_dma_addr(unsigned int dmanr,unsigned int addr)93 static inline void set_dma_addr(unsigned int dmanr, unsigned int addr)
94 {
95 sparc_ebus_dmas[dmanr].addr = addr;
96 }
97
set_dma_count(unsigned int dmanr,unsigned int count)98 static inline void set_dma_count(unsigned int dmanr, unsigned int count)
99 {
100 sparc_ebus_dmas[dmanr].count = count;
101 }
102
get_dma_residue(unsigned int dmanr)103 static inline unsigned int get_dma_residue(unsigned int dmanr)
104 {
105 return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
106 }
107
ecpp_probe(struct platform_device * op)108 static int ecpp_probe(struct platform_device *op)
109 {
110 unsigned long base = op->resource[0].start;
111 unsigned long config = op->resource[1].start;
112 unsigned long d_base = op->resource[2].start;
113 unsigned long d_len;
114 struct device_node *parent;
115 struct parport *p;
116 int slot, err;
117
118 parent = op->dev.of_node->parent;
119 if (!strcmp(parent->name, "dma")) {
120 p = parport_pc_probe_port(base, base + 0x400,
121 op->archdata.irqs[0], PARPORT_DMA_NOFIFO,
122 op->dev.parent->parent, 0);
123 if (!p)
124 return -ENOMEM;
125 dev_set_drvdata(&op->dev, p);
126 return 0;
127 }
128
129 for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) {
130 if (!test_and_set_bit(slot, dma_slot_map))
131 break;
132 }
133 err = -ENODEV;
134 if (slot >= PARPORT_PC_MAX_PORTS)
135 goto out_err;
136
137 spin_lock_init(&sparc_ebus_dmas[slot].info.lock);
138
139 d_len = (op->resource[2].end - d_base) + 1UL;
140 sparc_ebus_dmas[slot].info.regs =
141 of_ioremap(&op->resource[2], 0, d_len, "ECPP DMA");
142
143 if (!sparc_ebus_dmas[slot].info.regs)
144 goto out_clear_map;
145
146 sparc_ebus_dmas[slot].info.flags = 0;
147 sparc_ebus_dmas[slot].info.callback = NULL;
148 sparc_ebus_dmas[slot].info.client_cookie = NULL;
149 sparc_ebus_dmas[slot].info.irq = 0xdeadbeef;
150 strcpy(sparc_ebus_dmas[slot].info.name, "parport");
151 if (ebus_dma_register(&sparc_ebus_dmas[slot].info))
152 goto out_unmap_regs;
153
154 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1);
155
156 /* Configure IRQ to Push Pull, Level Low */
157 /* Enable ECP, set bit 2 of the CTR first */
158 outb(0x04, base + 0x02);
159 ns87303_modify(config, PCR,
160 PCR_EPP_ENABLE |
161 PCR_IRQ_ODRAIN,
162 PCR_ECP_ENABLE |
163 PCR_ECP_CLK_ENA |
164 PCR_IRQ_POLAR);
165
166 /* CTR bit 5 controls direction of port */
167 ns87303_modify(config, PTR,
168 0, PTR_LPT_REG_DIR);
169
170 p = parport_pc_probe_port(base, base + 0x400,
171 op->archdata.irqs[0],
172 slot,
173 op->dev.parent,
174 0);
175 err = -ENOMEM;
176 if (!p)
177 goto out_disable_irq;
178
179 dev_set_drvdata(&op->dev, p);
180
181 return 0;
182
183 out_disable_irq:
184 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
185 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
186
187 out_unmap_regs:
188 of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len);
189
190 out_clear_map:
191 clear_bit(slot, dma_slot_map);
192
193 out_err:
194 return err;
195 }
196
ecpp_remove(struct platform_device * op)197 static int ecpp_remove(struct platform_device *op)
198 {
199 struct parport *p = dev_get_drvdata(&op->dev);
200 int slot = p->dma;
201
202 parport_pc_unregister_port(p);
203
204 if (slot != PARPORT_DMA_NOFIFO) {
205 unsigned long d_base = op->resource[2].start;
206 unsigned long d_len;
207
208 d_len = (op->resource[2].end - d_base) + 1UL;
209
210 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
211 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
212 of_iounmap(&op->resource[2],
213 sparc_ebus_dmas[slot].info.regs,
214 d_len);
215 clear_bit(slot, dma_slot_map);
216 }
217
218 return 0;
219 }
220
221 static const struct of_device_id ecpp_match[] = {
222 {
223 .name = "ecpp",
224 },
225 {
226 .name = "parallel",
227 .compatible = "ecpp",
228 },
229 {
230 .name = "parallel",
231 .compatible = "ns87317-ecpp",
232 },
233 {
234 .name = "parallel",
235 .compatible = "pnpALI,1533,3",
236 },
237 {},
238 };
239
240 static struct platform_driver ecpp_driver = {
241 .driver = {
242 .name = "ecpp",
243 .of_match_table = ecpp_match,
244 },
245 .probe = ecpp_probe,
246 .remove = ecpp_remove,
247 };
248
parport_pc_find_nonpci_ports(int autoirq,int autodma)249 static int parport_pc_find_nonpci_ports(int autoirq, int autodma)
250 {
251 return platform_driver_register(&ecpp_driver);
252 }
253
254 #endif /* !(_ASM_SPARC64_PARPORT_H */
255