import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / sh / kernel / io_snapgear.c
1 /* 
2  * linux/arch/sh/kernel/io_7751se.c
3  *
4  * Copyright (C) 2002  David McCullough <davidm@snapgear.com>
5  * Copyright (C) 2001  Ian da Silva, Jeremy Siegel
6  * Based largely on io_se.c.
7  *
8  * I/O routine for Hitachi 7751 SolutionEngine.
9  *
10  * Initial version only to support LAN access; some
11  * placeholder code from io_se.c left in with the
12  * expectation of later SuperIO and PCMCIA access.
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/types.h>
17 #include <linux/pci.h>
18 #include <asm/io.h>
19 #include <asm/addrspace.h>
20
21 #include <asm/pci.h>
22 #include <asm/pci-sh7751.h>
23
24 #ifdef CONFIG_SH_SECUREEDGE5410
25 unsigned short secureedge5410_ioport;
26 #endif
27
28 /*
29  * The SnapGear uses the built-in PCI controller (PCIC)
30  * of the 7751 processor
31  */ 
32
33 #define PCIIOBR         (volatile long *)PCI_REG(SH7751_PCIIOBR)
34 #define PCIMBR          (volatile long *)PCI_REG(SH7751_PCIMBR)
35 #define PCI_IO_AREA     SH7751_PCI_IO_BASE
36 #define PCI_MEM_AREA    SH7751_PCI_CONFIG_BASE
37
38
39 #define PCI_IOMAP(adr)  (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
40
41
42 #define maybebadio(name,port) \
43   printk("bad PC-like io %s for port 0x%lx at 0x%08x\n", \
44          #name, (port), (__u32) __builtin_return_address(0))
45
46
47 static inline void delay(void)
48 {
49         ctrl_inw(0xa0000000);
50 }
51
52
53 static inline volatile __u16 *
54 port2adr(unsigned int port)
55 {
56 #if 0
57         if (port >= 0x2000)
58                 return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
59 #endif
60         maybebadio(name,port);
61         return (volatile __u16*)port;
62 }
63
64
65 /* In case someone configures the kernel w/o PCI support: in that */
66 /* scenario, don't ever bother to check for PCI-window addresses */
67
68 /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
69 #if defined(CONFIG_PCI)
70 #define CHECK_SH7751_PCIIO(port) \
71   ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
72 #else
73 #define CHECK_SH7751_PCIIO(port) (0)
74 #endif
75
76 /*
77  * General outline: remap really low stuff [eventually] to SuperIO,
78  * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
79  * is mapped through the PCI IO window.  Stuff with high bits (PXSEG)
80  * should be way beyond the window, and is used  w/o translation for
81  * compatibility.
82  */
83
84 unsigned char snapgear_inb(unsigned long port)
85 {
86         if (PXSEG(port))
87                 return *(volatile unsigned char *)port;
88         else if (CHECK_SH7751_PCIIO(port))
89                 return *(volatile unsigned char *)PCI_IOMAP(port);
90         else
91                 return (*port2adr(port))&0xff; 
92 }
93
94
95 unsigned char snapgear_inb_p(unsigned long port)
96 {
97         unsigned char v;
98
99         if (PXSEG(port))
100                 v = *(volatile unsigned char *)port;
101         else if (CHECK_SH7751_PCIIO(port))
102                 v = *(volatile unsigned char *)PCI_IOMAP(port);
103         else
104                 v = (*port2adr(port))&0xff; 
105         delay();
106         return v;
107 }
108
109
110 unsigned short snapgear_inw(unsigned long port)
111 {
112         if (PXSEG(port))
113                 return *(volatile unsigned short *)port;
114         else if (CHECK_SH7751_PCIIO(port))
115                 return *(volatile unsigned short *)PCI_IOMAP(port);
116         else if (port >= 0x2000)
117                 return *port2adr(port);
118         else
119                 maybebadio(inw, port);
120         return 0;
121 }
122
123
124 unsigned int snapgear_inl(unsigned long port)
125 {
126         if (PXSEG(port))
127                 return *(volatile unsigned long *)port;
128         else if (CHECK_SH7751_PCIIO(port))
129                 return *(volatile unsigned int *)PCI_IOMAP(port);
130         else if (port >= 0x2000)
131                 return *port2adr(port);
132         else
133                 maybebadio(inl, port);
134         return 0;
135 }
136
137
138 void snapgear_outb(unsigned char value, unsigned long port)
139 {
140
141         if (PXSEG(port))
142                 *(volatile unsigned char *)port = value;
143         else if (CHECK_SH7751_PCIIO(port))
144                 *((unsigned char*)PCI_IOMAP(port)) = value;
145         else
146                 *(port2adr(port)) = value;
147 }
148
149
150 void snapgear_outb_p(unsigned char value, unsigned long port)
151 {
152         if (PXSEG(port))
153                 *(volatile unsigned char *)port = value;
154         else if (CHECK_SH7751_PCIIO(port))
155                 *((unsigned char*)PCI_IOMAP(port)) = value;
156         else
157                 *(port2adr(port)) = value;
158         delay();
159 }
160
161
162 void snapgear_outw(unsigned short value, unsigned long port)
163 {
164         if (PXSEG(port))
165                 *(volatile unsigned short *)port = value;
166         else if (CHECK_SH7751_PCIIO(port))
167                 *((unsigned short *)PCI_IOMAP(port)) = value;
168         else if (port >= 0x2000)
169                 *port2adr(port) = value;
170         else
171                 maybebadio(outw, port);
172 }
173
174
175 void snapgear_outl(unsigned int value, unsigned long port)
176 {
177         if (PXSEG(port))
178                 *(volatile unsigned long *)port = value;
179         else if (CHECK_SH7751_PCIIO(port))
180                 *((unsigned long*)PCI_IOMAP(port)) = value;
181         else
182                 maybebadio(outl, port);
183 }
184
185
186 void snapgear_insb(unsigned long port, void *addr, unsigned long count)
187 {
188         unsigned char *p = addr;
189         while (count--) *p++ = snapgear_inb(port);
190 }
191
192
193 void snapgear_insw(unsigned long port, void *addr, unsigned long count)
194 {
195         unsigned short *p = addr;
196         while (count--) *p++ = snapgear_inw(port);
197 }
198
199
200 void snapgear_insl(unsigned long port, void *addr, unsigned long count)
201 {
202         maybebadio(insl, port);
203 }
204
205
206 void snapgear_outsb(unsigned long port, const void *addr, unsigned long count)
207 {
208         unsigned char *p = (unsigned char*)addr;
209         while (count--) snapgear_outb(*p++, port);
210 }
211
212
213 void snapgear_outsw(unsigned long port, const void *addr, unsigned long count)
214 {
215         unsigned short *p = (unsigned short*)addr;
216         while (count--) snapgear_outw(*p++, port);
217 }
218
219
220 void snapgear_outsl(unsigned long port, const void *addr, unsigned long count)
221 {
222         maybebadio(outsw, port);
223 }
224
225
226 /* For read/write calls, just copy generic (pass-thru); PCIMBR is  */
227 /* already set up.  For a larger memory space, these would need to */
228 /* reset PCIMBR as needed on a per-call basis...                   */
229
230 unsigned char snapgear_readb(unsigned long addr)
231 {
232         return (* ((volatile unsigned char *) addr));
233 }
234
235
236 unsigned short snapgear_readw(unsigned long addr)
237 {
238         return (* ((volatile unsigned short *) addr));
239 }
240
241
242 unsigned int snapgear_readl(unsigned long addr)
243 {
244         return (* ((volatile unsigned long *) addr));
245 }
246
247
248 void snapgear_writeb(unsigned char b, unsigned long addr)
249 {
250         *(volatile unsigned char*)addr = b;
251 }
252
253
254 void snapgear_writew(unsigned short b, unsigned long addr)
255 {
256         *(volatile unsigned short*)addr = b;
257 }
258
259
260 void snapgear_writel(unsigned int b, unsigned long addr)
261 {
262         *(volatile unsigned long*)addr = b;
263 }
264
265
266 /* Map ISA bus address to the real address. Only for PCMCIA.  */
267
268
269 /* ISA page descriptor.  */
270 static __u32 sh_isa_memmap[256];
271
272
273 static int
274 sh_isa_mmap(__u32 start, __u32 length, __u32 offset)
275 {
276         int idx;
277
278         if (start >= 0x100000 || (start & 0xfff) || (length != 0x1000))
279                 return -1;
280
281         idx = start >> 12;
282         sh_isa_memmap[idx] = 0xb8000000 + (offset &~ 0xfff);
283 #if 0
284         printk("sh_isa_mmap: start %x len %x offset %x (idx %x paddr %x)\n",
285                start, length, offset, idx, sh_isa_memmap[idx]);
286 #endif
287         return 0;
288 }
289
290
291 unsigned long
292 snapgear_isa_port2addr(unsigned long offset)
293 {
294         int idx;
295
296         idx = (offset >> 12) & 0xff;
297         offset &= 0xfff;
298         return sh_isa_memmap[idx] + offset;
299 }