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 *area6_io8_base; /* Area 6 8bit I/O Base address */
25 extern void *area5_io16_base; /* Area 5 16bit I/O Base address */
28 * The 7751R HS7751RVoIP uses the built-in PCI controller (PCIC)
29 * of the 7751R processor, and has a SuperIO accessible via the PCI.
30 * The board also includes a PCMCIA controller on its memory bus,
31 * like the other Solution Engine boards.
34 #define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR)
35 #define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR)
36 #define PCI_IO_AREA SH7751_PCI_IO_BASE
37 #define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE
38 #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
40 #define CODEC_IO_BASE 0x1000
41 #define CODEC_IOMAP(a) ((unsigned long)area6_io8_base + ((a) - CODEC_IO_BASE))
43 static inline void delay(void)
48 static inline unsigned long port2adr(unsigned int port)
50 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
52 return ((unsigned long)area5_io16_base + 0x0c);
54 return ((unsigned long)area5_io16_base + 0x800 + ((port-0x1f0) << 1));
56 maybebadio((unsigned long)port);
60 /* The 7751R HS7751RVoIP seems to have everything hooked */
61 /* up pretty normally (nothing on high-bytes only...) so this */
62 /* shouldn't be needed */
63 static inline int shifted_port(unsigned long port)
65 /* For IDE registers, value is not shifted */
66 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
72 #if defined(CONFIG_HS7751RVOIP_CODEC)
74 codec_port(unsigned long port)
76 if (CODEC_IO_BASE <= port && port < (CODEC_IO_BASE+0x20))
83 /* In case someone configures the kernel w/o PCI support: in that */
84 /* scenario, don't ever bother to check for PCI-window addresses */
86 /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
87 #if defined(CONFIG_PCI)
88 #define CHECK_SH7751_PCIIO(port) \
89 ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
91 #define CHECK_SH7751_PCIIO(port) (0)
95 * General outline: remap really low stuff [eventually] to SuperIO,
96 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
97 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
98 * should be way beyond the window, and is used w/o translation for
101 unsigned char hs7751rvoip_inb(unsigned long port)
104 return ctrl_inb(port);
105 #if defined(CONFIG_HS7751RVOIP_CODEC)
106 else if (codec_port(port))
107 return ctrl_inb(CODEC_IOMAP(port));
109 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
110 return ctrl_inb(PCI_IOMAP(port));
112 return ctrl_inw(port2adr(port)) & 0xff;
115 unsigned char hs7751rvoip_inb_p(unsigned long port)
121 #if defined(CONFIG_HS7751RVOIP_CODEC)
122 else if (codec_port(port))
123 v = ctrl_inb(CODEC_IOMAP(port));
125 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
126 v = ctrl_inb(PCI_IOMAP(port));
128 v = ctrl_inw(port2adr(port)) & 0xff;
133 unsigned short hs7751rvoip_inw(unsigned long port)
136 return ctrl_inw(port);
137 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
138 return ctrl_inw(PCI_IOMAP(port));
144 unsigned int hs7751rvoip_inl(unsigned long port)
147 return ctrl_inl(port);
148 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
149 return ctrl_inl(PCI_IOMAP(port));
155 void hs7751rvoip_outb(unsigned char value, unsigned long port)
159 ctrl_outb(value, port);
160 #if defined(CONFIG_HS7751RVOIP_CODEC)
161 else if (codec_port(port))
162 ctrl_outb(value, CODEC_IOMAP(port));
164 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
165 ctrl_outb(value, PCI_IOMAP(port));
167 ctrl_outb(value, port2adr(port));
170 void hs7751rvoip_outb_p(unsigned char value, unsigned long port)
173 ctrl_outb(value, port);
174 #if defined(CONFIG_HS7751RVOIP_CODEC)
175 else if (codec_port(port))
176 ctrl_outb(value, CODEC_IOMAP(port));
178 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
179 ctrl_outb(value, PCI_IOMAP(port));
181 ctrl_outw(value, port2adr(port));
186 void hs7751rvoip_outw(unsigned short value, unsigned long port)
189 ctrl_outw(value, port);
190 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
191 ctrl_outw(value, PCI_IOMAP(port));
196 void hs7751rvoip_outl(unsigned int value, unsigned long port)
199 ctrl_outl(value, port);
200 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
201 ctrl_outl(value, PCI_IOMAP(port));
206 void hs7751rvoip_insb(unsigned long port, void *addr, unsigned long count)
212 *buf++ = ctrl_inb(port);
213 #if defined(CONFIG_HS7751RVOIP_CODEC)
214 else if (codec_port(port))
216 *buf++ = ctrl_inb(CODEC_IOMAP(port));
218 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
219 volatile u8 *bp = (volatile u8 *)PCI_IOMAP(port);
224 volatile u16 *p = (volatile u16 *)port2adr(port);
231 void hs7751rvoip_insw(unsigned long port, void *addr, unsigned long count)
237 p = (volatile u16 *)port;
238 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
239 p = (volatile u16 *)PCI_IOMAP(port);
241 p = (volatile u16 *)port2adr(port);
246 void hs7751rvoip_insl(unsigned long port, void *addr, unsigned long count)
249 if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
250 volatile u32 *p = (volatile u32 *)PCI_IOMAP(port);
259 void hs7751rvoip_outsb(unsigned long port, const void *addr, unsigned long count)
261 const u8 *buf = addr;
265 ctrl_outb(*buf++, port);
266 #if defined(CONFIG_HS7751RVOIP_CODEC)
267 else if (codec_port(port))
269 ctrl_outb(*buf++, CODEC_IOMAP(port));
271 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
272 volatile u8 *bp = (volatile u8 *)PCI_IOMAP(port);
277 volatile u16 *p = (volatile u16 *)port2adr(port);
284 void hs7751rvoip_outsw(unsigned long port, const void *addr, unsigned long count)
287 const u16 *buf = addr;
290 p = (volatile u16 *)port;
291 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port))
292 p = (volatile u16 *)PCI_IOMAP(port);
294 p = (volatile u16 *)port2adr(port);
300 void hs7751rvoip_outsl(unsigned long port, const void *addr, unsigned long count)
302 const u32 *buf = addr;
304 if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
305 volatile u32 *p = (volatile u32 *)PCI_IOMAP(port);
313 void __iomem *hs7751rvoip_ioport_map(unsigned long port, unsigned int size)
316 return (void __iomem *)port;
317 else if (unlikely(codec_port(port) && (size == 1)))
318 return (void __iomem *)CODEC_IOMAP(port);
319 else if (CHECK_SH7751_PCIIO(port))
320 return (void __iomem *)PCI_IOMAP(port);
322 return (void __iomem *)port2adr(port);