aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/boards/renesas/hs7751rvoip/io.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2006-09-27 18:16:47 -0400
committerJeff Garzik <jeff@garzik.org>2006-09-27 18:16:47 -0400
commit3b9f6cb8a1ec791be79c6c7595fea922f12d1e64 (patch)
tree2393a448add846e6c2ed12f68106c3018b72c6a9 /arch/sh/boards/renesas/hs7751rvoip/io.c
parentc38778c3a9aeadcd1ee319cfc8ea5a9cbf8cdafa (diff)
parenta77c64c1a641950626181b4857abb701d8f38ccc (diff)
Merge branch 'master' into upstream
Diffstat (limited to 'arch/sh/boards/renesas/hs7751rvoip/io.c')
-rw-r--r--arch/sh/boards/renesas/hs7751rvoip/io.c252
1 files changed, 113 insertions, 139 deletions
diff --git a/arch/sh/boards/renesas/hs7751rvoip/io.c b/arch/sh/boards/renesas/hs7751rvoip/io.c
index 3a1abfa2fefb..9ea1136b219b 100644
--- a/arch/sh/boards/renesas/hs7751rvoip/io.c
+++ b/arch/sh/boards/renesas/hs7751rvoip/io.c
@@ -10,21 +10,16 @@
10 * placeholder code from io_hs7751rvoip.c left in with the 10 * placeholder code from io_hs7751rvoip.c left in with the
11 * expectation of later SuperIO and PCMCIA access. 11 * expectation of later SuperIO and PCMCIA access.
12 */ 12 */
13
14#include <linux/kernel.h> 13#include <linux/kernel.h>
15#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/module.h>
16#include <linux/pci.h>
16#include <asm/io.h> 17#include <asm/io.h>
17#include <asm/hs7751rvoip/hs7751rvoip.h> 18#include <asm/hs7751rvoip/hs7751rvoip.h>
18#include <asm/addrspace.h> 19#include <asm/addrspace.h>
19 20
20#include <linux/module.h>
21#include <linux/pci.h>
22#include "../../../drivers/pci/pci-sh7751.h"
23
24extern void *area5_io8_base; /* Area 5 8bit I/O Base address */
25extern void *area6_io8_base; /* Area 6 8bit I/O Base address */ 21extern void *area6_io8_base; /* Area 6 8bit I/O Base address */
26extern void *area5_io16_base; /* Area 5 16bit I/O Base address */ 22extern void *area5_io16_base; /* Area 5 16bit I/O Base address */
27extern void *area6_io16_base; /* Area 6 16bit I/O Base address */
28 23
29/* 24/*
30 * The 7751R HS7751RVoIP uses the built-in PCI controller (PCIC) 25 * The 7751R HS7751RVoIP uses the built-in PCI controller (PCIC)
@@ -33,25 +28,8 @@ extern void *area6_io16_base; /* Area 6 16bit I/O Base address */
33 * like the other Solution Engine boards. 28 * like the other Solution Engine boards.
34 */ 29 */
35 30
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
40
41#define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
42
43#if defined(CONFIG_HS7751RVOIP_CODEC)
44#define CODEC_IO_BASE 0x1000 31#define CODEC_IO_BASE 0x1000
45#endif 32#define CODEC_IOMAP(a) ((unsigned long)area6_io8_base + ((a) - CODEC_IO_BASE))
46
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))
50
51static inline void delay(void)
52{
53 ctrl_inw(0xa0000000);
54}
55 33
56static inline unsigned long port2adr(unsigned int port) 34static inline unsigned long port2adr(unsigned int port)
57{ 35{
@@ -59,9 +37,10 @@ static inline unsigned long port2adr(unsigned int port)
59 if (port == 0x3f6) 37 if (port == 0x3f6)
60 return ((unsigned long)area5_io16_base + 0x0c); 38 return ((unsigned long)area5_io16_base + 0x0c);
61 else 39 else
62 return ((unsigned long)area5_io16_base + 0x800 + ((port-0x1f0) << 1)); 40 return ((unsigned long)area5_io16_base + 0x800 +
41 ((port-0x1f0) << 1));
63 else 42 else
64 maybebadio(port2adr, (unsigned long)port); 43 maybebadio((unsigned long)port);
65 return port; 44 return port;
66} 45}
67 46
@@ -78,25 +57,10 @@ static inline int shifted_port(unsigned long port)
78} 57}
79 58
80#if defined(CONFIG_HS7751RVOIP_CODEC) 59#if defined(CONFIG_HS7751RVOIP_CODEC)
81static inline int 60#define codec_port(port) \
82codec_port(unsigned long port) 61 ((CODEC_IO_BASE <= (port)) && ((port) < (CODEC_IO_BASE + 0x20)))
83{
84 if (CODEC_IO_BASE <= port && port < (CODEC_IO_BASE+0x20))
85 return 1;
86 else
87 return 0;
88}
89#endif
90
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 */
93
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)))
98#else 62#else
99#define CHECK_SH7751_PCIIO(port) (0) 63#define codec_port(port) (0)
100#endif 64#endif
101 65
102/* 66/*
@@ -109,15 +73,13 @@ codec_port(unsigned long port)
109unsigned char hs7751rvoip_inb(unsigned long port) 73unsigned char hs7751rvoip_inb(unsigned long port)
110{ 74{
111 if (PXSEG(port)) 75 if (PXSEG(port))
112 return *(volatile unsigned char *)port; 76 return ctrl_inb(port);
113#if defined(CONFIG_HS7751RVOIP_CODEC)
114 else if (codec_port(port)) 77 else if (codec_port(port))
115 return *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)); 78 return ctrl_inb(CODEC_IOMAP(port));
116#endif 79 else if (is_pci_ioaddr(port) || shifted_port(port))
117 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 80 return ctrl_inb(pci_ioaddr(port));
118 return *(volatile unsigned char *)PCI_IOMAP(port);
119 else 81 else
120 return (*(volatile unsigned short *)port2adr(port) & 0xff); 82 return ctrl_inw(port2adr(port)) & 0xff;
121} 83}
122 84
123unsigned char hs7751rvoip_inb_p(unsigned long port) 85unsigned char hs7751rvoip_inb_p(unsigned long port)
@@ -125,38 +87,36 @@ unsigned char hs7751rvoip_inb_p(unsigned long port)
125 unsigned char v; 87 unsigned char v;
126 88
127 if (PXSEG(port)) 89 if (PXSEG(port))
128 v = *(volatile unsigned char *)port; 90 v = ctrl_inb(port);
129#if defined(CONFIG_HS7751RVOIP_CODEC)
130 else if (codec_port(port)) 91 else if (codec_port(port))
131 v = *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)); 92 v = ctrl_inb(CODEC_IOMAP(port));
132#endif 93 else if (is_pci_ioaddr(port) || shifted_port(port))
133 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 94 v = ctrl_inb(pci_ioaddr(port));
134 v = *(volatile unsigned char *)PCI_IOMAP(port);
135 else 95 else
136 v = (*(volatile unsigned short *)port2adr(port) & 0xff); 96 v = ctrl_inw(port2adr(port)) & 0xff;
137 delay(); 97 ctrl_delay();
138 return v; 98 return v;
139} 99}
140 100
141unsigned short hs7751rvoip_inw(unsigned long port) 101unsigned short hs7751rvoip_inw(unsigned long port)
142{ 102{
143 if (PXSEG(port)) 103 if (PXSEG(port))
144 return *(volatile unsigned short *)port; 104 return ctrl_inw(port);
145 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 105 else if (is_pci_ioaddr(port) || shifted_port(port))
146 return *(volatile unsigned short *)PCI_IOMAP(port); 106 return ctrl_inw(pci_ioaddr(port));
147 else 107 else
148 maybebadio(inw, port); 108 maybebadio(port);
149 return 0; 109 return 0;
150} 110}
151 111
152unsigned int hs7751rvoip_inl(unsigned long port) 112unsigned int hs7751rvoip_inl(unsigned long port)
153{ 113{
154 if (PXSEG(port)) 114 if (PXSEG(port))
155 return *(volatile unsigned long *)port; 115 return ctrl_inl(port);
156 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 116 else if (is_pci_ioaddr(port) || shifted_port(port))
157 return *(volatile unsigned long *)PCI_IOMAP(port); 117 return ctrl_inl(pci_ioaddr(port));
158 else 118 else
159 maybebadio(inl, port); 119 maybebadio(port);
160 return 0; 120 return 0;
161} 121}
162 122
@@ -164,146 +124,160 @@ void hs7751rvoip_outb(unsigned char value, unsigned long port)
164{ 124{
165 125
166 if (PXSEG(port)) 126 if (PXSEG(port))
167 *(volatile unsigned char *)port = value; 127 ctrl_outb(value, port);
168#if defined(CONFIG_HS7751RVOIP_CODEC)
169 else if (codec_port(port)) 128 else if (codec_port(port))
170 *(volatile unsigned cjar *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)) = value; 129 ctrl_outb(value, CODEC_IOMAP(port));
171#endif 130 else if (is_pci_ioaddr(port) || shifted_port(port))
172 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 131 ctrl_outb(value, pci_ioaddr(port));
173 *(unsigned char *)PCI_IOMAP(port) = value;
174 else 132 else
175 *(volatile unsigned short *)port2adr(port) = value; 133 ctrl_outb(value, port2adr(port));
176} 134}
177 135
178void hs7751rvoip_outb_p(unsigned char value, unsigned long port) 136void hs7751rvoip_outb_p(unsigned char value, unsigned long port)
179{ 137{
180 if (PXSEG(port)) 138 if (PXSEG(port))
181 *(volatile unsigned char *)port = value; 139 ctrl_outb(value, port);
182#if defined(CONFIG_HS7751RVOIP_CODEC)
183 else if (codec_port(port)) 140 else if (codec_port(port))
184 *(volatile unsigned cjar *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)) = value; 141 ctrl_outb(value, CODEC_IOMAP(port));
185#endif 142 else if (is_pci_ioaddr(port) || shifted_port(port))
186 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 143 ctrl_outb(value, pci_ioaddr(port));
187 *(unsigned char *)PCI_IOMAP(port) = value;
188 else 144 else
189 *(volatile unsigned short *)port2adr(port) = value; 145 ctrl_outw(value, port2adr(port));
190 delay(); 146
147 ctrl_delay();
191} 148}
192 149
193void hs7751rvoip_outw(unsigned short value, unsigned long port) 150void hs7751rvoip_outw(unsigned short value, unsigned long port)
194{ 151{
195 if (PXSEG(port)) 152 if (PXSEG(port))
196 *(volatile unsigned short *)port = value; 153 ctrl_outw(value, port);
197 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 154 else if (is_pci_ioaddr(port) || shifted_port(port))
198 *(unsigned short *)PCI_IOMAP(port) = value; 155 ctrl_outw(value, pci_ioaddr(port));
199 else 156 else
200 maybebadio(outw, port); 157 maybebadio(port);
201} 158}
202 159
203void hs7751rvoip_outl(unsigned int value, unsigned long port) 160void hs7751rvoip_outl(unsigned int value, unsigned long port)
204{ 161{
205 if (PXSEG(port)) 162 if (PXSEG(port))
206 *(volatile unsigned long *)port = value; 163 ctrl_outl(value, port);
207 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 164 else if (is_pci_ioaddr(port) || shifted_port(port))
208 *((unsigned long *)PCI_IOMAP(port)) = value; 165 ctrl_outl(value, pci_ioaddr(port));
209 else 166 else
210 maybebadio(outl, port); 167 maybebadio(port);
211} 168}
212 169
213void hs7751rvoip_insb(unsigned long port, void *addr, unsigned long count) 170void hs7751rvoip_insb(unsigned long port, void *addr, unsigned long count)
214{ 171{
172 u8 *buf = addr;
173
215 if (PXSEG(port)) 174 if (PXSEG(port))
216 while (count--) *((unsigned char *) addr)++ = *(volatile unsigned char *)port; 175 while (count--)
217#if defined(CONFIG_HS7751RVOIP_CODEC) 176 *buf++ = ctrl_inb(port);
218 else if (codec_port(port)) 177 else if (codec_port(port))
219 while (count--) *((unsigned char *) addr)++ = *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)); 178 while (count--)
220#endif 179 *buf++ = ctrl_inb(CODEC_IOMAP(port));
221 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) { 180 else if (is_pci_ioaddr(port) || shifted_port(port)) {
222 volatile __u8 *bp = (__u8 *)PCI_IOMAP(port); 181 volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
223 182
224 while (count--) *((volatile unsigned char *) addr)++ = *bp; 183 while (count--)
184 *buf++ = *bp;
225 } else { 185 } else {
226 volatile __u16 *p = (volatile unsigned short *)port2adr(port); 186 volatile u16 *p = (volatile u16 *)port2adr(port);
227 187
228 while (count--) *((unsigned char *) addr)++ = *p & 0xff; 188 while (count--)
189 *buf++ = *p & 0xff;
229 } 190 }
230} 191}
231 192
232void hs7751rvoip_insw(unsigned long port, void *addr, unsigned long count) 193void hs7751rvoip_insw(unsigned long port, void *addr, unsigned long count)
233{ 194{
234 volatile __u16 *p; 195 volatile u16 *p;
196 u16 *buf = addr;
235 197
236 if (PXSEG(port)) 198 if (PXSEG(port))
237 p = (volatile unsigned short *)port; 199 p = (volatile u16 *)port;
238 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 200 else if (is_pci_ioaddr(port) || shifted_port(port))
239 p = (volatile unsigned short *)PCI_IOMAP(port); 201 p = (volatile u16 *)pci_ioaddr(port);
240 else 202 else
241 p = (volatile unsigned short *)port2adr(port); 203 p = (volatile u16 *)port2adr(port);
242 while (count--) *((__u16 *) addr)++ = *p; 204 while (count--)
205 *buf++ = *p;
243} 206}
244 207
245void hs7751rvoip_insl(unsigned long port, void *addr, unsigned long count) 208void hs7751rvoip_insl(unsigned long port, void *addr, unsigned long count)
246{ 209{
247 if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) {
248 volatile __u32 *p = (__u32 *)PCI_IOMAP(port);
249 210
250 while (count--) *((__u32 *) addr)++ = *p; 211 if (is_pci_ioaddr(port) || shifted_port(port)) {
212 volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
213 u32 *buf = addr;
214
215 while (count--)
216 *buf++ = *p;
251 } else 217 } else
252 maybebadio(insl, port); 218 maybebadio(port);
253} 219}
254 220
255void hs7751rvoip_outsb(unsigned long port, const void *addr, unsigned long count) 221void hs7751rvoip_outsb(unsigned long port, const void *addr, unsigned long count)
256{ 222{
223 const u8 *buf = addr;
224
257 if (PXSEG(port)) 225 if (PXSEG(port))
258 while (count--) *(volatile unsigned char *)port = *((unsigned char *) addr)++; 226 while (count--)
259#if defined(CONFIG_HS7751RVOIP_CODEC) 227 ctrl_outb(*buf++, port);
260 else if (codec_port(port)) 228 else if (codec_port(port))
261 while (count--) *(volatile unsigned char *)((unsigned long)area6_io8_base+(port-CODEC_IO_BASE)) = *((unsigned char *) addr)++; 229 while (count--)
262#endif 230 ctrl_outb(*buf++, CODEC_IOMAP(port));
263 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) { 231 else if (is_pci_ioaddr(port) || shifted_port(port)) {
264 volatile __u8 *bp = (__u8 *)PCI_IOMAP(port); 232 volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
265 233
266 while (count--) *bp = *((volatile unsigned char *) addr)++; 234 while (count--)
235 *bp = *buf++;
267 } else { 236 } else {
268 volatile __u16 *p = (volatile unsigned short *)port2adr(port); 237 volatile u16 *p = (volatile u16 *)port2adr(port);
269 238
270 while (count--) *p = *((unsigned char *) addr)++; 239 while (count--)
240 *p = *buf++;
271 } 241 }
272} 242}
273 243
274void hs7751rvoip_outsw(unsigned long port, const void *addr, unsigned long count) 244void hs7751rvoip_outsw(unsigned long port, const void *addr, unsigned long count)
275{ 245{
276 volatile __u16 *p; 246 volatile u16 *p;
247 const u16 *buf = addr;
277 248
278 if (PXSEG(port)) 249 if (PXSEG(port))
279 p = (volatile unsigned short *)port; 250 p = (volatile u16 *)port;
280 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 251 else if (is_pci_ioaddr(port) || shifted_port(port))
281 p = (volatile unsigned short *)PCI_IOMAP(port); 252 p = (volatile u16 *)pci_ioaddr(port);
282 else 253 else
283 p = (volatile unsigned short *)port2adr(port); 254 p = (volatile u16 *)port2adr(port);
284 while (count--) *p = *((__u16 *) addr)++; 255
256 while (count--)
257 *p = *buf++;
285} 258}
286 259
287void hs7751rvoip_outsl(unsigned long port, const void *addr, unsigned long count) 260void hs7751rvoip_outsl(unsigned long port, const void *addr, unsigned long count)
288{ 261{
289 if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) { 262 const u32 *buf = addr;
290 volatile __u32 *p = (__u32 *)PCI_IOMAP(port);
291 263
292 while (count--) *p = *((__u32 *) addr)++; 264 if (is_pci_ioaddr(port) || shifted_port(port)) {
265 volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
266
267 while (count--)
268 *p = *buf++;
293 } else 269 } else
294 maybebadio(outsl, port); 270 maybebadio(port);
295} 271}
296 272
297void *hs7751rvoip_ioremap(unsigned long offset, unsigned long size) 273void __iomem *hs7751rvoip_ioport_map(unsigned long port, unsigned int size)
298{ 274{
299 if (offset >= 0xfd000000) 275 if (PXSEG(port))
300 return (void *)offset; 276 return (void __iomem *)port;
301 else 277 else if (unlikely(codec_port(port) && (size == 1)))
302 return (void *)P2SEGADDR(offset); 278 return (void __iomem *)CODEC_IOMAP(port);
303} 279 else if (is_pci_ioaddr(port))
304EXPORT_SYMBOL(hs7751rvoip_ioremap); 280 return (void __iomem *)pci_ioaddr(port);
305 281
306unsigned long hs7751rvoip_isa_port2addr(unsigned long offset) 282 return (void __iomem *)port2adr(port);
307{
308 return port2adr(offset);
309} 283}