[SPARC64]: Fix enable_dma() in asm-sparc64/parport.h
[linux-2.6.git] / include / asm-sparc64 / parport.h
1 /* $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
16 /*
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
22 static struct sparc_ebus_info {
23         struct ebus_dma_info info;
24         unsigned int addr;
25         unsigned int count;
26 } sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
27
28 static __inline__ void enable_dma(unsigned int dmanr)
29 {
30         ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
31
32         if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
33                              sparc_ebus_dmas[dmanr].addr,
34                              sparc_ebus_dmas[dmanr].count))
35                 BUG();
36 }
37
38 static __inline__ void disable_dma(unsigned int dmanr)
39 {
40         ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
41 }
42
43 static __inline__ void clear_dma_ff(unsigned int dmanr)
44 {
45         /* nothing */
46 }
47
48 static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
49 {
50         ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
51 }
52
53 static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int addr)
54 {
55         sparc_ebus_dmas[dmanr].addr = addr;
56 }
57
58 static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
59 {
60         sparc_ebus_dmas[dmanr].count = count;
61 }
62
63 static __inline__ unsigned int get_dma_residue(unsigned int dmanr)
64 {
65         return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
66 }
67
68 static int ebus_ecpp_p(struct linux_ebus_device *edev)
69 {
70         if (!strcmp(edev->prom_name, "ecpp"))
71                 return 1;
72         if (!strcmp(edev->prom_name, "parallel")) {
73                 char compat[19];
74                 prom_getstring(edev->prom_node,
75                                "compatible",
76                                compat, sizeof(compat));
77                 compat[18] = '\0';
78                 if (!strcmp(compat, "ecpp"))
79                         return 1;
80                 if (!strcmp(compat, "ns87317-ecpp") &&
81                     !strcmp(compat + 13, "ecpp"))
82                         return 1;
83         }
84         return 0;
85 }
86
87 static int parport_isa_probe(int count)
88 {
89         struct sparc_isa_bridge *isa_br;
90         struct sparc_isa_device *isa_dev;
91
92         for_each_isa(isa_br) {
93                 for_each_isadev(isa_dev, isa_br) {
94                         struct sparc_isa_device *child;
95                         unsigned long base;
96
97                         if (strcmp(isa_dev->prom_name, "dma"))
98                                 continue;
99
100                         child = isa_dev->child;
101                         while (child) {
102                                 if (!strcmp(child->prom_name, "parallel"))
103                                         break;
104                                 child = child->next;
105                         }
106                         if (!child)
107                                 continue;
108
109                         base = child->resource.start;
110
111                         /* No DMA, see commentary in
112                          * asm-sparc64/floppy.h:isa_floppy_init()
113                          */
114                         if (parport_pc_probe_port(base, base + 0x400,
115                                                   child->irq, PARPORT_DMA_NOFIFO,
116                                                   child->bus->self))
117                                 count++;
118                 }
119         }
120
121         return count;
122 }
123
124 static int parport_pc_find_nonpci_ports (int autoirq, int autodma)
125 {
126         struct linux_ebus *ebus;
127         struct linux_ebus_device *edev;
128         int count = 0;
129
130         for_each_ebus(ebus) {
131                 for_each_ebusdev(edev, ebus) {
132                         if (ebus_ecpp_p(edev)) {
133                                 unsigned long base = edev->resource[0].start;
134                                 unsigned long config = edev->resource[1].start;
135                                 unsigned long d_base = edev->resource[2].start;
136                                 unsigned long d_len;
137
138                                 spin_lock_init(&sparc_ebus_dmas[count].info.lock);
139                                 d_len = (edev->resource[2].end -
140                                          d_base) + 1;
141                                 sparc_ebus_dmas[count].info.regs =
142                                         ioremap(d_base, d_len);
143                                 if (!sparc_ebus_dmas[count].info.regs)
144                                         continue;
145                                 sparc_ebus_dmas[count].info.flags = 0;
146                                 sparc_ebus_dmas[count].info.callback = NULL;
147                                 sparc_ebus_dmas[count].info.client_cookie = NULL;
148                                 sparc_ebus_dmas[count].info.irq = 0xdeadbeef;
149                                 strcpy(sparc_ebus_dmas[count].info.name, "parport");
150                                 if (ebus_dma_register(&sparc_ebus_dmas[count].info))
151                                         continue;
152                                 ebus_dma_irq_enable(&sparc_ebus_dmas[count].info, 1);
153
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,
158                                                PCR_EPP_ENABLE |
159                                                PCR_IRQ_ODRAIN,
160                                                PCR_ECP_ENABLE |
161                                                PCR_ECP_CLK_ENA |
162                                                PCR_IRQ_POLAR);
163
164                                 /* CTR bit 5 controls direction of port */
165                                 ns87303_modify(config, PTR,
166                                                0, PTR_LPT_REG_DIR);
167
168                                 if (parport_pc_probe_port(base, base + 0x400,
169                                                           edev->irqs[0],
170                                                           count, ebus->self))
171                                         count++;
172                         }
173                 }
174         }
175
176         count = parport_isa_probe(count);
177
178         return count;
179 }
180
181 #endif /* !(_ASM_SPARC64_PARPORT_H */