1 /* parport.h: sparc64 specific parport initialization and dma.
3 * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be)
6 #ifndef _ASM_SPARC64_PARPORT_H
7 #define _ASM_SPARC64_PARPORT_H 1
9 #include <linux/of_device.h>
11 #include <asm/ebus_dma.h>
12 #include <asm/ns87303.h>
15 #define PARPORT_PC_MAX_PORTS PARPORT_MAX
18 * While sparc64 doesn't have an ISA DMA API, we provide something that looks
19 * close enough to make parport_pc happy
23 static DEFINE_SPINLOCK(dma_spin_lock
);
25 #define claim_dma_lock() \
26 ({ unsigned long flags; \
27 spin_lock_irqsave(&dma_spin_lock, flags); \
31 #define release_dma_lock(__flags) \
32 spin_unlock_irqrestore(&dma_spin_lock, __flags);
34 static struct sparc_ebus_info
{
35 struct ebus_dma_info info
;
41 } sparc_ebus_dmas
[PARPORT_PC_MAX_PORTS
];
43 static DECLARE_BITMAP(dma_slot_map
, PARPORT_PC_MAX_PORTS
);
45 static inline int request_dma(unsigned int dmanr
, const char *device_id
)
47 if (dmanr
>= PARPORT_PC_MAX_PORTS
)
49 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 1) != 0)
54 static inline void free_dma(unsigned int dmanr
)
56 if (dmanr
>= PARPORT_PC_MAX_PORTS
) {
57 printk(KERN_WARNING
"Trying to free DMA%d\n", dmanr
);
60 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 0) == 0) {
61 printk(KERN_WARNING
"Trying to free free DMA%d\n", dmanr
);
66 static inline void enable_dma(unsigned int dmanr
)
68 ebus_dma_enable(&sparc_ebus_dmas
[dmanr
].info
, 1);
70 if (ebus_dma_request(&sparc_ebus_dmas
[dmanr
].info
,
71 sparc_ebus_dmas
[dmanr
].addr
,
72 sparc_ebus_dmas
[dmanr
].count
))
76 static inline void disable_dma(unsigned int dmanr
)
78 ebus_dma_enable(&sparc_ebus_dmas
[dmanr
].info
, 0);
81 static inline void clear_dma_ff(unsigned int dmanr
)
86 static inline void set_dma_mode(unsigned int dmanr
, char mode
)
88 ebus_dma_prepare(&sparc_ebus_dmas
[dmanr
].info
, (mode
!= DMA_MODE_WRITE
));
91 static inline void set_dma_addr(unsigned int dmanr
, unsigned int addr
)
93 sparc_ebus_dmas
[dmanr
].addr
= addr
;
96 static inline void set_dma_count(unsigned int dmanr
, unsigned int count
)
98 sparc_ebus_dmas
[dmanr
].count
= count
;
101 static inline unsigned int get_dma_residue(unsigned int dmanr
)
103 return ebus_dma_residue(&sparc_ebus_dmas
[dmanr
].info
);
106 static int ecpp_probe(struct platform_device
*op
)
108 unsigned long base
= op
->resource
[0].start
;
109 unsigned long config
= op
->resource
[1].start
;
110 unsigned long d_base
= op
->resource
[2].start
;
112 struct device_node
*parent
;
116 parent
= op
->dev
.of_node
->parent
;
117 if (!strcmp(parent
->name
, "dma")) {
118 p
= parport_pc_probe_port(base
, base
+ 0x400,
119 op
->archdata
.irqs
[0], PARPORT_DMA_NOFIFO
,
120 op
->dev
.parent
->parent
, 0);
123 dev_set_drvdata(&op
->dev
, p
);
127 for (slot
= 0; slot
< PARPORT_PC_MAX_PORTS
; slot
++) {
128 if (!test_and_set_bit(slot
, dma_slot_map
))
132 if (slot
>= PARPORT_PC_MAX_PORTS
)
135 spin_lock_init(&sparc_ebus_dmas
[slot
].info
.lock
);
137 d_len
= (op
->resource
[2].end
- d_base
) + 1UL;
138 sparc_ebus_dmas
[slot
].info
.regs
=
139 of_ioremap(&op
->resource
[2], 0, d_len
, "ECPP DMA");
141 if (!sparc_ebus_dmas
[slot
].info
.regs
)
144 sparc_ebus_dmas
[slot
].info
.flags
= 0;
145 sparc_ebus_dmas
[slot
].info
.callback
= NULL
;
146 sparc_ebus_dmas
[slot
].info
.client_cookie
= NULL
;
147 sparc_ebus_dmas
[slot
].info
.irq
= 0xdeadbeef;
148 strcpy(sparc_ebus_dmas
[slot
].info
.name
, "parport");
149 if (ebus_dma_register(&sparc_ebus_dmas
[slot
].info
))
152 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 1);
154 /* Configure IRQ to Push Pull, Level Low */
155 /* Enable ECP, set bit 2 of the CTR first */
156 outb(0x04, base
+ 0x02);
157 ns87303_modify(config
, PCR
,
164 /* CTR bit 5 controls direction of port */
165 ns87303_modify(config
, PTR
,
168 p
= parport_pc_probe_port(base
, base
+ 0x400,
169 op
->archdata
.irqs
[0],
175 goto out_disable_irq
;
177 dev_set_drvdata(&op
->dev
, p
);
182 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 0);
183 ebus_dma_unregister(&sparc_ebus_dmas
[slot
].info
);
186 of_iounmap(&op
->resource
[2], sparc_ebus_dmas
[slot
].info
.regs
, d_len
);
189 clear_bit(slot
, dma_slot_map
);
195 static int ecpp_remove(struct platform_device
*op
)
197 struct parport
*p
= dev_get_drvdata(&op
->dev
);
200 parport_pc_unregister_port(p
);
202 if (slot
!= PARPORT_DMA_NOFIFO
) {
203 unsigned long d_base
= op
->resource
[2].start
;
206 d_len
= (op
->resource
[2].end
- d_base
) + 1UL;
208 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 0);
209 ebus_dma_unregister(&sparc_ebus_dmas
[slot
].info
);
210 of_iounmap(&op
->resource
[2],
211 sparc_ebus_dmas
[slot
].info
.regs
,
213 clear_bit(slot
, dma_slot_map
);
219 static const struct of_device_id ecpp_match
[] = {
225 .compatible
= "ecpp",
229 .compatible
= "ns87317-ecpp",
233 .compatible
= "pnpALI,1533,3",
238 static struct platform_driver ecpp_driver
= {
241 .owner
= THIS_MODULE
,
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 */