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
10 #include <asm/ns87303.h>
11 #include <asm/of_device.h>
14 #define PARPORT_PC_MAX_PORTS PARPORT_MAX
17 * While sparc64 doesn't have an ISA DMA API, we provide something that looks
18 * close enough to make parport_pc happy
22 static DEFINE_SPINLOCK(dma_spin_lock
);
24 #define claim_dma_lock() \
25 ({ unsigned long flags; \
26 spin_lock_irqsave(&dma_spin_lock, flags); \
30 #define release_dma_lock(__flags) \
31 spin_unlock_irqrestore(&dma_spin_lock, __flags);
33 static struct sparc_ebus_info
{
34 struct ebus_dma_info info
;
40 } sparc_ebus_dmas
[PARPORT_PC_MAX_PORTS
];
42 static DECLARE_BITMAP(dma_slot_map
, PARPORT_PC_MAX_PORTS
);
44 static inline int request_dma(unsigned int dmanr
, const char *device_id
)
46 if (dmanr
>= PARPORT_PC_MAX_PORTS
)
48 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 1) != 0)
53 static inline void free_dma(unsigned int dmanr
)
55 if (dmanr
>= PARPORT_PC_MAX_PORTS
) {
56 printk(KERN_WARNING
"Trying to free DMA%d\n", dmanr
);
59 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 0) == 0) {
60 printk(KERN_WARNING
"Trying to free free DMA%d\n", dmanr
);
65 static inline void enable_dma(unsigned int dmanr
)
67 ebus_dma_enable(&sparc_ebus_dmas
[dmanr
].info
, 1);
69 if (ebus_dma_request(&sparc_ebus_dmas
[dmanr
].info
,
70 sparc_ebus_dmas
[dmanr
].addr
,
71 sparc_ebus_dmas
[dmanr
].count
))
75 static inline void disable_dma(unsigned int dmanr
)
77 ebus_dma_enable(&sparc_ebus_dmas
[dmanr
].info
, 0);
80 static inline void clear_dma_ff(unsigned int dmanr
)
85 static inline void set_dma_mode(unsigned int dmanr
, char mode
)
87 ebus_dma_prepare(&sparc_ebus_dmas
[dmanr
].info
, (mode
!= DMA_MODE_WRITE
));
90 static inline void set_dma_addr(unsigned int dmanr
, unsigned int addr
)
92 sparc_ebus_dmas
[dmanr
].addr
= addr
;
95 static inline void set_dma_count(unsigned int dmanr
, unsigned int count
)
97 sparc_ebus_dmas
[dmanr
].count
= count
;
100 static inline unsigned int get_dma_residue(unsigned int dmanr
)
102 return ebus_dma_residue(&sparc_ebus_dmas
[dmanr
].info
);
105 static int __devinit
ecpp_probe(struct of_device
*op
, const struct of_device_id
*match
)
107 unsigned long base
= op
->resource
[0].start
;
108 unsigned long config
= op
->resource
[1].start
;
109 unsigned long d_base
= op
->resource
[2].start
;
111 struct device_node
*parent
;
115 parent
= op
->node
->parent
;
116 if (!strcmp(parent
->name
, "dma")) {
117 p
= parport_pc_probe_port(base
, base
+ 0x400,
118 op
->irqs
[0], PARPORT_DMA_NOFIFO
,
119 op
->dev
.parent
->parent
);
122 dev_set_drvdata(&op
->dev
, p
);
126 for (slot
= 0; slot
< PARPORT_PC_MAX_PORTS
; slot
++) {
127 if (!test_and_set_bit(slot
, dma_slot_map
))
131 if (slot
>= PARPORT_PC_MAX_PORTS
)
134 spin_lock_init(&sparc_ebus_dmas
[slot
].info
.lock
);
136 d_len
= (op
->resource
[2].end
- d_base
) + 1UL;
137 sparc_ebus_dmas
[slot
].info
.regs
=
138 of_ioremap(&op
->resource
[2], 0, d_len
, "ECPP DMA");
140 if (!sparc_ebus_dmas
[slot
].info
.regs
)
143 sparc_ebus_dmas
[slot
].info
.flags
= 0;
144 sparc_ebus_dmas
[slot
].info
.callback
= NULL
;
145 sparc_ebus_dmas
[slot
].info
.client_cookie
= NULL
;
146 sparc_ebus_dmas
[slot
].info
.irq
= 0xdeadbeef;
147 strcpy(sparc_ebus_dmas
[slot
].info
.name
, "parport");
148 if (ebus_dma_register(&sparc_ebus_dmas
[slot
].info
))
151 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 1);
153 /* Configure IRQ to Push Pull, Level Low */
154 /* Enable ECP, set bit 2 of the CTR first */
155 outb(0x04, base
+ 0x02);
156 ns87303_modify(config
, PCR
,
163 /* CTR bit 5 controls direction of port */
164 ns87303_modify(config
, PTR
,
167 p
= parport_pc_probe_port(base
, base
+ 0x400,
173 goto out_disable_irq
;
175 dev_set_drvdata(&op
->dev
, p
);
180 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 0);
181 ebus_dma_unregister(&sparc_ebus_dmas
[slot
].info
);
184 of_iounmap(&op
->resource
[2], sparc_ebus_dmas
[slot
].info
.regs
, d_len
);
187 clear_bit(slot
, dma_slot_map
);
193 static int __devexit
ecpp_remove(struct of_device
*op
)
195 struct parport
*p
= dev_get_drvdata(&op
->dev
);
198 parport_pc_unregister_port(p
);
200 if (slot
!= PARPORT_DMA_NOFIFO
) {
201 unsigned long d_base
= op
->resource
[2].start
;
204 d_len
= (op
->resource
[2].end
- d_base
) + 1UL;
206 ebus_dma_irq_enable(&sparc_ebus_dmas
[slot
].info
, 0);
207 ebus_dma_unregister(&sparc_ebus_dmas
[slot
].info
);
208 of_iounmap(&op
->resource
[2],
209 sparc_ebus_dmas
[slot
].info
.regs
,
211 clear_bit(slot
, dma_slot_map
);
217 static struct of_device_id ecpp_match
[] = {
223 .compatible
= "ecpp",
227 .compatible
= "ns87317-ecpp",
232 static struct of_platform_driver ecpp_driver
= {
234 .match_table
= ecpp_match
,
236 .remove
= __devexit_p(ecpp_remove
),
239 static int parport_pc_find_nonpci_ports(int autoirq
, int autodma
)
241 of_register_driver(&ecpp_driver
, &of_bus_type
);
246 #endif /* !(_ASM_SPARC64_PARPORT_H */