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 static DEFINE_SPINLOCK(dma_spin_lock
);
26 #define claim_dma_lock() \
27 ({ unsigned long flags; \
28 spin_lock_irqsave(&dma_spin_lock, 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
;
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
)
50 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 1) != 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
);
61 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 0) == 0) {
62 printk(KERN_WARNING
"Trying to free free DMA%d\n", dmanr
);
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
))
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
)
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
;
113 struct device_node
*parent
;
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);
124 dev_set_drvdata(&op
->dev
, p
);
128 for (slot
= 0; slot
< PARPORT_PC_MAX_PORTS
; slot
++) {
129 if (!test_and_set_bit(slot
, dma_slot_map
))
133 if (slot
>= PARPORT_PC_MAX_PORTS
)
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
)
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
))
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
,
165 /* CTR bit 5 controls direction of port */
166 ns87303_modify(config
, PTR
,
169 p
= parport_pc_probe_port(base
, base
+ 0x400,
170 op
->archdata
.irqs
[0],
176 goto out_disable_irq
;
178 dev_set_drvdata(&op
->dev
, p
);
183 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 0);
184 ebus_dma_unregister(&sparc_ebus_dmas
[slot
].info
);
187 of_iounmap(&op
->resource
[2], sparc_ebus_dmas
[slot
].info
.regs
, d_len
);
190 clear_bit(slot
, dma_slot_map
);
196 static int ecpp_remove(struct platform_device
*op
)
198 struct parport
*p
= dev_get_drvdata(&op
->dev
);
201 parport_pc_unregister_port(p
);
203 if (slot
!= PARPORT_DMA_NOFIFO
) {
204 unsigned long d_base
= op
->resource
[2].start
;
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
,
214 clear_bit(slot
, dma_slot_map
);
220 static const struct of_device_id ecpp_match
[] = {
226 .compatible
= "ecpp",
230 .compatible
= "ns87317-ecpp",
234 .compatible
= "pnpALI,1533,3",
239 static struct platform_driver ecpp_driver
= {
242 .of_match_table
= ecpp_match
,
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 */