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)
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>
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
24 #ifdef CONFIG_PARPORT_PC_FIFO
25 static DEFINE_SPINLOCK(dma_spin_lock
);
27 #define claim_dma_lock() \
28 ({ unsigned long flags; \
29 spin_lock_irqsave(&dma_spin_lock, flags); \
33 #define release_dma_lock(__flags) \
34 spin_unlock_irqrestore(&dma_spin_lock, __flags);
37 static struct sparc_ebus_info
{
38 struct ebus_dma_info info
;
44 } sparc_ebus_dmas
[PARPORT_PC_MAX_PORTS
];
46 static DECLARE_BITMAP(dma_slot_map
, PARPORT_PC_MAX_PORTS
);
48 static inline int request_dma(unsigned int dmanr
, const char *device_id
)
50 if (dmanr
>= PARPORT_PC_MAX_PORTS
)
52 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 1) != 0)
57 static inline void free_dma(unsigned int dmanr
)
59 if (dmanr
>= PARPORT_PC_MAX_PORTS
) {
60 printk(KERN_WARNING
"Trying to free DMA%d\n", dmanr
);
63 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 0) == 0) {
64 printk(KERN_WARNING
"Trying to free free DMA%d\n", dmanr
);
69 static inline void enable_dma(unsigned int dmanr
)
71 ebus_dma_enable(&sparc_ebus_dmas
[dmanr
].info
, 1);
73 if (ebus_dma_request(&sparc_ebus_dmas
[dmanr
].info
,
74 sparc_ebus_dmas
[dmanr
].addr
,
75 sparc_ebus_dmas
[dmanr
].count
))
79 static inline void disable_dma(unsigned int dmanr
)
81 ebus_dma_enable(&sparc_ebus_dmas
[dmanr
].info
, 0);
84 static inline void clear_dma_ff(unsigned int dmanr
)
89 static inline void set_dma_mode(unsigned int dmanr
, char mode
)
91 ebus_dma_prepare(&sparc_ebus_dmas
[dmanr
].info
, (mode
!= DMA_MODE_WRITE
));
94 static inline void set_dma_addr(unsigned int dmanr
, unsigned int addr
)
96 sparc_ebus_dmas
[dmanr
].addr
= addr
;
99 static inline void set_dma_count(unsigned int dmanr
, unsigned int count
)
101 sparc_ebus_dmas
[dmanr
].count
= count
;
104 static inline unsigned int get_dma_residue(unsigned int dmanr
)
106 return ebus_dma_residue(&sparc_ebus_dmas
[dmanr
].info
);
109 static int ecpp_probe(struct platform_device
*op
)
111 unsigned long base
= op
->resource
[0].start
;
112 unsigned long config
= op
->resource
[1].start
;
113 unsigned long d_base
= op
->resource
[2].start
;
115 struct device_node
*parent
;
119 parent
= op
->dev
.of_node
->parent
;
120 if (of_node_name_eq(parent
, "dma")) {
121 p
= parport_pc_probe_port(base
, base
+ 0x400,
122 op
->archdata
.irqs
[0], PARPORT_DMA_NOFIFO
,
123 op
->dev
.parent
->parent
, 0);
126 dev_set_drvdata(&op
->dev
, p
);
130 for (slot
= 0; slot
< PARPORT_PC_MAX_PORTS
; slot
++) {
131 if (!test_and_set_bit(slot
, dma_slot_map
))
135 if (slot
>= PARPORT_PC_MAX_PORTS
)
138 spin_lock_init(&sparc_ebus_dmas
[slot
].info
.lock
);
140 d_len
= (op
->resource
[2].end
- d_base
) + 1UL;
141 sparc_ebus_dmas
[slot
].info
.regs
=
142 of_ioremap(&op
->resource
[2], 0, d_len
, "ECPP DMA");
144 if (!sparc_ebus_dmas
[slot
].info
.regs
)
147 sparc_ebus_dmas
[slot
].info
.flags
= 0;
148 sparc_ebus_dmas
[slot
].info
.callback
= NULL
;
149 sparc_ebus_dmas
[slot
].info
.client_cookie
= NULL
;
150 sparc_ebus_dmas
[slot
].info
.irq
= 0xdeadbeef;
151 strcpy(sparc_ebus_dmas
[slot
].info
.name
, "parport");
152 if (ebus_dma_register(&sparc_ebus_dmas
[slot
].info
))
155 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 1);
157 /* Configure IRQ to Push Pull, Level Low */
158 /* Enable ECP, set bit 2 of the CTR first */
159 outb(0x04, base
+ 0x02);
160 ns87303_modify(config
, PCR
,
167 /* CTR bit 5 controls direction of port */
168 ns87303_modify(config
, PTR
,
171 p
= parport_pc_probe_port(base
, base
+ 0x400,
172 op
->archdata
.irqs
[0],
178 goto out_disable_irq
;
180 dev_set_drvdata(&op
->dev
, p
);
185 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 0);
186 ebus_dma_unregister(&sparc_ebus_dmas
[slot
].info
);
189 of_iounmap(&op
->resource
[2], sparc_ebus_dmas
[slot
].info
.regs
, d_len
);
192 clear_bit(slot
, dma_slot_map
);
198 static int ecpp_remove(struct platform_device
*op
)
200 struct parport
*p
= dev_get_drvdata(&op
->dev
);
203 parport_pc_unregister_port(p
);
205 if (slot
!= PARPORT_DMA_NOFIFO
) {
206 unsigned long d_base
= op
->resource
[2].start
;
209 d_len
= (op
->resource
[2].end
- d_base
) + 1UL;
211 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 0);
212 ebus_dma_unregister(&sparc_ebus_dmas
[slot
].info
);
213 of_iounmap(&op
->resource
[2],
214 sparc_ebus_dmas
[slot
].info
.regs
,
216 clear_bit(slot
, dma_slot_map
);
222 static const struct of_device_id ecpp_match
[] = {
228 .compatible
= "ecpp",
232 .compatible
= "ns87317-ecpp",
236 .compatible
= "pnpALI,1533,3",
241 static struct platform_driver ecpp_driver
= {
244 .of_match_table
= ecpp_match
,
247 .remove
= ecpp_remove
,
250 static int parport_pc_find_nonpci_ports(int autoirq
, int autodma
)
252 return platform_driver_register(&ecpp_driver
);
255 #endif /* !(_ASM_SPARC64_PARPORT_H */