2 * linux/arch/sh/boards/systemh/io.c
4 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
5 * Based largely on io_se.c.
7 * I/O routine for Hitachi 7751 Systemh.
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <asm/systemh/7751systemh.h>
14 #include <asm/addrspace.h>
17 #include <linux/pci.h>
18 #include "../../drivers/pci/pci-sh7751.h"
21 * The 7751 SystemH Engine uses the built-in PCI controller (PCIC)
22 * of the 7751 processor, and has a SuperIO accessible on its memory
26 #define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR)
27 #define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR)
28 #define PCI_IO_AREA SH7751_PCI_IO_BASE
29 #define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE
31 #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
32 #define ETHER_IOMAP(adr) (0xB3000000 + (adr)) /*map to 16bits access area
35 #define maybebadio(name,port) \
36 printk("bad PC-like io %s for port 0x%lx at 0x%08x\n", \
37 #name, (port), (__u32) __builtin_return_address(0))
39 static inline void delay(void)
44 static inline volatile __u16
*
45 port2adr(unsigned int port
)
48 return (volatile __u16
*) (PA_MRSHPC
+ (port
- 0x2000));
51 return (volatile __u16
*) (PA_SUPERIO
+ (port
<< 1));
53 maybebadio(name
,(unsigned long)port
);
54 return (volatile __u16
*)port
;
57 /* In case someone configures the kernel w/o PCI support: in that */
58 /* scenario, don't ever bother to check for PCI-window addresses */
60 /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
61 #if defined(CONFIG_PCI)
62 #define CHECK_SH7751_PCIIO(port) \
63 ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
65 #define CHECK_SH7751_PCIIO(port) (0)
69 * General outline: remap really low stuff [eventually] to SuperIO,
70 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
71 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
72 * should be way beyond the window, and is used w/o translation for
75 unsigned char sh7751systemh_inb(unsigned long port
)
78 return *(volatile unsigned char *)port
;
79 else if (CHECK_SH7751_PCIIO(port
))
80 return *(volatile unsigned char *)PCI_IOMAP(port
);
81 else if (port
<= 0x3F1)
82 return *(volatile unsigned char *)ETHER_IOMAP(port
);
84 return (*port2adr(port
))&0xff;
87 unsigned char sh7751systemh_inb_p(unsigned long port
)
92 v
= *(volatile unsigned char *)port
;
93 else if (CHECK_SH7751_PCIIO(port
))
94 v
= *(volatile unsigned char *)PCI_IOMAP(port
);
95 else if (port
<= 0x3F1)
96 v
= *(volatile unsigned char *)ETHER_IOMAP(port
);
98 v
= (*port2adr(port
))&0xff;
103 unsigned short sh7751systemh_inw(unsigned long port
)
106 return *(volatile unsigned short *)port
;
107 else if (CHECK_SH7751_PCIIO(port
))
108 return *(volatile unsigned short *)PCI_IOMAP(port
);
109 else if (port
>= 0x2000)
110 return *port2adr(port
);
111 else if (port
<= 0x3F1)
112 return *(volatile unsigned int *)ETHER_IOMAP(port
);
114 maybebadio(inw
, port
);
118 unsigned int sh7751systemh_inl(unsigned long port
)
121 return *(volatile unsigned long *)port
;
122 else if (CHECK_SH7751_PCIIO(port
))
123 return *(volatile unsigned int *)PCI_IOMAP(port
);
124 else if (port
>= 0x2000)
125 return *port2adr(port
);
126 else if (port
<= 0x3F1)
127 return *(volatile unsigned int *)ETHER_IOMAP(port
);
129 maybebadio(inl
, port
);
133 void sh7751systemh_outb(unsigned char value
, unsigned long port
)
137 *(volatile unsigned char *)port
= value
;
138 else if (CHECK_SH7751_PCIIO(port
))
139 *((unsigned char*)PCI_IOMAP(port
)) = value
;
140 else if (port
<= 0x3F1)
141 *(volatile unsigned char *)ETHER_IOMAP(port
) = value
;
143 *(port2adr(port
)) = value
;
146 void sh7751systemh_outb_p(unsigned char value
, unsigned long port
)
149 *(volatile unsigned char *)port
= value
;
150 else if (CHECK_SH7751_PCIIO(port
))
151 *((unsigned char*)PCI_IOMAP(port
)) = value
;
152 else if (port
<= 0x3F1)
153 *(volatile unsigned char *)ETHER_IOMAP(port
) = value
;
155 *(port2adr(port
)) = value
;
159 void sh7751systemh_outw(unsigned short value
, unsigned long port
)
162 *(volatile unsigned short *)port
= value
;
163 else if (CHECK_SH7751_PCIIO(port
))
164 *((unsigned short *)PCI_IOMAP(port
)) = value
;
165 else if (port
>= 0x2000)
166 *port2adr(port
) = value
;
167 else if (port
<= 0x3F1)
168 *(volatile unsigned short *)ETHER_IOMAP(port
) = value
;
170 maybebadio(outw
, port
);
173 void sh7751systemh_outl(unsigned int value
, unsigned long port
)
176 *(volatile unsigned long *)port
= value
;
177 else if (CHECK_SH7751_PCIIO(port
))
178 *((unsigned long*)PCI_IOMAP(port
)) = value
;
180 maybebadio(outl
, port
);
183 void sh7751systemh_insb(unsigned long port
, void *addr
, unsigned long count
)
185 unsigned char *p
= addr
;
186 while (count
--) *p
++ = sh7751systemh_inb(port
);
189 void sh7751systemh_insw(unsigned long port
, void *addr
, unsigned long count
)
191 unsigned short *p
= addr
;
192 while (count
--) *p
++ = sh7751systemh_inw(port
);
195 void sh7751systemh_insl(unsigned long port
, void *addr
, unsigned long count
)
197 maybebadio(insl
, port
);
200 void sh7751systemh_outsb(unsigned long port
, const void *addr
, unsigned long count
)
202 unsigned char *p
= (unsigned char*)addr
;
203 while (count
--) sh7751systemh_outb(*p
++, port
);
206 void sh7751systemh_outsw(unsigned long port
, const void *addr
, unsigned long count
)
208 unsigned short *p
= (unsigned short*)addr
;
209 while (count
--) sh7751systemh_outw(*p
++, port
);
212 void sh7751systemh_outsl(unsigned long port
, const void *addr
, unsigned long count
)
214 maybebadio(outsw
, port
);
217 /* For read/write calls, just copy generic (pass-thru); PCIMBR is */
218 /* already set up. For a larger memory space, these would need to */
219 /* reset PCIMBR as needed on a per-call basis... */
221 unsigned char sh7751systemh_readb(unsigned long addr
)
223 return *(volatile unsigned char*)addr
;
226 unsigned short sh7751systemh_readw(unsigned long addr
)
228 return *(volatile unsigned short*)addr
;
231 unsigned int sh7751systemh_readl(unsigned long addr
)
233 return *(volatile unsigned long*)addr
;
236 void sh7751systemh_writeb(unsigned char b
, unsigned long addr
)
238 *(volatile unsigned char*)addr
= b
;
241 void sh7751systemh_writew(unsigned short b
, unsigned long addr
)
243 *(volatile unsigned short*)addr
= b
;
246 void sh7751systemh_writel(unsigned int b
, unsigned long addr
)
248 *(volatile unsigned long*)addr
= b
;
253 /* Map ISA bus address to the real address. Only for PCMCIA. */
255 /* ISA page descriptor. */
256 static __u32 sh_isa_memmap
[256];
260 sh_isa_mmap(__u32 start
, __u32 length
, __u32 offset
)
264 if (start
>= 0x100000 || (start
& 0xfff) || (length
!= 0x1000))
268 sh_isa_memmap
[idx
] = 0xb8000000 + (offset
&~ 0xfff);
269 printk("sh_isa_mmap: start %x len %x offset %x (idx %x paddr %x)\n",
270 start
, length
, offset
, idx
, sh_isa_memmap
[idx
]);
276 sh7751systemh_isa_port2addr(unsigned long offset
)
280 idx
= (offset
>> 12) & 0xff;
282 return sh_isa_memmap
[idx
] + offset
;