blob: be9509c8f8c10bc9dcaf54e91e4aae52c265d36d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: parport.h,v 1.11 2001/05/11 07:54:24 davem Exp $
2 * parport.h: sparc64 specific parport initialization and dma.
3 *
4 * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be)
5 */
6
7#ifndef _ASM_SPARC64_PARPORT_H
8#define _ASM_SPARC64_PARPORT_H 1
9
10#include <asm/ebus.h>
11#include <asm/isa.h>
12#include <asm/ns87303.h>
13
14#define PARPORT_PC_MAX_PORTS PARPORT_MAX
15
Al Viro7fbacd52005-05-04 05:39:32 +010016/*
17 * While sparc64 doesn't have an ISA DMA API, we provide something that looks
18 * close enough to make parport_pc happy
19 */
20#define HAS_DMA
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static struct sparc_ebus_info {
23 struct ebus_dma_info info;
24 unsigned int addr;
25 unsigned int count;
David S. Miller74bd7d02007-02-28 13:09:34 -080026 int lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027} sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
28
David S. Miller74bd7d02007-02-28 13:09:34 -080029static __inline__ int request_dma(unsigned int dmanr, const char *device_id)
30{
31 if (dmanr >= PARPORT_PC_MAX_PORTS)
32 return -EINVAL;
33 if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0)
34 return -EBUSY;
35 return 0;
36}
37
38static __inline__ void free_dma(unsigned int dmanr)
39{
40 if (dmanr >= PARPORT_PC_MAX_PORTS) {
41 printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
42 return;
43 }
44 if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
45 printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
46 return;
47 }
48}
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050static __inline__ void enable_dma(unsigned int dmanr)
51{
Eddie C. Doste3e01d62005-07-06 15:41:54 -070052 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
55 sparc_ebus_dmas[dmanr].addr,
56 sparc_ebus_dmas[dmanr].count))
57 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -070058}
59
60static __inline__ void disable_dma(unsigned int dmanr)
61{
62 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
63}
64
65static __inline__ void clear_dma_ff(unsigned int dmanr)
66{
67 /* nothing */
68}
69
70static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
71{
72 ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
73}
74
75static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int addr)
76{
77 sparc_ebus_dmas[dmanr].addr = addr;
78}
79
80static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
81{
82 sparc_ebus_dmas[dmanr].count = count;
83}
84
85static __inline__ unsigned int get_dma_residue(unsigned int dmanr)
86{
87 return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
88}
89
90static int ebus_ecpp_p(struct linux_ebus_device *edev)
91{
David S. Miller690c8fd2006-06-22 19:12:03 -070092 if (!strcmp(edev->prom_node->name, "ecpp"))
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return 1;
David S. Miller690c8fd2006-06-22 19:12:03 -070094 if (!strcmp(edev->prom_node->name, "parallel")) {
95 char *compat;
96
97 compat = of_get_property(edev->prom_node,
98 "compatible", NULL);
99 if (compat &&
100 (!strcmp(compat, "ecpp") ||
101 !strcmp(compat, "ns87317-ecpp") ||
102 !strcmp(compat + 13, "ecpp")))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 return 1;
104 }
105 return 0;
106}
107
108static int parport_isa_probe(int count)
109{
110 struct sparc_isa_bridge *isa_br;
111 struct sparc_isa_device *isa_dev;
112
113 for_each_isa(isa_br) {
114 for_each_isadev(isa_dev, isa_br) {
115 struct sparc_isa_device *child;
116 unsigned long base;
117
David S. Miller690c8fd2006-06-22 19:12:03 -0700118 if (strcmp(isa_dev->prom_node->name, "dma"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 continue;
120
121 child = isa_dev->child;
122 while (child) {
David S. Miller690c8fd2006-06-22 19:12:03 -0700123 if (!strcmp(child->prom_node->name, "parallel"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 break;
125 child = child->next;
126 }
127 if (!child)
128 continue;
129
130 base = child->resource.start;
131
132 /* No DMA, see commentary in
133 * asm-sparc64/floppy.h:isa_floppy_init()
134 */
135 if (parport_pc_probe_port(base, base + 0x400,
136 child->irq, PARPORT_DMA_NOFIFO,
137 child->bus->self))
138 count++;
139 }
140 }
141
142 return count;
143}
144
145static int parport_pc_find_nonpci_ports (int autoirq, int autodma)
146{
147 struct linux_ebus *ebus;
148 struct linux_ebus_device *edev;
149 int count = 0;
150
151 for_each_ebus(ebus) {
152 for_each_ebusdev(edev, ebus) {
153 if (ebus_ecpp_p(edev)) {
154 unsigned long base = edev->resource[0].start;
155 unsigned long config = edev->resource[1].start;
156 unsigned long d_base = edev->resource[2].start;
157 unsigned long d_len;
158
159 spin_lock_init(&sparc_ebus_dmas[count].info.lock);
160 d_len = (edev->resource[2].end -
161 d_base) + 1;
162 sparc_ebus_dmas[count].info.regs =
163 ioremap(d_base, d_len);
164 if (!sparc_ebus_dmas[count].info.regs)
165 continue;
166 sparc_ebus_dmas[count].info.flags = 0;
167 sparc_ebus_dmas[count].info.callback = NULL;
168 sparc_ebus_dmas[count].info.client_cookie = NULL;
169 sparc_ebus_dmas[count].info.irq = 0xdeadbeef;
170 strcpy(sparc_ebus_dmas[count].info.name, "parport");
171 if (ebus_dma_register(&sparc_ebus_dmas[count].info))
172 continue;
173 ebus_dma_irq_enable(&sparc_ebus_dmas[count].info, 1);
174
175 /* Configure IRQ to Push Pull, Level Low */
176 /* Enable ECP, set bit 2 of the CTR first */
177 outb(0x04, base + 0x02);
178 ns87303_modify(config, PCR,
179 PCR_EPP_ENABLE |
180 PCR_IRQ_ODRAIN,
181 PCR_ECP_ENABLE |
182 PCR_ECP_CLK_ENA |
183 PCR_IRQ_POLAR);
184
185 /* CTR bit 5 controls direction of port */
186 ns87303_modify(config, PTR,
187 0, PTR_LPT_REG_DIR);
188
189 if (parport_pc_probe_port(base, base + 0x400,
190 edev->irqs[0],
191 count, ebus->self))
192 count++;
193 }
194 }
195 }
196
197 count = parport_isa_probe(count);
198
199 return count;
200}
201
202#endif /* !(_ASM_SPARC64_PARPORT_H */