Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Hirokazu Takata | 3264f97 | 2007-08-01 21:09:31 +0900 | [diff] [blame] | 3 | * linux/arch/m32r/platforms/mappi2/io.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Typical I/O routines for Mappi2 board. |
| 6 | * |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 7 | * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Hitoshi Yamamoto, Mamoru Sakugawa |
| 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 28 | #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | { |
Hirokazu Takata | 46ea178 | 2006-01-06 00:18:43 -0800 | [diff] [blame] | 36 | return (void *)(port | NONCACHE_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) |
| 40 | static inline void *__port2addr_ata(unsigned long port) |
| 41 | { |
| 42 | static int dummy_reg; |
| 43 | |
| 44 | switch (port) { |
Hirokazu Takata | 46ea178 | 2006-01-06 00:18:43 -0800 | [diff] [blame] | 45 | case 0x1f0: return (void *)(0x0c002000 | NONCACHE_OFFSET); |
| 46 | case 0x1f1: return (void *)(0x0c012800 | NONCACHE_OFFSET); |
| 47 | case 0x1f2: return (void *)(0x0c012002 | NONCACHE_OFFSET); |
| 48 | case 0x1f3: return (void *)(0x0c012802 | NONCACHE_OFFSET); |
| 49 | case 0x1f4: return (void *)(0x0c012004 | NONCACHE_OFFSET); |
| 50 | case 0x1f5: return (void *)(0x0c012804 | NONCACHE_OFFSET); |
| 51 | case 0x1f6: return (void *)(0x0c012006 | NONCACHE_OFFSET); |
| 52 | case 0x1f7: return (void *)(0x0c012806 | NONCACHE_OFFSET); |
| 53 | case 0x3f6: return (void *)(0x0c01200e | NONCACHE_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | default: return (void *)&dummy_reg; |
| 55 | } |
| 56 | } |
| 57 | #endif |
| 58 | |
Hirokazu Takata | 46ea178 | 2006-01-06 00:18:43 -0800 | [diff] [blame] | 59 | #define LAN_IOSTART (0x300 | NONCACHE_OFFSET) |
| 60 | #define LAN_IOEND (0x320 | NONCACHE_OFFSET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #ifdef CONFIG_CHIP_OPSP |
| 62 | static inline void *_port2addr_ne(unsigned long port) |
| 63 | { |
Hirokazu Takata | f3ac9fb | 2005-10-30 15:00:06 -0800 | [diff] [blame] | 64 | return (void *)(port + 0x10000000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | #else |
| 67 | static inline void *_port2addr_ne(unsigned long port) |
| 68 | { |
Hirokazu Takata | f3ac9fb | 2005-10-30 15:00:06 -0800 | [diff] [blame] | 69 | return (void *)(port + 0x04000000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | } |
| 71 | #endif |
| 72 | static inline void *_port2addr_usb(unsigned long port) |
| 73 | { |
| 74 | return (void *)(port + NONCACHE_OFFSET + 0x14000000); |
| 75 | } |
| 76 | static inline void delay(void) |
| 77 | { |
| 78 | __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory"); |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * NIC I/O function |
| 83 | */ |
| 84 | |
| 85 | static inline unsigned char _ne_inb(void *portp) |
| 86 | { |
| 87 | return (unsigned char) *(volatile unsigned char *)portp; |
| 88 | } |
| 89 | |
| 90 | static inline unsigned short _ne_inw(void *portp) |
| 91 | { |
| 92 | return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp); |
| 93 | } |
| 94 | |
| 95 | static inline void _ne_insb(void *portp, void * addr, unsigned long count) |
| 96 | { |
| 97 | unsigned char *buf = addr; |
| 98 | |
| 99 | while (count--) |
| 100 | *buf++ = *(volatile unsigned char *)portp; |
| 101 | } |
| 102 | |
| 103 | static inline void _ne_outb(unsigned char b, void *portp) |
| 104 | { |
| 105 | *(volatile unsigned char *)portp = (unsigned char)b; |
| 106 | } |
| 107 | |
| 108 | static inline void _ne_outw(unsigned short w, void *portp) |
| 109 | { |
| 110 | *(volatile unsigned short *)portp = cpu_to_le16(w); |
| 111 | } |
| 112 | |
| 113 | unsigned char _inb(unsigned long port) |
| 114 | { |
| 115 | if (port >= LAN_IOSTART && port < LAN_IOEND) |
| 116 | return _ne_inb(PORT2ADDR_NE(port)); |
| 117 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) |
| 118 | else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { |
| 119 | return *(volatile unsigned char *)__port2addr_ata(port); |
| 120 | } |
| 121 | #endif |
| 122 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) |
| 123 | else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { |
| 124 | unsigned char b; |
| 125 | pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0); |
| 126 | return b; |
| 127 | } else |
| 128 | #endif |
| 129 | |
| 130 | return *(volatile unsigned char *)PORT2ADDR(port); |
| 131 | } |
| 132 | |
| 133 | unsigned short _inw(unsigned long port) |
| 134 | { |
| 135 | if (port >= LAN_IOSTART && port < LAN_IOEND) |
| 136 | return _ne_inw(PORT2ADDR_NE(port)); |
| 137 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) |
| 138 | else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { |
| 139 | return *(volatile unsigned short *)__port2addr_ata(port); |
| 140 | } |
| 141 | #endif |
| 142 | #if defined(CONFIG_USB) |
| 143 | else if (port >= 0x340 && port < 0x3a0) |
| 144 | return *(volatile unsigned short *)PORT2ADDR_USB(port); |
| 145 | #endif |
| 146 | |
| 147 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) |
| 148 | else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { |
| 149 | unsigned short w; |
| 150 | pcc_ioread_word(0, port, &w, sizeof(w), 1, 0); |
| 151 | return w; |
| 152 | } else |
| 153 | #endif |
| 154 | return *(volatile unsigned short *)PORT2ADDR(port); |
| 155 | } |
| 156 | |
| 157 | unsigned long _inl(unsigned long port) |
| 158 | { |
| 159 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) |
| 160 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { |
| 161 | unsigned long l; |
| 162 | pcc_ioread_word(0, port, &l, sizeof(l), 1, 0); |
| 163 | return l; |
| 164 | } else |
| 165 | #endif |
| 166 | return *(volatile unsigned long *)PORT2ADDR(port); |
| 167 | } |
| 168 | |
| 169 | unsigned char _inb_p(unsigned long port) |
| 170 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 171 | unsigned char v = _inb(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | delay(); |
| 173 | return (v); |
| 174 | } |
| 175 | |
| 176 | unsigned short _inw_p(unsigned long port) |
| 177 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 178 | unsigned short v = _inw(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | delay(); |
| 180 | return (v); |
| 181 | } |
| 182 | |
| 183 | unsigned long _inl_p(unsigned long port) |
| 184 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 185 | unsigned long v = _inl(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | delay(); |
| 187 | return (v); |
| 188 | } |
| 189 | |
| 190 | void _outb(unsigned char b, unsigned long port) |
| 191 | { |
| 192 | if (port >= LAN_IOSTART && port < LAN_IOEND) |
| 193 | _ne_outb(b, PORT2ADDR_NE(port)); |
| 194 | else |
| 195 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) |
| 196 | if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { |
| 197 | *(volatile unsigned char *)__port2addr_ata(port) = b; |
| 198 | } else |
| 199 | #endif |
| 200 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) |
| 201 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { |
| 202 | pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0); |
| 203 | } else |
| 204 | #endif |
| 205 | *(volatile unsigned char *)PORT2ADDR(port) = b; |
| 206 | } |
| 207 | |
| 208 | void _outw(unsigned short w, unsigned long port) |
| 209 | { |
| 210 | if (port >= LAN_IOSTART && port < LAN_IOEND) |
| 211 | _ne_outw(w, PORT2ADDR_NE(port)); |
| 212 | else |
| 213 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) |
| 214 | if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { |
| 215 | *(volatile unsigned short *)__port2addr_ata(port) = w; |
| 216 | } else |
| 217 | #endif |
| 218 | #if defined(CONFIG_USB) |
| 219 | if (port >= 0x340 && port < 0x3a0) |
| 220 | *(volatile unsigned short *)PORT2ADDR_USB(port) = w; |
| 221 | else |
| 222 | #endif |
| 223 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) |
| 224 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { |
| 225 | pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0); |
| 226 | } else |
| 227 | #endif |
| 228 | *(volatile unsigned short *)PORT2ADDR(port) = w; |
| 229 | } |
| 230 | |
| 231 | void _outl(unsigned long l, unsigned long port) |
| 232 | { |
| 233 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) |
| 234 | if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { |
| 235 | pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0); |
| 236 | } else |
| 237 | #endif |
| 238 | *(volatile unsigned long *)PORT2ADDR(port) = l; |
| 239 | } |
| 240 | |
| 241 | void _outb_p(unsigned char b, unsigned long port) |
| 242 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 243 | _outb(b, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | delay(); |
| 245 | } |
| 246 | |
| 247 | void _outw_p(unsigned short w, unsigned long port) |
| 248 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 249 | _outw(w, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | delay(); |
| 251 | } |
| 252 | |
| 253 | void _outl_p(unsigned long l, unsigned long port) |
| 254 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 255 | _outl(l, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | delay(); |
| 257 | } |
| 258 | |
| 259 | void _insb(unsigned int port, void * addr, unsigned long count) |
| 260 | { |
| 261 | if (port >= LAN_IOSTART && port < LAN_IOEND) |
| 262 | _ne_insb(PORT2ADDR_NE(port), addr, count); |
| 263 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) |
| 264 | else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { |
| 265 | unsigned char *buf = addr; |
| 266 | unsigned char *portp = __port2addr_ata(port); |
| 267 | while (count--) |
| 268 | *buf++ = *(volatile unsigned char *)portp; |
| 269 | } |
| 270 | #endif |
| 271 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) |
| 272 | else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { |
| 273 | pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char), |
| 274 | count, 1); |
| 275 | } |
| 276 | #endif |
| 277 | else { |
| 278 | unsigned char *buf = addr; |
| 279 | unsigned char *portp = PORT2ADDR(port); |
| 280 | while (count--) |
| 281 | *buf++ = *(volatile unsigned char *)portp; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | void _insw(unsigned int port, void * addr, unsigned long count) |
| 286 | { |
| 287 | unsigned short *buf = addr; |
| 288 | unsigned short *portp; |
| 289 | |
| 290 | if (port >= LAN_IOSTART && port < LAN_IOEND) { |
| 291 | portp = PORT2ADDR_NE(port); |
| 292 | while (count--) |
| 293 | *buf++ = *(volatile unsigned short *)portp; |
| 294 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) |
| 295 | } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { |
| 296 | pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short), |
| 297 | count, 1); |
| 298 | #endif |
| 299 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) |
| 300 | } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { |
| 301 | portp = __port2addr_ata(port); |
| 302 | while (count--) |
| 303 | *buf++ = *(volatile unsigned short *)portp; |
| 304 | #endif |
| 305 | } else { |
| 306 | portp = PORT2ADDR(port); |
| 307 | while (count--) |
| 308 | *buf++ = *(volatile unsigned short *)portp; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | void _insl(unsigned int port, void * addr, unsigned long count) |
| 313 | { |
| 314 | unsigned long *buf = addr; |
| 315 | unsigned long *portp; |
| 316 | |
| 317 | portp = PORT2ADDR(port); |
| 318 | while (count--) |
| 319 | *buf++ = *(volatile unsigned long *)portp; |
| 320 | } |
| 321 | |
| 322 | void _outsb(unsigned int port, const void * addr, unsigned long count) |
| 323 | { |
| 324 | const unsigned char *buf = addr; |
| 325 | unsigned char *portp; |
| 326 | |
| 327 | if (port >= LAN_IOSTART && port < LAN_IOEND) { |
| 328 | portp = PORT2ADDR_NE(port); |
| 329 | while (count--) |
| 330 | _ne_outb(*buf++, portp); |
| 331 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) |
| 332 | } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { |
| 333 | portp = __port2addr_ata(port); |
| 334 | while (count--) |
| 335 | *(volatile unsigned char *)portp = *buf++; |
| 336 | #endif |
| 337 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) |
| 338 | } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { |
| 339 | pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char), |
| 340 | count, 1); |
| 341 | #endif |
| 342 | } else { |
| 343 | portp = PORT2ADDR(port); |
| 344 | while (count--) |
| 345 | *(volatile unsigned char *)portp = *buf++; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | void _outsw(unsigned int port, const void * addr, unsigned long count) |
| 350 | { |
| 351 | const unsigned short *buf = addr; |
| 352 | unsigned short *portp; |
| 353 | |
| 354 | if (port >= LAN_IOSTART && port < LAN_IOEND) { |
| 355 | portp = PORT2ADDR_NE(port); |
| 356 | while (count--) |
| 357 | *(volatile unsigned short *)portp = *buf++; |
| 358 | #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC) |
| 359 | } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) { |
| 360 | portp = __port2addr_ata(port); |
| 361 | while (count--) |
| 362 | *(volatile unsigned short *)portp = *buf++; |
| 363 | #endif |
| 364 | #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) |
| 365 | } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { |
| 366 | pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short), |
| 367 | count, 1); |
| 368 | #endif |
| 369 | } else { |
| 370 | portp = PORT2ADDR(port); |
| 371 | while (count--) |
| 372 | *(volatile unsigned short *)portp = *buf++; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | void _outsl(unsigned int port, const void * addr, unsigned long count) |
| 377 | { |
| 378 | const unsigned long *buf = addr; |
| 379 | unsigned char *portp; |
| 380 | |
| 381 | portp = PORT2ADDR(port); |
| 382 | while (count--) |
| 383 | *(volatile unsigned long *)portp = *buf++; |
| 384 | } |