1
2
3
4
5
6
7
8
9
10
11#include <linux/kernel.h>
12#include <linux/config.h>
13#include <linux/types.h>
14#include <linux/ioport.h>
15#include <linux/pci.h>
16#include <asm/io.h>
17#include <asm/hitachi_hs7729pci.h>
18
19#include "pci-sd0001.h"
20
21#ifdef CONFIG_PCI
22#define io_is_pci(port) (port >= PCIBIOS_MIN_IO)
23#else
24#define io_is_pci(port) (0)
25#endif
26
27
28int sh_pcic_io_wbase = 0xb8400000;
29int sh_pcic_io_start;
30int sh_pcic_io_stop;
31int sh_pcic_io_type;
32int sh_pcic_io_dummy;
33
34static inline void delay(void)
35{
36 ctrl_inw(0xa0000000);
37}
38
39
40
41
42
43static inline volatile __u16 *
44port2adr(unsigned long port)
45{
46 if (port >= 0x2000)
47 return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
48 else if (sh_pcic_io_start <= port && port <= sh_pcic_io_stop)
49 return (volatile __u16 *) (sh_pcic_io_wbase + (port &~ 1));
50
51 else
52 return (volatile __u16 *) (PA_SUPERIO + (port << 1));
53}
54
55static inline int
56shifted_port(unsigned long port)
57{
58
59 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6 ||
60 (0x170 <= port && port < 0x178) || port == 0x376 ||
61 port >= 0x1000)
62 return 0;
63 else
64 return 1;
65}
66
67#define maybebadio(name,port) \
68 printk("bad PC-like io %s for port 0x%lx at 0x%08x\n", \
69 #name, (port), (__u32) __builtin_return_address(0))
70
71
72unsigned char hs7729pci_inb(unsigned long port)
73{
74 if (io_is_pci(port))
75 return sd0001_inb(port);
76 if (sh_pcic_io_start <= port && port <= sh_pcic_io_stop)
77 return *(__u8 *) (sh_pcic_io_wbase + 0x40000 + port);
78 if (shifted_port(port))
79 return (*port2adr(port) >> 8);
80#if defined(CONFIG_CF_ENABLER)
81 else if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
82 return *(__u8 *)(PA_MRSHPC_IO + port + 0x40000);
83#endif
84 else
85 return (*port2adr(port))&0xff;
86}
87
88unsigned char hs7729pci_inb_p(unsigned long port)
89{
90 unsigned long v;
91
92 if (io_is_pci(port))
93 v = sd0001_inb(port);
94 else if (sh_pcic_io_start <= port && port <= sh_pcic_io_stop)
95 v = *(__u8 *) (sh_pcic_io_wbase + 0x40000 + port);
96 else if (shifted_port(port))
97 v = (*port2adr(port) >> 8);
98#if defined(CONFIG_CF_ENABLER)
99 else if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
100 v = *(__u8 *)(PA_MRSHPC_IO + port + 0x40000);
101#endif
102 else
103 v = (*port2adr(port))&0xff;
104 delay();
105 return v;
106}
107
108unsigned short hs7729pci_inw(unsigned long port)
109{
110 if (io_is_pci(port))
111 return sd0001_inw(port);
112 if (port >= 0x2000 ||
113 (sh_pcic_io_start <= port && port <= sh_pcic_io_stop))
114 return *port2adr(port);
115
116 maybebadio(inw, port);
117}
118
119unsigned int hs7729pci_inl(unsigned long port)
120{
121 if (io_is_pci(port))
122 return sd0001_inl(port);
123 else
124 maybebadio(inl, port);
125}
126
127void hs7729pci_outb(unsigned char value, unsigned long port)
128{
129 if (io_is_pci(port))
130 sd0001_outb(value, port);
131 else if (sh_pcic_io_start <= port && port <= sh_pcic_io_stop)
132 *(__u8 *)(sh_pcic_io_wbase + port) = value;
133 else if (shifted_port(port))
134 *(port2adr(port)) = value << 8;
135#if defined(CONFIG_CF_ENABLER)
136 else if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
137 *(__u8 *)(PA_MRSHPC_IO + port + 0x40000) = value;
138#endif
139 else
140 *(port2adr(port)) = value;
141}
142
143void hs7729pci_outb_p(unsigned char value, unsigned long port)
144{
145 if (io_is_pci(port))
146 sd0001_outb(value, port);
147 else if (sh_pcic_io_start <= port && port <= sh_pcic_io_stop)
148 *(__u8 *)(sh_pcic_io_wbase + port) = value;
149 else if (shifted_port(port))
150 *(port2adr(port)) = value << 8;
151#if defined(CONFIG_CF_ENABLER)
152 else if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
153 *(__u8 *)(PA_MRSHPC_IO + port + 0x40000) = value;
154#endif
155 else
156 *(port2adr(port)) = value;
157 delay();
158}
159
160void hs7729pci_outw(unsigned short value, unsigned long port)
161{
162 if (io_is_pci(port))
163 sd0001_outw(value, port);
164 else if (port >= 0x2000 ||
165 (sh_pcic_io_start <= port && port <= sh_pcic_io_stop))
166 *port2adr(port) = value;
167 else
168 maybebadio(outw, port);
169}
170
171void hs7729pci_outl(unsigned int value, unsigned long port)
172{
173 if (io_is_pci(port))
174 sd0001_outl(value, port);
175 else
176 maybebadio(outl, port);
177}
178
179void hs7729pci_insb(unsigned long port, void *addr, unsigned long count)
180{
181 volatile __u16 *p = port2adr(port);
182
183 if (io_is_pci(port))
184 sd0001_insb(port, addr, count);
185 else if (sh_pcic_io_start <= port && port <= sh_pcic_io_stop) {
186 volatile __u8 *bp = (__u8 *) (sh_pcic_io_wbase + 0x40000 + port);
187 while (count--)
188 *((__u8 *) addr)++ = *bp;
189 } else if (shifted_port(port)) {
190 while (count--)
191 *((__u8 *) addr)++ = *p >> 8;
192#if defined(CONFIG_CF_ENABLER)
193 } else if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6) {
194 volatile __u8 *q = (__u8 *)(PA_MRSHPC_IO + port + 0x40000);
195 while (count--) {
196 *((__u8 *) addr)++ = *q;
197 }
198#endif
199 } else {
200 while (count--)
201 *((__u8 *) addr)++ = *p;
202
203 }
204}
205
206void hs7729pci_insw(unsigned long port, void *addr, unsigned long count)
207{
208 volatile __u16 *p;
209
210 if (io_is_pci(port))
211 return sd0001_insw(port, addr, count);
212#if defined(CONFIG_CF_ENABLER)
213 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6) {
214 p = (__u16 *)(PA_MRSHPC_IO + port);
215 } else
216#endif
217 p = port2adr(port);
218 while (count--)
219 *((__u16 *) addr)++ = *p;
220}
221
222void hs7729pci_insl(unsigned long port, void *addr, unsigned long count)
223{
224 if (io_is_pci(port))
225 sd0001_insl(port, addr, count);
226 else
227 maybebadio(insl, port);
228}
229
230void hs7729pci_outsb(unsigned long port, const void *addr, unsigned long count)
231{
232 volatile __u16 *p = port2adr(port);
233
234 if (io_is_pci(port)) {
235 sd0001_outsb(port, addr, count);
236 return;
237 }
238 if (sh_pcic_io_start <= port && port <= sh_pcic_io_stop) {
239 volatile __u8 *bp = (__u8 *) (sh_pcic_io_wbase + port);
240 while (count--)
241 *bp = *((__u8 *) addr)++;
242 } else if (shifted_port(port)) {
243 while (count--)
244 *p = *((__u8 *) addr)++ << 8;
245#if defined(CONFIG_CF_ENABLER)
246 } else if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6) {
247 volatile __u8 *q = (__u8 *)(PA_MRSHPC_IO + port + 0x40000);
248 while (count--) {
249 *q = *((__u8 *) addr)++;
250 }
251#endif
252 } else while (count--)
253 *p = *((__u8 *) addr)++;
254}
255
256void hs7729pci_outsw(unsigned long port, const void *addr, unsigned long count)
257{
258 volatile __u16 *p;
259
260 if (io_is_pci(port)) {
261 sd0001_outsw(port, addr, count);
262 return;
263 }
264#if defined(CONFIG_CF_ENABLER)
265 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6) {
266 p = (__u16 *)(PA_MRSHPC_IO + port);
267 } else
268#endif
269 p = port2adr(port);
270 while (count--)
271 *p = *((__u16 *) addr)++;
272}
273
274void hs7729pci_outsl(unsigned long port, const void *addr, unsigned long count)
275{
276 if (io_is_pci(port))
277 sd0001_outsl(port, addr, count);
278 else
279 maybebadio(outsl, port);
280}
281
282
283
284
285static __u32 sh_isa_memmap[256];
286
287static int
288sh_isa_mmap(__u32 start, __u32 length, __u32 offset)
289{
290 int idx;
291
292 if (start >= 0x100000 || (start & 0xfff) || (length != 0x1000))
293 return -1;
294
295 idx = start >> 12;
296 sh_isa_memmap[idx] = 0xb8000000 + (offset &~ 0xfff);
297#if 0
298 printk("sh_isa_mmap: start %x len %x offset %x (idx %x paddr %x)\n",
299 start, length, offset, idx, sh_isa_memmap[idx]);
300#endif
301 return 0;
302}
303
304unsigned long
305hs7729pci_isa_port2addr(unsigned long offset)
306{
307 int idx;
308
309 idx = (offset >> 12) & 0xff;
310 offset &= 0xfff;
311 return sh_isa_memmap[idx] + offset;
312}
313
314void *hs7729pci_ioremap(unsigned long phys_addr, unsigned long size)
315{
316
317 if (!size || (phys_addr + size - 1) < phys_addr)
318 return NULL;
319
320#ifdef CONFIG_PCI
321 if (phys_addr >= PCIBIOS_MIN_MEM &&
322 phys_addr < (PCIBIOS_MIN_MEM&0xfc000000)+0x03000000)
323 return sd0001_ioremap(phys_addr, size);
324#endif
325 return (void *) P2SEGADDR(phys_addr);
326}
327
328void hs7729pci_iounmap(void *addr)
329{
330#ifdef CONFIG_PCI
331
332
333 if ((unsigned long)addr >= VMALLOC_START &&
334 (unsigned long)addr < VMALLOC_END)
335 sd0001_iounmap(addr);
336#endif
337}
338
339