1 /* $Id: parport.h,v 1.11 2001/05/11 07:54:24 davem Exp $
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
12 #include <asm/ns87303.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
;
38 } sparc_ebus_dmas
[PARPORT_PC_MAX_PORTS
];
40 static __inline__
int request_dma(unsigned int dmanr
, const char *device_id
)
42 if (dmanr
>= PARPORT_PC_MAX_PORTS
)
44 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 1) != 0)
49 static __inline__
void free_dma(unsigned int dmanr
)
51 if (dmanr
>= PARPORT_PC_MAX_PORTS
) {
52 printk(KERN_WARNING
"Trying to free DMA%d\n", dmanr
);
55 if (xchg(&sparc_ebus_dmas
[dmanr
].lock
, 0) == 0) {
56 printk(KERN_WARNING
"Trying to free free DMA%d\n", dmanr
);
61 static __inline__
void enable_dma(unsigned int dmanr
)
63 ebus_dma_enable(&sparc_ebus_dmas
[dmanr
].info
, 1);
65 if (ebus_dma_request(&sparc_ebus_dmas
[dmanr
].info
,
66 sparc_ebus_dmas
[dmanr
].addr
,
67 sparc_ebus_dmas
[dmanr
].count
))
71 static __inline__
void disable_dma(unsigned int dmanr
)
73 ebus_dma_enable(&sparc_ebus_dmas
[dmanr
].info
, 0);
76 static __inline__
void clear_dma_ff(unsigned int dmanr
)
81 static __inline__
void set_dma_mode(unsigned int dmanr
, char mode
)
83 ebus_dma_prepare(&sparc_ebus_dmas
[dmanr
].info
, (mode
!= DMA_MODE_WRITE
));
86 static __inline__
void set_dma_addr(unsigned int dmanr
, unsigned int addr
)
88 sparc_ebus_dmas
[dmanr
].addr
= addr
;
91 static __inline__
void set_dma_count(unsigned int dmanr
, unsigned int count
)
93 sparc_ebus_dmas
[dmanr
].count
= count
;
96 static __inline__
unsigned int get_dma_residue(unsigned int dmanr
)
98 return ebus_dma_residue(&sparc_ebus_dmas
[dmanr
].info
);
101 static int ebus_ecpp_p(struct linux_ebus_device
*edev
)
103 if (!strcmp(edev
->prom_node
->name
, "ecpp"))
105 if (!strcmp(edev
->prom_node
->name
, "parallel")) {
108 compat
= of_get_property(edev
->prom_node
,
111 (!strcmp(compat
, "ecpp") ||
112 !strcmp(compat
, "ns87317-ecpp") ||
113 !strcmp(compat
+ 13, "ecpp")))
119 static int parport_isa_probe(int count
)
121 struct sparc_isa_bridge
*isa_br
;
122 struct sparc_isa_device
*isa_dev
;
124 for_each_isa(isa_br
) {
125 for_each_isadev(isa_dev
, isa_br
) {
126 struct sparc_isa_device
*child
;
129 if (strcmp(isa_dev
->prom_node
->name
, "dma"))
132 child
= isa_dev
->child
;
134 if (!strcmp(child
->prom_node
->name
, "parallel"))
141 base
= child
->resource
.start
;
143 /* No DMA, see commentary in
144 * asm-sparc64/floppy.h:isa_floppy_init()
146 if (parport_pc_probe_port(base
, base
+ 0x400,
147 child
->irq
, PARPORT_DMA_NOFIFO
,
156 static int parport_pc_find_nonpci_ports (int autoirq
, int autodma
)
158 struct linux_ebus
*ebus
;
159 struct linux_ebus_device
*edev
;
162 for_each_ebus(ebus
) {
163 for_each_ebusdev(edev
, ebus
) {
164 if (ebus_ecpp_p(edev
)) {
165 unsigned long base
= edev
->resource
[0].start
;
166 unsigned long config
= edev
->resource
[1].start
;
167 unsigned long d_base
= edev
->resource
[2].start
;
170 spin_lock_init(&sparc_ebus_dmas
[count
].info
.lock
);
171 d_len
= (edev
->resource
[2].end
-
173 sparc_ebus_dmas
[count
].info
.regs
=
174 ioremap(d_base
, d_len
);
175 if (!sparc_ebus_dmas
[count
].info
.regs
)
177 sparc_ebus_dmas
[count
].info
.flags
= 0;
178 sparc_ebus_dmas
[count
].info
.callback
= NULL
;
179 sparc_ebus_dmas
[count
].info
.client_cookie
= NULL
;
180 sparc_ebus_dmas
[count
].info
.irq
= 0xdeadbeef;
181 strcpy(sparc_ebus_dmas
[count
].info
.name
, "parport");
182 if (ebus_dma_register(&sparc_ebus_dmas
[count
].info
))
184 ebus_dma_irq_enable(&sparc_ebus_dmas
[count
].info
, 1);
186 /* Configure IRQ to Push Pull, Level Low */
187 /* Enable ECP, set bit 2 of the CTR first */
188 outb(0x04, base
+ 0x02);
189 ns87303_modify(config
, PCR
,
196 /* CTR bit 5 controls direction of port */
197 ns87303_modify(config
, PTR
,
200 if (parport_pc_probe_port(base
, base
+ 0x400,
208 count
= parport_isa_probe(count
);
213 #endif /* !(_ASM_SPARC64_PARPORT_H */