Debian Codegraph @

arch/sparc/include/asm/parport_64.h

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