blob: 9ea1136b219b2ca9fa78cbbeda1d2127aa237fb3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/sh/kernel/io_hs7751rvoip.c
3 *
4 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
5 * Based largely on io_se.c.
6 *
7 * I/O routine for Renesas Technology sales HS7751RVoIP
8 *
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.
12 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/kernel.h>
14#include <linux/types.h>
Paul Mundt959f85f2006-09-27 16:43:28 +090015#include <linux/module.h>
Paul Mundte5723e02006-09-27 17:38:11 +090016#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/io.h>
18#include <asm/hs7751rvoip/hs7751rvoip.h>
19#include <asm/addrspace.h>
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021extern void *area6_io8_base; /* Area 6 8bit I/O Base address */
22extern void *area5_io16_base; /* Area 5 16bit I/O Base address */
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24/*
25 * The 7751R HS7751RVoIP uses the built-in PCI controller (PCIC)
26 * of the 7751R processor, and has a SuperIO accessible via the PCI.
27 * The board also includes a PCMCIA controller on its memory bus,
28 * like the other Solution Engine boards.
29 */
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#define CODEC_IO_BASE 0x1000
Paul Mundt373e68b2006-09-27 15:41:24 +090032#define CODEC_IOMAP(a) ((unsigned long)area6_io8_base + ((a) - CODEC_IO_BASE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Linus Torvalds1da177e2005-04-16 15:20:36 -070034static inline unsigned long port2adr(unsigned int port)
35{
36 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
37 if (port == 0x3f6)
38 return ((unsigned long)area5_io16_base + 0x0c);
39 else
Paul Mundt959f85f2006-09-27 16:43:28 +090040 return ((unsigned long)area5_io16_base + 0x800 +
41 ((port-0x1f0) << 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 else
Paul Mundt373e68b2006-09-27 15:41:24 +090043 maybebadio((unsigned long)port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 return port;
45}
46
47/* The 7751R HS7751RVoIP seems to have everything hooked */
48/* up pretty normally (nothing on high-bytes only...) so this */
49/* shouldn't be needed */
50static inline int shifted_port(unsigned long port)
51{
52 /* For IDE registers, value is not shifted */
53 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
54 return 0;
55 else
56 return 1;
57}
58
59#if defined(CONFIG_HS7751RVOIP_CODEC)
Paul Mundt959f85f2006-09-27 16:43:28 +090060#define codec_port(port) \
61 ((CODEC_IO_BASE <= (port)) && ((port) < (CODEC_IO_BASE + 0x20)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#else
Paul Mundt959f85f2006-09-27 16:43:28 +090063#define codec_port(port) (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#endif
65
66/*
67 * General outline: remap really low stuff [eventually] to SuperIO,
68 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
69 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
70 * should be way beyond the window, and is used w/o translation for
71 * compatibility.
72 */
73unsigned char hs7751rvoip_inb(unsigned long port)
74{
75 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +090076 return ctrl_inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 else if (codec_port(port))
Paul Mundt373e68b2006-09-27 15:41:24 +090078 return ctrl_inb(CODEC_IOMAP(port));
Paul Mundt959f85f2006-09-27 16:43:28 +090079 else if (is_pci_ioaddr(port) || shifted_port(port))
80 return ctrl_inb(pci_ioaddr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 else
Paul Mundt373e68b2006-09-27 15:41:24 +090082 return ctrl_inw(port2adr(port)) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
85unsigned char hs7751rvoip_inb_p(unsigned long port)
86{
87 unsigned char v;
88
89 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +090090 v = ctrl_inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 else if (codec_port(port))
Paul Mundt373e68b2006-09-27 15:41:24 +090092 v = ctrl_inb(CODEC_IOMAP(port));
Paul Mundt959f85f2006-09-27 16:43:28 +090093 else if (is_pci_ioaddr(port) || shifted_port(port))
94 v = ctrl_inb(pci_ioaddr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 else
Paul Mundt373e68b2006-09-27 15:41:24 +090096 v = ctrl_inw(port2adr(port)) & 0xff;
Paul Mundt959f85f2006-09-27 16:43:28 +090097 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return v;
99}
100
101unsigned short hs7751rvoip_inw(unsigned long port)
102{
103 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900104 return ctrl_inw(port);
Paul Mundt959f85f2006-09-27 16:43:28 +0900105 else if (is_pci_ioaddr(port) || shifted_port(port))
106 return ctrl_inw(pci_ioaddr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900108 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 return 0;
110}
111
112unsigned int hs7751rvoip_inl(unsigned long port)
113{
114 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900115 return ctrl_inl(port);
Paul Mundt959f85f2006-09-27 16:43:28 +0900116 else if (is_pci_ioaddr(port) || shifted_port(port))
117 return ctrl_inl(pci_ioaddr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900119 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return 0;
121}
122
123void hs7751rvoip_outb(unsigned char value, unsigned long port)
124{
125
126 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900127 ctrl_outb(value, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 else if (codec_port(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900129 ctrl_outb(value, CODEC_IOMAP(port));
Paul Mundt959f85f2006-09-27 16:43:28 +0900130 else if (is_pci_ioaddr(port) || shifted_port(port))
131 ctrl_outb(value, pci_ioaddr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900133 ctrl_outb(value, port2adr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
136void hs7751rvoip_outb_p(unsigned char value, unsigned long port)
137{
138 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900139 ctrl_outb(value, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 else if (codec_port(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900141 ctrl_outb(value, CODEC_IOMAP(port));
Paul Mundt959f85f2006-09-27 16:43:28 +0900142 else if (is_pci_ioaddr(port) || shifted_port(port))
143 ctrl_outb(value, pci_ioaddr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900145 ctrl_outw(value, port2adr(port));
146
Paul Mundt959f85f2006-09-27 16:43:28 +0900147 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
150void hs7751rvoip_outw(unsigned short value, unsigned long port)
151{
152 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900153 ctrl_outw(value, port);
Paul Mundt959f85f2006-09-27 16:43:28 +0900154 else if (is_pci_ioaddr(port) || shifted_port(port))
155 ctrl_outw(value, pci_ioaddr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900157 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
160void hs7751rvoip_outl(unsigned int value, unsigned long port)
161{
162 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900163 ctrl_outl(value, port);
Paul Mundt959f85f2006-09-27 16:43:28 +0900164 else if (is_pci_ioaddr(port) || shifted_port(port))
165 ctrl_outl(value, pci_ioaddr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900167 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
170void hs7751rvoip_insb(unsigned long port, void *addr, unsigned long count)
171{
Paul Mundt373e68b2006-09-27 15:41:24 +0900172 u8 *buf = addr;
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900175 while (count--)
176 *buf++ = ctrl_inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 else if (codec_port(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900178 while (count--)
179 *buf++ = ctrl_inb(CODEC_IOMAP(port));
Paul Mundt959f85f2006-09-27 16:43:28 +0900180 else if (is_pci_ioaddr(port) || shifted_port(port)) {
181 volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Paul Mundt373e68b2006-09-27 15:41:24 +0900183 while (count--)
184 *buf++ = *bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 } else {
Paul Mundt373e68b2006-09-27 15:41:24 +0900186 volatile u16 *p = (volatile u16 *)port2adr(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Paul Mundt373e68b2006-09-27 15:41:24 +0900188 while (count--)
189 *buf++ = *p & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 }
191}
192
193void hs7751rvoip_insw(unsigned long port, void *addr, unsigned long count)
194{
Paul Mundt373e68b2006-09-27 15:41:24 +0900195 volatile u16 *p;
196 u16 *buf = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900199 p = (volatile u16 *)port;
Paul Mundt959f85f2006-09-27 16:43:28 +0900200 else if (is_pci_ioaddr(port) || shifted_port(port))
201 p = (volatile u16 *)pci_ioaddr(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900203 p = (volatile u16 *)port2adr(port);
204 while (count--)
205 *buf++ = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
207
208void hs7751rvoip_insl(unsigned long port, void *addr, unsigned long count)
209{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Paul Mundt959f85f2006-09-27 16:43:28 +0900211 if (is_pci_ioaddr(port) || shifted_port(port)) {
212 volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
Paul Mundt373e68b2006-09-27 15:41:24 +0900213 u32 *buf = addr;
214
215 while (count--)
216 *buf++ = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 } else
Paul Mundt373e68b2006-09-27 15:41:24 +0900218 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
221void hs7751rvoip_outsb(unsigned long port, const void *addr, unsigned long count)
222{
Paul Mundt373e68b2006-09-27 15:41:24 +0900223 const u8 *buf = addr;
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900226 while (count--)
227 ctrl_outb(*buf++, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 else if (codec_port(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900229 while (count--)
230 ctrl_outb(*buf++, CODEC_IOMAP(port));
Paul Mundt959f85f2006-09-27 16:43:28 +0900231 else if (is_pci_ioaddr(port) || shifted_port(port)) {
232 volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Paul Mundt373e68b2006-09-27 15:41:24 +0900234 while (count--)
235 *bp = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 } else {
Paul Mundt373e68b2006-09-27 15:41:24 +0900237 volatile u16 *p = (volatile u16 *)port2adr(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Paul Mundt373e68b2006-09-27 15:41:24 +0900239 while (count--)
240 *p = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
242}
243
244void hs7751rvoip_outsw(unsigned long port, const void *addr, unsigned long count)
245{
Paul Mundt373e68b2006-09-27 15:41:24 +0900246 volatile u16 *p;
247 const u16 *buf = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 if (PXSEG(port))
Paul Mundt373e68b2006-09-27 15:41:24 +0900250 p = (volatile u16 *)port;
Paul Mundt959f85f2006-09-27 16:43:28 +0900251 else if (is_pci_ioaddr(port) || shifted_port(port))
252 p = (volatile u16 *)pci_ioaddr(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900254 p = (volatile u16 *)port2adr(port);
255
256 while (count--)
257 *p = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258}
259
260void hs7751rvoip_outsl(unsigned long port, const void *addr, unsigned long count)
261{
Paul Mundt373e68b2006-09-27 15:41:24 +0900262 const u32 *buf = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Paul Mundt959f85f2006-09-27 16:43:28 +0900264 if (is_pci_ioaddr(port) || shifted_port(port)) {
265 volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
Paul Mundt373e68b2006-09-27 15:41:24 +0900266
267 while (count--)
268 *p = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 } else
Paul Mundt373e68b2006-09-27 15:41:24 +0900270 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271}
272
Paul Mundt373e68b2006-09-27 15:41:24 +0900273void __iomem *hs7751rvoip_ioport_map(unsigned long port, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Paul Mundt373e68b2006-09-27 15:41:24 +0900275 if (PXSEG(port))
276 return (void __iomem *)port;
277 else if (unlikely(codec_port(port) && (size == 1)))
278 return (void __iomem *)CODEC_IOMAP(port);
Paul Mundt959f85f2006-09-27 16:43:28 +0900279 else if (is_pci_ioaddr(port))
280 return (void __iomem *)pci_ioaddr(port);
Paul Mundt373e68b2006-09-27 15:41:24 +0900281
282 return (void __iomem *)port2adr(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}