Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/m32r/kernel/io_oaks32r.c |
| 3 | * |
| 4 | * Typical I/O routines for OAKS32R board. |
| 5 | * |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 6 | * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 15 | #define PORT2ADDR(port) _port2addr(port) |
| 16 | |
| 17 | static inline void *_port2addr(unsigned long port) |
| 18 | { |
Hirokazu Takata | 46ea178 | 2006-01-06 00:18:43 -0800 | [diff] [blame] | 19 | return (void *)(port | NONCACHE_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | static inline void *_port2addr_ne(unsigned long port) |
| 23 | { |
| 24 | return (void *)((port<<1) + NONCACHE_OFFSET + 0x02000000); |
| 25 | } |
| 26 | |
| 27 | static inline void delay(void) |
| 28 | { |
| 29 | __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory"); |
| 30 | } |
| 31 | |
| 32 | /* |
| 33 | * NIC I/O function |
| 34 | */ |
| 35 | |
| 36 | #define PORT2ADDR_NE(port) _port2addr_ne(port) |
| 37 | |
| 38 | static inline unsigned char _ne_inb(void *portp) |
| 39 | { |
| 40 | return *(volatile unsigned char *)(portp+1); |
| 41 | } |
| 42 | |
| 43 | static inline unsigned short _ne_inw(void *portp) |
| 44 | { |
| 45 | unsigned short tmp; |
| 46 | |
| 47 | tmp = *(unsigned short *)(portp) & 0xff; |
| 48 | tmp |= *(unsigned short *)(portp+2) << 8; |
| 49 | return tmp; |
| 50 | } |
| 51 | |
| 52 | static inline void _ne_insb(void *portp, void *addr, unsigned long count) |
| 53 | { |
| 54 | unsigned char *buf = addr; |
| 55 | while (count--) |
| 56 | *buf++ = *(volatile unsigned char *)(portp+1); |
| 57 | } |
| 58 | |
| 59 | static inline void _ne_outb(unsigned char b, void *portp) |
| 60 | { |
| 61 | *(volatile unsigned char *)(portp+1) = b; |
| 62 | } |
| 63 | |
| 64 | static inline void _ne_outw(unsigned short w, void *portp) |
| 65 | { |
| 66 | *(volatile unsigned short *)portp = (w >> 8); |
| 67 | *(volatile unsigned short *)(portp+2) = (w & 0xff); |
| 68 | } |
| 69 | |
| 70 | unsigned char _inb(unsigned long port) |
| 71 | { |
| 72 | if (port >= 0x300 && port < 0x320) |
| 73 | return _ne_inb(PORT2ADDR_NE(port)); |
| 74 | |
| 75 | return *(volatile unsigned char *)PORT2ADDR(port); |
| 76 | } |
| 77 | |
| 78 | unsigned short _inw(unsigned long port) |
| 79 | { |
| 80 | if (port >= 0x300 && port < 0x320) |
| 81 | return _ne_inw(PORT2ADDR_NE(port)); |
| 82 | |
| 83 | return *(volatile unsigned short *)PORT2ADDR(port); |
| 84 | } |
| 85 | |
| 86 | unsigned long _inl(unsigned long port) |
| 87 | { |
| 88 | return *(volatile unsigned long *)PORT2ADDR(port); |
| 89 | } |
| 90 | |
| 91 | unsigned char _inb_p(unsigned long port) |
| 92 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 93 | unsigned char v = _inb(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | delay(); |
| 95 | return (v); |
| 96 | } |
| 97 | |
| 98 | unsigned short _inw_p(unsigned long port) |
| 99 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 100 | unsigned short v = _inw(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | delay(); |
| 102 | return (v); |
| 103 | } |
| 104 | |
| 105 | unsigned long _inl_p(unsigned long port) |
| 106 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 107 | unsigned long v = _inl(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | delay(); |
| 109 | return (v); |
| 110 | } |
| 111 | |
| 112 | void _outb(unsigned char b, unsigned long port) |
| 113 | { |
| 114 | if (port >= 0x300 && port < 0x320) |
| 115 | _ne_outb(b, PORT2ADDR_NE(port)); |
| 116 | else |
| 117 | *(volatile unsigned char *)PORT2ADDR(port) = b; |
| 118 | } |
| 119 | |
| 120 | void _outw(unsigned short w, unsigned long port) |
| 121 | { |
| 122 | if (port >= 0x300 && port < 0x320) |
| 123 | _ne_outw(w, PORT2ADDR_NE(port)); |
| 124 | else |
| 125 | *(volatile unsigned short *)PORT2ADDR(port) = w; |
| 126 | } |
| 127 | |
| 128 | void _outl(unsigned long l, unsigned long port) |
| 129 | { |
| 130 | *(volatile unsigned long *)PORT2ADDR(port) = l; |
| 131 | } |
| 132 | |
| 133 | void _outb_p(unsigned char b, unsigned long port) |
| 134 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 135 | _outb(b, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | delay(); |
| 137 | } |
| 138 | |
| 139 | void _outw_p(unsigned short w, unsigned long port) |
| 140 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 141 | _outw(w, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | delay(); |
| 143 | } |
| 144 | |
| 145 | void _outl_p(unsigned long l, unsigned long port) |
| 146 | { |
Hirokazu Takata | 2368086 | 2005-06-21 17:16:10 -0700 | [diff] [blame] | 147 | _outl(l, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | delay(); |
| 149 | } |
| 150 | |
| 151 | void _insb(unsigned int port, void *addr, unsigned long count) |
| 152 | { |
| 153 | if (port >= 0x300 && port < 0x320) |
| 154 | _ne_insb(PORT2ADDR_NE(port), addr, count); |
| 155 | else { |
| 156 | unsigned char *buf = addr; |
| 157 | unsigned char *portp = PORT2ADDR(port); |
| 158 | while (count--) |
| 159 | *buf++ = *(volatile unsigned char *)portp; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | void _insw(unsigned int port, void *addr, unsigned long count) |
| 164 | { |
| 165 | unsigned short *buf = addr; |
| 166 | unsigned short *portp; |
| 167 | |
| 168 | if (port >= 0x300 && port < 0x320) { |
| 169 | portp = PORT2ADDR_NE(port); |
| 170 | while (count--) |
| 171 | *buf++ = _ne_inw(portp); |
| 172 | } else { |
| 173 | portp = PORT2ADDR(port); |
| 174 | while (count--) |
| 175 | *buf++ = *(volatile unsigned short *)portp; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | void _insl(unsigned int port, void *addr, unsigned long count) |
| 180 | { |
| 181 | unsigned long *buf = addr; |
| 182 | unsigned long *portp; |
| 183 | |
| 184 | portp = PORT2ADDR(port); |
| 185 | while (count--) |
| 186 | *buf++ = *(volatile unsigned long *)portp; |
| 187 | } |
| 188 | |
| 189 | void _outsb(unsigned int port, const void *addr, unsigned long count) |
| 190 | { |
| 191 | const unsigned char *buf = addr; |
| 192 | unsigned char *portp; |
| 193 | |
| 194 | if (port >= 0x300 && port < 0x320) { |
| 195 | portp = PORT2ADDR_NE(port); |
| 196 | while (count--) |
| 197 | _ne_outb(*buf++, portp); |
| 198 | } else { |
| 199 | portp = PORT2ADDR(port); |
| 200 | while (count--) |
| 201 | *(volatile unsigned char *)portp = *buf++; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | void _outsw(unsigned int port, const void *addr, unsigned long count) |
| 206 | { |
| 207 | const unsigned short *buf = addr; |
| 208 | unsigned short *portp; |
| 209 | |
| 210 | if (port >= 0x300 && port < 0x320) { |
| 211 | portp = PORT2ADDR_NE(port); |
| 212 | while (count--) |
| 213 | _ne_outw(*buf++, portp); |
| 214 | } else { |
| 215 | portp = PORT2ADDR(port); |
| 216 | while (count--) |
| 217 | *(volatile unsigned short *)portp = *buf++; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void _outsl(unsigned int port, const void *addr, unsigned long count) |
| 222 | { |
| 223 | const unsigned long *buf = addr; |
| 224 | unsigned char *portp; |
| 225 | |
| 226 | portp = PORT2ADDR(port); |
| 227 | while (count--) |
| 228 | *(volatile unsigned long *)portp = *buf++; |
| 229 | } |