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
11 #include <linux/platform_device.h>
13 #include <asm/ebus_dma.h>
14 #include <asm/ns87303.h>
17 #define PARPORT_PC_MAX_PORTS PARPORT_MAX
20 * While sparc64 doesn't have an ISA DMA API, we provide something that looks
21 * close enough to make parport_pc happy
25 #ifdef CONFIG_PARPORT_PC_FIFO
26 static DEFINE_SPINLOCK(dma_spin_lock
);
28 #define claim_dma_lock() \
29 ({ unsigned long flags; \
30 spin_lock_irqsave(&dma_spin_lock, flags); \
34 #define release_dma_lock(__flags) \
35 spin_unlock_irqrestore(&dma_spin_lock, __flags);
38 static struct sparc_ebus_info
{
39 struct ebus_dma_info info
;
45 } sparc_ebus_dmas
[PARPORT_PC_MAX_PORTS
];
47 static DECLARE_BITMAP(dma_slot_map
, PARPORT_PC_MAX_PORTS
);
49 static inline int request_dma(unsigned int dmanr
, const char *device_id
)
51 if (dmanr
>= PARPORT_PC_MAX_PORTS
)
53 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 1) != 0)
58 static inline void free_dma(unsigned int dmanr
)
60 if (dmanr
>= PARPORT_PC_MAX_PORTS
) {
61 printk(KERN_WARNING
"Trying to free DMA%d\n", dmanr
);
64 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 0) == 0) {
65 printk(KERN_WARNING
"Trying to free free DMA%d\n", dmanr
);
70 static inline void enable_dma(unsigned int dmanr
)
72 ebus_dma_enable(&sparc_ebus_dmas
[dmanr
].info
, 1);
74 if (ebus_dma_request(&sparc_ebus_dmas
[dmanr
].info
,
75 sparc_ebus_dmas
[dmanr
].addr
,
76 sparc_ebus_dmas
[dmanr
].count
))
80 static inline void disable_dma(unsigned int dmanr
)
82 ebus_dma_enable(&sparc_ebus_dmas
[dmanr
].info
, 0);
85 static inline void clear_dma_ff(unsigned int dmanr
)
90 static inline void set_dma_mode(unsigned int dmanr
, char mode
)
92 ebus_dma_prepare(&sparc_ebus_dmas
[dmanr
].info
, (mode
!= DMA_MODE_WRITE
));
95 static inline void set_dma_addr(unsigned int dmanr
, unsigned int addr
)
97 sparc_ebus_dmas
[dmanr
].addr
= addr
;
100 static inline void set_dma_count(unsigned int dmanr
, unsigned int count
)
102 sparc_ebus_dmas
[dmanr
].count
= count
;
105 static inline unsigned int get_dma_residue(unsigned int dmanr
)
107 return ebus_dma_residue(&sparc_ebus_dmas
[dmanr
].info
);
110 static int ecpp_probe(struct platform_device
*op
)
112 unsigned long base
= op
->resource
[0].start
;
113 unsigned long config
= op
->resource
[1].start
;
114 unsigned long d_base
= op
->resource
[2].start
;
116 struct device_node
*parent
;
120 parent
= op
->dev
.of_node
->parent
;
121 if (of_node_name_eq(parent
, "dma")) {
122 p
= parport_pc_probe_port(base
, base
+ 0x400,
123 op
->archdata
.irqs
[0], PARPORT_DMA_NOFIFO
,
124 op
->dev
.parent
->parent
, 0);
127 dev_set_drvdata(&op
->dev
, p
);
131 for (slot
= 0; slot
< PARPORT_PC_MAX_PORTS
; slot
++) {
132 if (!test_and_set_bit(slot
, dma_slot_map
))
136 if (slot
>= PARPORT_PC_MAX_PORTS
)
139 spin_lock_init(&sparc_ebus_dmas
[slot
].info
.lock
);
141 d_len
= (op
->resource
[2].end
- d_base
) + 1UL;
142 sparc_ebus_dmas
[slot
].info
.regs
=
143 of_ioremap(&op
->resource
[2], 0, d_len
, "ECPP DMA");
145 if (!sparc_ebus_dmas
[slot
].info
.regs
)
148 sparc_ebus_dmas
[slot
].info
.flags
= 0;
149 sparc_ebus_dmas
[slot
].info
.callback
= NULL
;
150 sparc_ebus_dmas
[slot
].info
.client_cookie
= NULL
;
151 sparc_ebus_dmas
[slot
].info
.irq
= 0xdeadbeef;
152 strcpy(sparc_ebus_dmas
[slot
].info
.name
, "parport");
153 if (ebus_dma_register(&sparc_ebus_dmas
[slot
].info
))
156 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 1);
158 /* Configure IRQ to Push Pull, Level Low */
159 /* Enable ECP, set bit 2 of the CTR first */
160 outb(0x04, base
+ 0x02);
161 ns87303_modify(config
, PCR
,
168 /* CTR bit 5 controls direction of port */
169 ns87303_modify(config
, PTR
,
172 p
= parport_pc_probe_port(base
, base
+ 0x400,
173 op
->archdata
.irqs
[0],
179 goto out_disable_irq
;
181 dev_set_drvdata(&op
->dev
, p
);
186 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 0);
187 ebus_dma_unregister(&sparc_ebus_dmas
[slot
].info
);
190 of_iounmap(&op
->resource
[2], sparc_ebus_dmas
[slot
].info
.regs
, d_len
);
193 clear_bit(slot
, dma_slot_map
);
199 static void ecpp_remove(struct platform_device
*op
)
201 struct parport
*p
= dev_get_drvdata(&op
->dev
);
204 parport_pc_unregister_port(p
);
206 if (slot
!= PARPORT_DMA_NOFIFO
) {
207 unsigned long d_base
= op
->resource
[2].start
;
210 d_len
= (op
->resource
[2].end
- d_base
) + 1UL;
212 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 0);
213 ebus_dma_unregister(&sparc_ebus_dmas
[slot
].info
);
214 of_iounmap(&op
->resource
[2],
215 sparc_ebus_dmas
[slot
].info
.regs
,
217 clear_bit(slot
, dma_slot_map
);
221 static const struct of_device_id ecpp_match
[] = {
227 .compatible
= "ecpp",
231 .compatible
= "ns87317-ecpp",
235 .compatible
= "pnpALI,1533,3",
240 static struct platform_driver ecpp_driver
= {
243 .of_match_table
= ecpp_match
,
246 .remove
= ecpp_remove
,
249 static int parport_pc_find_nonpci_ports(int autoirq
, int autodma
)
251 return platform_driver_register(&ecpp_driver
);
254 #endif /* !(_ASM_SPARC64_PARPORT_H */