aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/boards/renesas/hs7751rvoip/io.c
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2006-09-27 03:43:28 -0400
committerPaul Mundt <lethal@linux-sh.org>2006-09-27 03:43:28 -0400
commit959f85f8a3223c116bbe95dd8a9b207790b5d4d3 (patch)
treee7da9ccf292f860bfa0ff9cc8b2682cd1d6bad4d /arch/sh/boards/renesas/hs7751rvoip/io.c
parente108b2ca2349f510ce7d7f910eda89f71d710d84 (diff)
sh: Consolidated SH7751/SH7780 PCI support.
This cleans up quite a lot of the PCI mess that we currently have, and attempts to consolidate the duplication in the SH7780 and SH7751 PCI controllers. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'arch/sh/boards/renesas/hs7751rvoip/io.c')
-rw-r--r--arch/sh/boards/renesas/hs7751rvoip/io.c116
1 files changed, 38 insertions, 78 deletions
diff --git a/arch/sh/boards/renesas/hs7751rvoip/io.c b/arch/sh/boards/renesas/hs7751rvoip/io.c
index ecdce7ef6a34..8c26550ca2e4 100644
--- a/arch/sh/boards/renesas/hs7751rvoip/io.c
+++ b/arch/sh/boards/renesas/hs7751rvoip/io.c
@@ -13,14 +13,11 @@
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/module.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 *area6_io8_base; /* Area 6 8bit I/O Base address */ 21extern void *area6_io8_base; /* Area 6 8bit I/O Base address */
25extern void *area5_io16_base; /* Area 5 16bit I/O Base address */ 22extern void *area5_io16_base; /* Area 5 16bit I/O Base address */
26 23
@@ -31,27 +28,17 @@ extern void *area5_io16_base; /* Area 5 16bit I/O Base address */
31 * like the other Solution Engine boards. 28 * like the other Solution Engine boards.
32 */ 29 */
33 30
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))
39
40#define CODEC_IO_BASE 0x1000 31#define CODEC_IO_BASE 0x1000
41#define CODEC_IOMAP(a) ((unsigned long)area6_io8_base + ((a) - CODEC_IO_BASE)) 32#define CODEC_IOMAP(a) ((unsigned long)area6_io8_base + ((a) - CODEC_IO_BASE))
42 33
43static inline void delay(void)
44{
45 ctrl_inw(0xa0000000);
46}
47
48static inline unsigned long port2adr(unsigned int port) 34static inline unsigned long port2adr(unsigned int port)
49{ 35{
50 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6) 36 if ((0x1f0 <= port && port < 0x1f8) || port == 0x3f6)
51 if (port == 0x3f6) 37 if (port == 0x3f6)
52 return ((unsigned long)area5_io16_base + 0x0c); 38 return ((unsigned long)area5_io16_base + 0x0c);
53 else 39 else
54 return ((unsigned long)area5_io16_base + 0x800 + ((port-0x1f0) << 1)); 40 return ((unsigned long)area5_io16_base + 0x800 +
41 ((port-0x1f0) << 1));
55 else 42 else
56 maybebadio((unsigned long)port); 43 maybebadio((unsigned long)port);
57 return port; 44 return port;
@@ -70,25 +57,10 @@ static inline int shifted_port(unsigned long port)
70} 57}
71 58
72#if defined(CONFIG_HS7751RVOIP_CODEC) 59#if defined(CONFIG_HS7751RVOIP_CODEC)
73static inline int 60#define codec_port(port) \
74codec_port(unsigned long port) 61 ((CODEC_IO_BASE <= (port)) && ((port) < (CODEC_IO_BASE + 0x20)))
75{
76 if (CODEC_IO_BASE <= port && port < (CODEC_IO_BASE+0x20))
77 return 1;
78 else
79 return 0;
80}
81#endif
82
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 */
85
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)))
90#else 62#else
91#define CHECK_SH7751_PCIIO(port) (0) 63#define codec_port(port) (0)
92#endif 64#endif
93 65
94/* 66/*
@@ -102,12 +74,10 @@ unsigned char hs7751rvoip_inb(unsigned long port)
102{ 74{
103 if (PXSEG(port)) 75 if (PXSEG(port))
104 return ctrl_inb(port); 76 return ctrl_inb(port);
105#if defined(CONFIG_HS7751RVOIP_CODEC)
106 else if (codec_port(port)) 77 else if (codec_port(port))
107 return ctrl_inb(CODEC_IOMAP(port)); 78 return ctrl_inb(CODEC_IOMAP(port));
108#endif 79 else if (is_pci_ioaddr(port) || shifted_port(port))
109 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 80 return ctrl_inb(pci_ioaddr(port));
110 return ctrl_inb(PCI_IOMAP(port));
111 else 81 else
112 return ctrl_inw(port2adr(port)) & 0xff; 82 return ctrl_inw(port2adr(port)) & 0xff;
113} 83}
@@ -118,15 +88,13 @@ unsigned char hs7751rvoip_inb_p(unsigned long port)
118 88
119 if (PXSEG(port)) 89 if (PXSEG(port))
120 v = ctrl_inb(port); 90 v = ctrl_inb(port);
121#if defined(CONFIG_HS7751RVOIP_CODEC)
122 else if (codec_port(port)) 91 else if (codec_port(port))
123 v = ctrl_inb(CODEC_IOMAP(port)); 92 v = ctrl_inb(CODEC_IOMAP(port));
124#endif 93 else if (is_pci_ioaddr(port) || shifted_port(port))
125 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 94 v = ctrl_inb(pci_ioaddr(port));
126 v = ctrl_inb(PCI_IOMAP(port));
127 else 95 else
128 v = ctrl_inw(port2adr(port)) & 0xff; 96 v = ctrl_inw(port2adr(port)) & 0xff;
129 delay(); 97 ctrl_delay();
130 return v; 98 return v;
131} 99}
132 100
@@ -134,8 +102,8 @@ unsigned short hs7751rvoip_inw(unsigned long port)
134{ 102{
135 if (PXSEG(port)) 103 if (PXSEG(port))
136 return ctrl_inw(port); 104 return ctrl_inw(port);
137 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 105 else if (is_pci_ioaddr(port) || shifted_port(port))
138 return ctrl_inw(PCI_IOMAP(port)); 106 return ctrl_inw(pci_ioaddr(port));
139 else 107 else
140 maybebadio(port); 108 maybebadio(port);
141 return 0; 109 return 0;
@@ -145,8 +113,8 @@ unsigned int hs7751rvoip_inl(unsigned long port)
145{ 113{
146 if (PXSEG(port)) 114 if (PXSEG(port))
147 return ctrl_inl(port); 115 return ctrl_inl(port);
148 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 116 else if (is_pci_ioaddr(port) || shifted_port(port))
149 return ctrl_inl(PCI_IOMAP(port)); 117 return ctrl_inl(pci_ioaddr(port));
150 else 118 else
151 maybebadio(port); 119 maybebadio(port);
152 return 0; 120 return 0;
@@ -157,12 +125,10 @@ void hs7751rvoip_outb(unsigned char value, unsigned long port)
157 125
158 if (PXSEG(port)) 126 if (PXSEG(port))
159 ctrl_outb(value, port); 127 ctrl_outb(value, port);
160#if defined(CONFIG_HS7751RVOIP_CODEC)
161 else if (codec_port(port)) 128 else if (codec_port(port))
162 ctrl_outb(value, CODEC_IOMAP(port)); 129 ctrl_outb(value, CODEC_IOMAP(port));
163#endif 130 else if (is_pci_ioaddr(port) || shifted_port(port))
164 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 131 ctrl_outb(value, pci_ioaddr(port));
165 ctrl_outb(value, PCI_IOMAP(port));
166 else 132 else
167 ctrl_outb(value, port2adr(port)); 133 ctrl_outb(value, port2adr(port));
168} 134}
@@ -171,24 +137,22 @@ void hs7751rvoip_outb_p(unsigned char value, unsigned long port)
171{ 137{
172 if (PXSEG(port)) 138 if (PXSEG(port))
173 ctrl_outb(value, port); 139 ctrl_outb(value, port);
174#if defined(CONFIG_HS7751RVOIP_CODEC)
175 else if (codec_port(port)) 140 else if (codec_port(port))
176 ctrl_outb(value, CODEC_IOMAP(port)); 141 ctrl_outb(value, CODEC_IOMAP(port));
177#endif 142 else if (is_pci_ioaddr(port) || shifted_port(port))
178 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 143 ctrl_outb(value, pci_ioaddr(port));
179 ctrl_outb(value, PCI_IOMAP(port));
180 else 144 else
181 ctrl_outw(value, port2adr(port)); 145 ctrl_outw(value, port2adr(port));
182 146
183 delay(); 147 ctrl_delay();
184} 148}
185 149
186void hs7751rvoip_outw(unsigned short value, unsigned long port) 150void hs7751rvoip_outw(unsigned short value, unsigned long port)
187{ 151{
188 if (PXSEG(port)) 152 if (PXSEG(port))
189 ctrl_outw(value, port); 153 ctrl_outw(value, port);
190 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 154 else if (is_pci_ioaddr(port) || shifted_port(port))
191 ctrl_outw(value, PCI_IOMAP(port)); 155 ctrl_outw(value, pci_ioaddr(port));
192 else 156 else
193 maybebadio(port); 157 maybebadio(port);
194} 158}
@@ -197,8 +161,8 @@ void hs7751rvoip_outl(unsigned int value, unsigned long port)
197{ 161{
198 if (PXSEG(port)) 162 if (PXSEG(port))
199 ctrl_outl(value, port); 163 ctrl_outl(value, port);
200 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 164 else if (is_pci_ioaddr(port) || shifted_port(port))
201 ctrl_outl(value, PCI_IOMAP(port)); 165 ctrl_outl(value, pci_ioaddr(port));
202 else 166 else
203 maybebadio(port); 167 maybebadio(port);
204} 168}
@@ -210,13 +174,11 @@ void hs7751rvoip_insb(unsigned long port, void *addr, unsigned long count)
210 if (PXSEG(port)) 174 if (PXSEG(port))
211 while (count--) 175 while (count--)
212 *buf++ = ctrl_inb(port); 176 *buf++ = ctrl_inb(port);
213#if defined(CONFIG_HS7751RVOIP_CODEC)
214 else if (codec_port(port)) 177 else if (codec_port(port))
215 while (count--) 178 while (count--)
216 *buf++ = ctrl_inb(CODEC_IOMAP(port)); 179 *buf++ = ctrl_inb(CODEC_IOMAP(port));
217#endif 180 else if (is_pci_ioaddr(port) || shifted_port(port)) {
218 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) { 181 volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
219 volatile u8 *bp = (volatile u8 *)PCI_IOMAP(port);
220 182
221 while (count--) 183 while (count--)
222 *buf++ = *bp; 184 *buf++ = *bp;
@@ -235,8 +197,8 @@ void hs7751rvoip_insw(unsigned long port, void *addr, unsigned long count)
235 197
236 if (PXSEG(port)) 198 if (PXSEG(port))
237 p = (volatile u16 *)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 u16 *)PCI_IOMAP(port); 201 p = (volatile u16 *)pci_ioaddr(port);
240 else 202 else
241 p = (volatile u16 *)port2adr(port); 203 p = (volatile u16 *)port2adr(port);
242 while (count--) 204 while (count--)
@@ -246,8 +208,8 @@ void hs7751rvoip_insw(unsigned long port, void *addr, unsigned long count)
246void hs7751rvoip_insl(unsigned long port, void *addr, unsigned long count) 208void hs7751rvoip_insl(unsigned long port, void *addr, unsigned long count)
247{ 209{
248 210
249 if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) { 211 if (is_pci_ioaddr(port) || shifted_port(port)) {
250 volatile u32 *p = (volatile u32 *)PCI_IOMAP(port); 212 volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
251 u32 *buf = addr; 213 u32 *buf = addr;
252 214
253 while (count--) 215 while (count--)
@@ -263,13 +225,11 @@ void hs7751rvoip_outsb(unsigned long port, const void *addr, unsigned long count
263 if (PXSEG(port)) 225 if (PXSEG(port))
264 while (count--) 226 while (count--)
265 ctrl_outb(*buf++, port); 227 ctrl_outb(*buf++, port);
266#if defined(CONFIG_HS7751RVOIP_CODEC)
267 else if (codec_port(port)) 228 else if (codec_port(port))
268 while (count--) 229 while (count--)
269 ctrl_outb(*buf++, CODEC_IOMAP(port)); 230 ctrl_outb(*buf++, CODEC_IOMAP(port));
270#endif 231 else if (is_pci_ioaddr(port) || shifted_port(port)) {
271 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) { 232 volatile u8 *bp = (volatile u8 *)pci_ioaddr(port);
272 volatile u8 *bp = (volatile u8 *)PCI_IOMAP(port);
273 233
274 while (count--) 234 while (count--)
275 *bp = *buf++; 235 *bp = *buf++;
@@ -288,8 +248,8 @@ void hs7751rvoip_outsw(unsigned long port, const void *addr, unsigned long count
288 248
289 if (PXSEG(port)) 249 if (PXSEG(port))
290 p = (volatile u16 *)port; 250 p = (volatile u16 *)port;
291 else if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) 251 else if (is_pci_ioaddr(port) || shifted_port(port))
292 p = (volatile u16 *)PCI_IOMAP(port); 252 p = (volatile u16 *)pci_ioaddr(port);
293 else 253 else
294 p = (volatile u16 *)port2adr(port); 254 p = (volatile u16 *)port2adr(port);
295 255
@@ -301,8 +261,8 @@ void hs7751rvoip_outsl(unsigned long port, const void *addr, unsigned long count
301{ 261{
302 const u32 *buf = addr; 262 const u32 *buf = addr;
303 263
304 if (CHECK_SH7751_PCIIO(port) || shifted_port(port)) { 264 if (is_pci_ioaddr(port) || shifted_port(port)) {
305 volatile u32 *p = (volatile u32 *)PCI_IOMAP(port); 265 volatile u32 *p = (volatile u32 *)pci_ioaddr(port);
306 266
307 while (count--) 267 while (count--)
308 *p = *buf++; 268 *p = *buf++;
@@ -316,8 +276,8 @@ void __iomem *hs7751rvoip_ioport_map(unsigned long port, unsigned int size)
316 return (void __iomem *)port; 276 return (void __iomem *)port;
317 else if (unlikely(codec_port(port) && (size == 1))) 277 else if (unlikely(codec_port(port) && (size == 1)))
318 return (void __iomem *)CODEC_IOMAP(port); 278 return (void __iomem *)CODEC_IOMAP(port);
319 else if (CHECK_SH7751_PCIIO(port)) 279 else if (is_pci_ioaddr(port))
320 return (void __iomem *)PCI_IOMAP(port); 280 return (void __iomem *)pci_ioaddr(port);
321 281
322 return (void __iomem *)port2adr(port); 282 return (void __iomem *)port2adr(port);
323} 283}