2 * linux/arch/sh/kernel/io_hs7751rvoip.c
4 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
5 * Based largely on io_se.c.
7 * I/O routine for Renesas Technology sales HS7751RVoIP
9 * Initial version only to support LAN access; some
10 * placeholder code from io_hs7751rvoip.c left in with the
11 * expectation of later SuperIO and PCMCIA access.
14 #include <linux/kernel.h>
15 #include <linux/types.h>
17 #include <asm/hs7751rvoip/hs7751rvoip.h>
18 #include <asm/addrspace.h>
20 #include <linux/module.h>
21 #include <linux/pci.h>
22 #include "../../../drivers/pci/pci-sh7751.h"
24 extern void *area5_io8_base; /* Area 5 8bit I/O Base address */
25 extern void *area6_io8_base; /* Area 6 8bit I/O Base address */
26 extern void *area5_io16_base; /* Area 5 16bit I/O Base address */
27 extern void *area6_io16_base; /* Area 6 16bit I/O Base address */
30 * The 7751R HS7751RVoIP uses the built-in PCI controller (PCIC)
31 * of the 7751R processor, and has a SuperIO accessible via the PCI.
32 * The board also includes a PCMCIA controller on its memory bus,
33 * like the other Solution Engine boards.
36 #define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR)
37 #define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR)
38 #define PCI_IO_AREA SH7751_PCI_IO_BASE
39 #define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE
41 #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
43 #if defined(CONFIG_HS7751RVOIP_CODEC)
44 #define CODEC_IO_BASE 0x1000
47 #define maybebadio(name,port) \
48 printk("bad PC-like io %s for port 0x%lx at 0x%08x\n", \
49 #name, (port), (__u32) __builtin_return_address(0))
51 static inline void delay(void)
56 static inline unsigned long port2adr(unsigned int port)
58 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
60 return ((unsigned long)area5_io16_base + 0x0c);
62 return ((unsigned long)area5_io16_base + 0x800 + ((port-0x1f0) << 1));
64 maybebadio(port2adr, (unsigned long)port);
68 /* The 7751R HS7751RVoIP seems to have everything hooked */
69 /* up pretty normally (nothing on high-bytes only...) so this */
70 /* shouldn't be needed */
71 static inline int shifted_port(unsigned long port)
73 /* For IDE registers, value is not shifted */
74 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
80 #if defined(CONFIG_HS7751RVOIP_CODEC)
82 codec_port(unsigned long port)
84 if (CODEC_IO_BASE <= port && port < (CODEC_IO_BASE+0x20))
91 /* In case someone configures the kernel w/o PCI support: in that */
92 /* scenario, don't ever bother to check for PCI-window addresses */
94 /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
95 #if defined(CONFIG_PCI)
96 #define CHECK_SH7751_PCIIO(port) \
97 ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
99 #define CHECK_SH7751_PCIIO(port) (0)
103 * General outline: remap really low stuff [eventually] to SuperIO,
104 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
105 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
106 * should be way beyond the window, and is used w/o translation for
109 unsigned char hs7751rvoip_inb(unsigned long port)
112 return *(volatile unsigned char *)port;
113 #if defined(CONFIG_HS7751RVOIP_CODEC)
114 else if (codec_port(port))
115 return *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE));
117 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
118 return *(volatile unsigned char *)PCI_IOMAP(port);
120 return (*(volatile unsigned short *)port2adr(port) & 0xff);
123 unsigned char hs7751rvoip_inb_p(unsigned long port)
128 v = *(volatile unsigned char *)port;
129 #if defined(CONFIG_HS7751RVOIP_CODEC)
130 else if (codec_port(port))
131 v = *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE));
133 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
134 v = *(volatile unsigned char *)PCI_IOMAP(port);
136 v = (*(volatile unsigned short *)port2adr(port) & 0xff);
141 unsigned short hs7751rvoip_inw(unsigned long port)
144 return *(volatile unsigned short *)port;
145 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
146 return *(volatile unsigned short *)PCI_IOMAP(port);
148 maybebadio(inw, port);
152 unsigned int hs7751rvoip_inl(unsigned long port)
155 return *(volatile unsigned long *)port;
156 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
157 return *(volatile unsigned long *)PCI_IOMAP(port);
159 maybebadio(inl, port);
163 void hs7751rvoip_outb(unsigned char value, unsigned long port)
167 *(volatile unsigned char *)port = value;
168 #if defined(CONFIG_HS7751RVOIP_CODEC)
169 else if (codec_port(port))
170 *(volatile unsigned cjar *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)) = value;
172 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
173 *(unsigned char *)PCI_IOMAP(port) = value;
175 *(volatile unsigned short *)port2adr(port) = value;
178 void hs7751rvoip_outb_p(unsigned char value, unsigned long port)
181 *(volatile unsigned char *)port = value;
182 #if defined(CONFIG_HS7751RVOIP_CODEC)
183 else if (codec_port(port))
184 *(volatile unsigned cjar *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)) = value;
186 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
187 *(unsigned char *)PCI_IOMAP(port) = value;
189 *(volatile unsigned short *)port2adr(port) = value;
193 void hs7751rvoip_outw(unsigned short value, unsigned long port)
196 *(volatile unsigned short *)port = value;
197 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
198 *(unsigned short *)PCI_IOMAP(port) = value;
200 maybebadio(outw, port);
203 void hs7751rvoip_outl(unsigned int value, unsigned long port)
206 *(volatile unsigned long *)port = value;
207 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
208 *((unsigned long *)PCI_IOMAP(port)) = value;
210 maybebadio(outl, port);
213 void hs7751rvoip_insb(unsigned long port, void *addr, unsigned long count)
216 while (count--) *((unsigned char *) addr)++ = *(volatile unsigned char *)port;
217 #if defined(CONFIG_HS7751RVOIP_CODEC)
218 else if (codec_port(port))
219 while (count--) *((unsigned char *) addr)++ = *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE));
221 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
222 volatile __u8 *bp = (__u8 *)PCI_IOMAP(port);
224 while (count--) *((volatile unsigned char *) addr)++ = *bp;
226 volatile __u16 *p = (volatile unsigned short *)port2adr(port);
228 while (count--) *((unsigned char *) addr)++ = *p & 0xff;
232 void hs7751rvoip_insw(unsigned long port, void *addr, unsigned long count)
237 p = (volatile unsigned short *)port;
238 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
239 p = (volatile unsigned short *)PCI_IOMAP(port);
241 p = (volatile unsigned short *)port2adr(port);
242 while (count--) *((__u16 *) addr)++ = *p;
245 void hs7751rvoip_insl(unsigned long port, void *addr, unsigned long count)
247 if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
248 volatile __u32 *p = (__u32 *)PCI_IOMAP(port);
250 while (count--) *((__u32 *) addr)++ = *p;
252 maybebadio(insl, port);
255 void hs7751rvoip_outsb(unsigned long port, const void *addr, unsigned long count)
258 while (count--) *(volatile unsigned char *)port = *((unsigned char *) addr)++;
259 #if defined(CONFIG_HS7751RVOIP_CODEC)
260 else if (codec_port(port))
261 while (count--) *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)) = *((unsigned char *) addr)++;
263 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
264 volatile __u8 *bp = (__u8 *)PCI_IOMAP(port);
266 while (count--) *bp = *((volatile unsigned char *) addr)++;
268 volatile __u16 *p = (volatile unsigned short *)port2adr(port);
270 while (count--) *p = *((unsigned char *) addr)++;
274 void hs7751rvoip_outsw(unsigned long port, const void *addr, unsigned long count)
279 p = (volatile unsigned short *)port;
280 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
281 p = (volatile unsigned short *)PCI_IOMAP(port);
283 p = (volatile unsigned short *)port2adr(port);
284 while (count--) *p = *((__u16 *) addr)++;
287 void hs7751rvoip_outsl(unsigned long port, const void *addr, unsigned long count)
289 if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
290 volatile __u32 *p = (__u32 *)PCI_IOMAP(port);
292 while (count--) *p = *((__u32 *) addr)++;
294 maybebadio(outsl, port);
297 void *hs7751rvoip_ioremap(unsigned long offset, unsigned long size)
299 if (offset >= 0xfd000000)
300 return (void *)offset;
302 return (void *)P2SEGADDR(offset);
304 EXPORT_SYMBOL(hs7751rvoip_ioremap);
306 unsigned long hs7751rvoip_isa_port2addr(unsigned long offset)
308 return port2adr(offset);