ARM: amba: Make driver_override output consistent with other buses
[linux/fpc-iii.git] / arch / m32r / platforms / mappi / io.c
blob06ea6d9bc576adf3bc00ff73fbad9a1d8b1fc166
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/arch/m32r/platforms/mappi/io.c
5 * Typical I/O routines for Mappi board.
7 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
8 * Hitoshi Yamamoto
9 */
11 #include <asm/m32r.h>
12 #include <asm/page.h>
13 #include <asm/io.h>
14 #include <asm/byteorder.h>
16 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
17 #include <linux/types.h>
19 #define M32R_PCC_IOMAP_SIZE 0x1000
21 #define M32R_PCC_IOSTART0 0x1000
22 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
23 #define M32R_PCC_IOSTART1 0x2000
24 #define M32R_PCC_IOEND1 (M32R_PCC_IOSTART1 + M32R_PCC_IOMAP_SIZE - 1)
26 extern void pcc_ioread(int, unsigned long, void *, size_t, size_t, int);
27 extern void pcc_iowrite(int, unsigned long, void *, size_t, size_t, int);
28 #endif /* CONFIG_PCMCIA && CONFIG_M32R_PCC */
30 #define PORT2ADDR(port) _port2addr(port)
32 static inline void *_port2addr(unsigned long port)
34 return (void *)(port | NONCACHE_OFFSET);
37 static inline void *_port2addr_ne(unsigned long port)
39 return (void *)((port<<1) + NONCACHE_OFFSET + 0x0C000000);
42 static inline void delay(void)
44 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
48 * NIC I/O function
51 #define PORT2ADDR_NE(port) _port2addr_ne(port)
53 static inline unsigned char _ne_inb(void *portp)
55 return (unsigned char) *(volatile unsigned short *)portp;
58 static inline unsigned short _ne_inw(void *portp)
60 unsigned short tmp;
62 tmp = *(volatile unsigned short *)portp;
63 return le16_to_cpu(tmp);
66 static inline void _ne_outb(unsigned char b, void *portp)
68 *(volatile unsigned short *)portp = (unsigned short)b;
71 static inline void _ne_outw(unsigned short w, void *portp)
73 *(volatile unsigned short *)portp = cpu_to_le16(w);
76 unsigned char _inb(unsigned long port)
78 if (port >= 0x300 && port < 0x320)
79 return _ne_inb(PORT2ADDR_NE(port));
80 else
81 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
82 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
83 unsigned char b;
84 pcc_ioread(0, port, &b, sizeof(b), 1, 0);
85 return b;
86 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
87 unsigned char b;
88 pcc_ioread(1, port, &b, sizeof(b), 1, 0);
89 return b;
90 } else
91 #endif
93 return *(volatile unsigned char *)PORT2ADDR(port);
96 unsigned short _inw(unsigned long port)
98 if (port >= 0x300 && port < 0x320)
99 return _ne_inw(PORT2ADDR_NE(port));
100 else
101 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
102 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
103 unsigned short w;
104 pcc_ioread(0, port, &w, sizeof(w), 1, 0);
105 return w;
106 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
107 unsigned short w;
108 pcc_ioread(1, port, &w, sizeof(w), 1, 0);
109 return w;
110 } else
111 #endif
112 return *(volatile unsigned short *)PORT2ADDR(port);
115 unsigned long _inl(unsigned long port)
117 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
118 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
119 unsigned long l;
120 pcc_ioread(0, port, &l, sizeof(l), 1, 0);
121 return l;
122 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
123 unsigned short l;
124 pcc_ioread(1, port, &l, sizeof(l), 1, 0);
125 return l;
126 } else
127 #endif
128 return *(volatile unsigned long *)PORT2ADDR(port);
131 unsigned char _inb_p(unsigned long port)
133 unsigned char v = _inb(port);
134 delay();
135 return (v);
138 unsigned short _inw_p(unsigned long port)
140 unsigned short v = _inw(port);
141 delay();
142 return (v);
145 unsigned long _inl_p(unsigned long port)
147 unsigned long v = _inl(port);
148 delay();
149 return (v);
152 void _outb(unsigned char b, unsigned long port)
154 if (port >= 0x300 && port < 0x320)
155 _ne_outb(b, PORT2ADDR_NE(port));
156 else
157 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
158 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
159 pcc_iowrite(0, port, &b, sizeof(b), 1, 0);
160 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
161 pcc_iowrite(1, port, &b, sizeof(b), 1, 0);
162 } else
163 #endif
164 *(volatile unsigned char *)PORT2ADDR(port) = b;
167 void _outw(unsigned short w, unsigned long port)
169 if (port >= 0x300 && port < 0x320)
170 _ne_outw(w, PORT2ADDR_NE(port));
171 else
172 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
173 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
174 pcc_iowrite(0, port, &w, sizeof(w), 1, 0);
175 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
176 pcc_iowrite(1, port, &w, sizeof(w), 1, 0);
177 } else
178 #endif
179 *(volatile unsigned short *)PORT2ADDR(port) = w;
182 void _outl(unsigned long l, unsigned long port)
184 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
185 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
186 pcc_iowrite(0, port, &l, sizeof(l), 1, 0);
187 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
188 pcc_iowrite(1, port, &l, sizeof(l), 1, 0);
189 } else
190 #endif
191 *(volatile unsigned long *)PORT2ADDR(port) = l;
194 void _outb_p(unsigned char b, unsigned long port)
196 _outb(b, port);
197 delay();
200 void _outw_p(unsigned short w, unsigned long port)
202 _outw(w, port);
203 delay();
206 void _outl_p(unsigned long l, unsigned long port)
208 _outl(l, port);
209 delay();
212 void _insb(unsigned int port, void *addr, unsigned long count)
214 unsigned short *buf = addr;
215 unsigned short *portp;
217 if (port >= 0x300 && port < 0x320){
218 portp = PORT2ADDR_NE(port);
219 while (count--)
220 *buf++ = *(volatile unsigned char *)portp;
221 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
222 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
223 pcc_ioread(0, port, (void *)addr, sizeof(unsigned char),
224 count, 1);
225 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
226 pcc_ioread(1, port, (void *)addr, sizeof(unsigned char),
227 count, 1);
228 #endif
229 } else {
230 portp = PORT2ADDR(port);
231 while (count--)
232 *buf++ = *(volatile unsigned char *)portp;
236 void _insw(unsigned int port, void *addr, unsigned long count)
238 unsigned short *buf = addr;
239 unsigned short *portp;
241 if (port >= 0x300 && port < 0x320) {
242 portp = PORT2ADDR_NE(port);
243 while (count--)
244 *buf++ = _ne_inw(portp);
245 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
246 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
247 pcc_ioread(0, port, (void *)addr, sizeof(unsigned short),
248 count, 1);
249 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
250 pcc_ioread(1, port, (void *)addr, sizeof(unsigned short),
251 count, 1);
252 #endif
253 } else {
254 portp = PORT2ADDR(port);
255 while (count--)
256 *buf++ = *(volatile unsigned short *)portp;
260 void _insl(unsigned int port, void *addr, unsigned long count)
262 unsigned long *buf = addr;
263 unsigned long *portp;
265 portp = PORT2ADDR(port);
266 while (count--)
267 *buf++ = *(volatile unsigned long *)portp;
270 void _outsb(unsigned int port, const void *addr, unsigned long count)
272 const unsigned char *buf = addr;
273 unsigned char *portp;
275 if (port >= 0x300 && port < 0x320) {
276 portp = PORT2ADDR_NE(port);
277 while (count--)
278 _ne_outb(*buf++, portp);
279 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
280 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
281 pcc_iowrite(0, port, (void *)addr, sizeof(unsigned char),
282 count, 1);
283 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
284 pcc_iowrite(1, port, (void *)addr, sizeof(unsigned char),
285 count, 1);
286 #endif
287 } else {
288 portp = PORT2ADDR(port);
289 while (count--)
290 *(volatile unsigned char *)portp = *buf++;
294 void _outsw(unsigned int port, const void *addr, unsigned long count)
296 const unsigned short *buf = addr;
297 unsigned short *portp;
299 if (port >= 0x300 && port < 0x320) {
300 portp = PORT2ADDR_NE(port);
301 while (count--)
302 _ne_outw(*buf++, portp);
303 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_PCC)
304 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
305 pcc_iowrite(0, port, (void *)addr, sizeof(unsigned short),
306 count, 1);
307 } else if (port >= M32R_PCC_IOSTART1 && port <= M32R_PCC_IOEND1) {
308 pcc_iowrite(1, port, (void *)addr, sizeof(unsigned short),
309 count, 1);
310 #endif
311 } else {
312 portp = PORT2ADDR(port);
313 while (count--)
314 *(volatile unsigned short *)portp = *buf++;
318 void _outsl(unsigned int port, const void *addr, unsigned long count)
320 const unsigned long *buf = addr;
321 unsigned char *portp;
323 portp = PORT2ADDR(port);
324 while (count--)
325 *(volatile unsigned long *)portp = *buf++;