Merge tag 'xtensa-20180225' of git://github.com/jcmvbkbc/linux-xtensa
[cris-mirror.git] / arch / sparc / include / asm / parport.h
blob05df5f0430535f307495662610f2c06dda92d0b5
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* parport.h: sparc64 specific parport initialization and dma.
4 * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be)
5 */
7 #ifndef _ASM_SPARC64_PARPORT_H
8 #define _ASM_SPARC64_PARPORT_H 1
10 #include <linux/of_device.h>
12 #include <asm/ebus_dma.h>
13 #include <asm/ns87303.h>
14 #include <asm/prom.h>
16 #define PARPORT_PC_MAX_PORTS PARPORT_MAX
19 * While sparc64 doesn't have an ISA DMA API, we provide something that looks
20 * close enough to make parport_pc happy
22 #define HAS_DMA
24 static DEFINE_SPINLOCK(dma_spin_lock);
26 #define claim_dma_lock() \
27 ({ unsigned long flags; \
28 spin_lock_irqsave(&dma_spin_lock, flags); \
29 flags; \
32 #define release_dma_lock(__flags) \
33 spin_unlock_irqrestore(&dma_spin_lock, __flags);
35 static struct sparc_ebus_info {
36 struct ebus_dma_info info;
37 unsigned int addr;
38 unsigned int count;
39 int lock;
41 struct parport *port;
42 } sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
44 static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS);
46 static inline int request_dma(unsigned int dmanr, const char *device_id)
48 if (dmanr >= PARPORT_PC_MAX_PORTS)
49 return -EINVAL;
50 if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0)
51 return -EBUSY;
52 return 0;
55 static inline void free_dma(unsigned int dmanr)
57 if (dmanr >= PARPORT_PC_MAX_PORTS) {
58 printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
59 return;
61 if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
62 printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
63 return;
67 static inline void enable_dma(unsigned int dmanr)
69 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
71 if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
72 sparc_ebus_dmas[dmanr].addr,
73 sparc_ebus_dmas[dmanr].count))
74 BUG();
77 static inline void disable_dma(unsigned int dmanr)
79 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
82 static inline void clear_dma_ff(unsigned int dmanr)
84 /* nothing */
87 static inline void set_dma_mode(unsigned int dmanr, char mode)
89 ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
92 static inline void set_dma_addr(unsigned int dmanr, unsigned int addr)
94 sparc_ebus_dmas[dmanr].addr = addr;
97 static inline void set_dma_count(unsigned int dmanr, unsigned int count)
99 sparc_ebus_dmas[dmanr].count = count;
102 static inline unsigned int get_dma_residue(unsigned int dmanr)
104 return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
107 static int ecpp_probe(struct platform_device *op)
109 unsigned long base = op->resource[0].start;
110 unsigned long config = op->resource[1].start;
111 unsigned long d_base = op->resource[2].start;
112 unsigned long d_len;
113 struct device_node *parent;
114 struct parport *p;
115 int slot, err;
117 parent = op->dev.of_node->parent;
118 if (!strcmp(parent->name, "dma")) {
119 p = parport_pc_probe_port(base, base + 0x400,
120 op->archdata.irqs[0], PARPORT_DMA_NOFIFO,
121 op->dev.parent->parent, 0);
122 if (!p)
123 return -ENOMEM;
124 dev_set_drvdata(&op->dev, p);
125 return 0;
128 for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) {
129 if (!test_and_set_bit(slot, dma_slot_map))
130 break;
132 err = -ENODEV;
133 if (slot >= PARPORT_PC_MAX_PORTS)
134 goto out_err;
136 spin_lock_init(&sparc_ebus_dmas[slot].info.lock);
138 d_len = (op->resource[2].end - d_base) + 1UL;
139 sparc_ebus_dmas[slot].info.regs =
140 of_ioremap(&op->resource[2], 0, d_len, "ECPP DMA");
142 if (!sparc_ebus_dmas[slot].info.regs)
143 goto out_clear_map;
145 sparc_ebus_dmas[slot].info.flags = 0;
146 sparc_ebus_dmas[slot].info.callback = NULL;
147 sparc_ebus_dmas[slot].info.client_cookie = NULL;
148 sparc_ebus_dmas[slot].info.irq = 0xdeadbeef;
149 strcpy(sparc_ebus_dmas[slot].info.name, "parport");
150 if (ebus_dma_register(&sparc_ebus_dmas[slot].info))
151 goto out_unmap_regs;
153 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1);
155 /* Configure IRQ to Push Pull, Level Low */
156 /* Enable ECP, set bit 2 of the CTR first */
157 outb(0x04, base + 0x02);
158 ns87303_modify(config, PCR,
159 PCR_EPP_ENABLE |
160 PCR_IRQ_ODRAIN,
161 PCR_ECP_ENABLE |
162 PCR_ECP_CLK_ENA |
163 PCR_IRQ_POLAR);
165 /* CTR bit 5 controls direction of port */
166 ns87303_modify(config, PTR,
167 0, PTR_LPT_REG_DIR);
169 p = parport_pc_probe_port(base, base + 0x400,
170 op->archdata.irqs[0],
171 slot,
172 op->dev.parent,
174 err = -ENOMEM;
175 if (!p)
176 goto out_disable_irq;
178 dev_set_drvdata(&op->dev, p);
180 return 0;
182 out_disable_irq:
183 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
184 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
186 out_unmap_regs:
187 of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len);
189 out_clear_map:
190 clear_bit(slot, dma_slot_map);
192 out_err:
193 return err;
196 static int ecpp_remove(struct platform_device *op)
198 struct parport *p = dev_get_drvdata(&op->dev);
199 int slot = p->dma;
201 parport_pc_unregister_port(p);
203 if (slot != PARPORT_DMA_NOFIFO) {
204 unsigned long d_base = op->resource[2].start;
205 unsigned long d_len;
207 d_len = (op->resource[2].end - d_base) + 1UL;
209 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
210 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
211 of_iounmap(&op->resource[2],
212 sparc_ebus_dmas[slot].info.regs,
213 d_len);
214 clear_bit(slot, dma_slot_map);
217 return 0;
220 static const struct of_device_id ecpp_match[] = {
222 .name = "ecpp",
225 .name = "parallel",
226 .compatible = "ecpp",
229 .name = "parallel",
230 .compatible = "ns87317-ecpp",
233 .name = "parallel",
234 .compatible = "pnpALI,1533,3",
239 static struct platform_driver ecpp_driver = {
240 .driver = {
241 .name = "ecpp",
242 .of_match_table = ecpp_match,
244 .probe = ecpp_probe,
245 .remove = ecpp_remove,
248 static int parport_pc_find_nonpci_ports(int autoirq, int autodma)
250 return platform_driver_register(&ecpp_driver);
253 #endif /* !(_ASM_SPARC64_PARPORT_H */