]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/m32r/kernel/io_mappi3.c
drm: merge in Linus mainline
[mirror_ubuntu-zesty-kernel.git] / arch / m32r / kernel / io_mappi3.c
1 /*
2 * linux/arch/m32r/kernel/io_mappi3.c
3 *
4 * Typical I/O routines for Mappi3 board.
5 *
6 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Mamoru Sakugawa
8 */
9
10 #include <linux/config.h>
11 #include <asm/m32r.h>
12 #include <asm/page.h>
13 #include <asm/io.h>
14 #include <asm/byteorder.h>
15
16 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
17 #include <linux/types.h>
18
19 #define M32R_PCC_IOMAP_SIZE 0x1000
20
21 #define M32R_PCC_IOSTART0 0x1000
22 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
23
24 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
25 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
26 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
27 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
28 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
29
30 #define PORT2ADDR(port) _port2addr(port)
31 #define PORT2ADDR_NE(port) _port2addr_ne(port)
32 #define PORT2ADDR_USB(port) _port2addr_usb(port)
33
34 static inline void *_port2addr(unsigned long port)
35 {
36 return (void *)(port + NONCACHE_OFFSET);
37 }
38
39 #if defined(CONFIG_IDE)
40 static inline void *__port2addr_ata(unsigned long port)
41 {
42 static int dummy_reg;
43
44 switch (port) {
45 /* IDE0 CF */
46 case 0x1f0: return (void *)0xb4002000;
47 case 0x1f1: return (void *)0xb4012800;
48 case 0x1f2: return (void *)0xb4012002;
49 case 0x1f3: return (void *)0xb4012802;
50 case 0x1f4: return (void *)0xb4012004;
51 case 0x1f5: return (void *)0xb4012804;
52 case 0x1f6: return (void *)0xb4012006;
53 case 0x1f7: return (void *)0xb4012806;
54 case 0x3f6: return (void *)0xb401200e;
55 /* IDE1 IDE */
56 case 0x170: return (void *)0xb4810000; /* Data 16bit */
57 case 0x171: return (void *)0xb4810002; /* Features / Error */
58 case 0x172: return (void *)0xb4810004; /* Sector count */
59 case 0x173: return (void *)0xb4810006; /* Sector number */
60 case 0x174: return (void *)0xb4810008; /* Cylinder low */
61 case 0x175: return (void *)0xb481000a; /* Cylinder high */
62 case 0x176: return (void *)0xb481000c; /* Device head */
63 case 0x177: return (void *)0xb481000e; /* Command */
64 case 0x376: return (void *)0xb480800c; /* Device control / Alt status */
65
66 default: return (void *)&dummy_reg;
67 }
68 }
69 #endif
70
71 #define LAN_IOSTART 0xa0000300
72 #define LAN_IOEND 0xa0000320
73 static inline void *_port2addr_ne(unsigned long port)
74 {
75 return (void *)(port + 0x10000000);
76 }
77
78 static inline void *_port2addr_usb(unsigned long port)
79 {
80 return (void *)(port + NONCACHE_OFFSET + 0x12000000);
81 }
82 static inline void delay(void)
83 {
84 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
85 }
86
87 /*
88 * NIC I/O function
89 */
90
91 static inline unsigned char _ne_inb(void *portp)
92 {
93 return (unsigned char) *(volatile unsigned char *)portp;
94 }
95
96 static inline unsigned short _ne_inw(void *portp)
97 {
98 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
99 }
100
101 static inline void _ne_insb(void *portp, void * addr, unsigned long count)
102 {
103 unsigned char *buf = addr;
104
105 while (count--)
106 *buf++ = *(volatile unsigned char *)portp;
107 }
108
109 static inline void _ne_outb(unsigned char b, void *portp)
110 {
111 *(volatile unsigned char *)portp = (unsigned char)b;
112 }
113
114 static inline void _ne_outw(unsigned short w, void *portp)
115 {
116 *(volatile unsigned short *)portp = cpu_to_le16(w);
117 }
118
119 unsigned char _inb(unsigned long port)
120 {
121 if (port >= LAN_IOSTART && port < LAN_IOEND)
122 return _ne_inb(PORT2ADDR_NE(port));
123 #if defined(CONFIG_IDE)
124 else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
125 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
126 return *(volatile unsigned char *)__port2addr_ata(port);
127 }
128 #endif
129 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
130 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
131 unsigned char b;
132 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
133 return b;
134 } else
135 #endif
136 return *(volatile unsigned char *)PORT2ADDR(port);
137 }
138
139 unsigned short _inw(unsigned long port)
140 {
141 if (port >= LAN_IOSTART && port < LAN_IOEND)
142 return _ne_inw(PORT2ADDR_NE(port));
143 #if defined(CONFIG_IDE)
144 else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
145 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
146 return *(volatile unsigned short *)__port2addr_ata(port);
147 }
148 #endif
149 #if defined(CONFIG_USB)
150 else if (port >= 0x340 && port < 0x3a0)
151 return *(volatile unsigned short *)PORT2ADDR_USB(port);
152 #endif
153
154 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
155 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
156 unsigned short w;
157 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
158 return w;
159 } else
160 #endif
161 return *(volatile unsigned short *)PORT2ADDR(port);
162 }
163
164 unsigned long _inl(unsigned long port)
165 {
166 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
167 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
168 unsigned long l;
169 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
170 return l;
171 } else
172 #endif
173 return *(volatile unsigned long *)PORT2ADDR(port);
174 }
175
176 unsigned char _inb_p(unsigned long port)
177 {
178 unsigned char v = _inb(port);
179 delay();
180 return (v);
181 }
182
183 unsigned short _inw_p(unsigned long port)
184 {
185 unsigned short v = _inw(port);
186 delay();
187 return (v);
188 }
189
190 unsigned long _inl_p(unsigned long port)
191 {
192 unsigned long v = _inl(port);
193 delay();
194 return (v);
195 }
196
197 void _outb(unsigned char b, unsigned long port)
198 {
199 if (port >= LAN_IOSTART && port < LAN_IOEND)
200 _ne_outb(b, PORT2ADDR_NE(port));
201 else
202 #if defined(CONFIG_IDE)
203 if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
204 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
205 *(volatile unsigned char *)__port2addr_ata(port) = b;
206 } else
207 #endif
208 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
209 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
210 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
211 } else
212 #endif
213 *(volatile unsigned char *)PORT2ADDR(port) = b;
214 }
215
216 void _outw(unsigned short w, unsigned long port)
217 {
218 if (port >= LAN_IOSTART && port < LAN_IOEND)
219 _ne_outw(w, PORT2ADDR_NE(port));
220 else
221 #if defined(CONFIG_IDE)
222 if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
223 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
224 *(volatile unsigned short *)__port2addr_ata(port) = w;
225 } else
226 #endif
227 #if defined(CONFIG_USB)
228 if (port >= 0x340 && port < 0x3a0)
229 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
230 else
231 #endif
232 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
233 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
234 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
235 } else
236 #endif
237 *(volatile unsigned short *)PORT2ADDR(port) = w;
238 }
239
240 void _outl(unsigned long l, unsigned long port)
241 {
242 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
243 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
244 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
245 } else
246 #endif
247 *(volatile unsigned long *)PORT2ADDR(port) = l;
248 }
249
250 void _outb_p(unsigned char b, unsigned long port)
251 {
252 _outb(b, port);
253 delay();
254 }
255
256 void _outw_p(unsigned short w, unsigned long port)
257 {
258 _outw(w, port);
259 delay();
260 }
261
262 void _outl_p(unsigned long l, unsigned long port)
263 {
264 _outl(l, port);
265 delay();
266 }
267
268 void _insb(unsigned int port, void * addr, unsigned long count)
269 {
270 if (port >= LAN_IOSTART && port < LAN_IOEND)
271 _ne_insb(PORT2ADDR_NE(port), addr, count);
272 #if defined(CONFIG_IDE)
273 else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
274 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
275 unsigned char *buf = addr;
276 unsigned char *portp = __port2addr_ata(port);
277 while (count--)
278 *buf++ = *(volatile unsigned char *)portp;
279 }
280 #endif
281 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
282 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
283 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
284 count, 1);
285 }
286 #endif
287 else {
288 unsigned char *buf = addr;
289 unsigned char *portp = PORT2ADDR(port);
290 while (count--)
291 *buf++ = *(volatile unsigned char *)portp;
292 }
293 }
294
295 void _insw(unsigned int port, void * addr, unsigned long count)
296 {
297 unsigned short *buf = addr;
298 unsigned short *portp;
299
300 if (port >= LAN_IOSTART && port < LAN_IOEND) {
301 portp = PORT2ADDR_NE(port);
302 while (count--)
303 *buf++ = *(volatile unsigned short *)portp;
304 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
305 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
306 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
307 count, 1);
308 #endif
309 #if defined(CONFIG_IDE)
310 } else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
311 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
312 portp = __port2addr_ata(port);
313 while (count--)
314 *buf++ = *(volatile unsigned short *)portp;
315 #endif
316 } else {
317 portp = PORT2ADDR(port);
318 while (count--)
319 *buf++ = *(volatile unsigned short *)portp;
320 }
321 }
322
323 void _insl(unsigned int port, void * addr, unsigned long count)
324 {
325 unsigned long *buf = addr;
326 unsigned long *portp;
327
328 portp = PORT2ADDR(port);
329 while (count--)
330 *buf++ = *(volatile unsigned long *)portp;
331 }
332
333 void _outsb(unsigned int port, const void * addr, unsigned long count)
334 {
335 const unsigned char *buf = addr;
336 unsigned char *portp;
337
338 if (port >= LAN_IOSTART && port < LAN_IOEND) {
339 portp = PORT2ADDR_NE(port);
340 while (count--)
341 _ne_outb(*buf++, portp);
342 #if defined(CONFIG_IDE)
343 } else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
344 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
345 portp = __port2addr_ata(port);
346 while (count--)
347 *(volatile unsigned char *)portp = *buf++;
348 #endif
349 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
350 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
351 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
352 count, 1);
353 #endif
354 } else {
355 portp = PORT2ADDR(port);
356 while (count--)
357 *(volatile unsigned char *)portp = *buf++;
358 }
359 }
360
361 void _outsw(unsigned int port, const void * addr, unsigned long count)
362 {
363 const unsigned short *buf = addr;
364 unsigned short *portp;
365
366 if (port >= LAN_IOSTART && port < LAN_IOEND) {
367 portp = PORT2ADDR_NE(port);
368 while (count--)
369 *(volatile unsigned short *)portp = *buf++;
370 #if defined(CONFIG_IDE)
371 } else if ( ((port >= 0x170 && port <=0x177) || port == 0x376) ||
372 ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) ){
373 portp = __port2addr_ata(port);
374 while (count--)
375 *(volatile unsigned short *)portp = *buf++;
376 #endif
377 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
378 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
379 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
380 count, 1);
381 #endif
382 } else {
383 portp = PORT2ADDR(port);
384 while (count--)
385 *(volatile unsigned short *)portp = *buf++;
386 }
387 }
388
389 void _outsl(unsigned int port, const void * addr, unsigned long count)
390 {
391 const unsigned long *buf = addr;
392 unsigned char *portp;
393
394 portp = PORT2ADDR(port);
395 while (count--)
396 *(volatile unsigned long *)portp = *buf++;
397 }