blob: 286964794d5158bc58e666c0cbf8664a92781db4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m32r/kernel/io_oaks32r.c
3 *
4 * Typical I/O routines for OAKS32R board.
5 *
6 * Copyright (c) 2001-2004 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
15#define PORT2ADDR(port) _port2addr(port)
16
17static inline void *_port2addr(unsigned long port)
18{
19 return (void *)(port + NONCACHE_OFFSET);
20}
21
22static inline void *_port2addr_ne(unsigned long port)
23{
24 return (void *)((port<<1) + NONCACHE_OFFSET + 0x02000000);
25}
26
27static 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
38static inline unsigned char _ne_inb(void *portp)
39{
40 return *(volatile unsigned char *)(portp+1);
41}
42
43static 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
52static 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
59static inline void _ne_outb(unsigned char b, void *portp)
60{
61 *(volatile unsigned char *)(portp+1) = b;
62}
63
64static 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
70unsigned 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
78unsigned 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
86unsigned long _inl(unsigned long port)
87{
88 return *(volatile unsigned long *)PORT2ADDR(port);
89}
90
91unsigned char _inb_p(unsigned long port)
92{
93 unsigned char v;
94
95 if (port >= 0x300 && port < 0x320)
96 v = _ne_inb(PORT2ADDR_NE(port));
97 else
98 v = *(volatile unsigned char *)PORT2ADDR(port);
99
100 delay();
101 return (v);
102}
103
104unsigned short _inw_p(unsigned long port)
105{
106 unsigned short v;
107
108 if (port >= 0x300 && port < 0x320)
109 v = _ne_inw(PORT2ADDR_NE(port));
110 else
111 v = *(volatile unsigned short *)PORT2ADDR(port);
112
113 delay();
114 return (v);
115}
116
117unsigned long _inl_p(unsigned long port)
118{
119 unsigned long v;
120
121 v = *(volatile unsigned long *)PORT2ADDR(port);
122 delay();
123 return (v);
124}
125
126void _outb(unsigned char b, unsigned long port)
127{
128 if (port >= 0x300 && port < 0x320)
129 _ne_outb(b, PORT2ADDR_NE(port));
130 else
131 *(volatile unsigned char *)PORT2ADDR(port) = b;
132}
133
134void _outw(unsigned short w, unsigned long port)
135{
136 if (port >= 0x300 && port < 0x320)
137 _ne_outw(w, PORT2ADDR_NE(port));
138 else
139 *(volatile unsigned short *)PORT2ADDR(port) = w;
140}
141
142void _outl(unsigned long l, unsigned long port)
143{
144 *(volatile unsigned long *)PORT2ADDR(port) = l;
145}
146
147void _outb_p(unsigned char b, unsigned long port)
148{
149 if (port >= 0x300 && port < 0x320)
150 _ne_outb(b, PORT2ADDR_NE(port));
151 else
152 *(volatile unsigned char *)PORT2ADDR(port) = b;
153
154 delay();
155}
156
157void _outw_p(unsigned short w, unsigned long port)
158{
159 if (port >= 0x300 && port < 0x320)
160 _ne_outw(w, PORT2ADDR_NE(port));
161 else
162 *(volatile unsigned short *)PORT2ADDR(port) = w;
163
164 delay();
165}
166
167void _outl_p(unsigned long l, unsigned long port)
168{
169 *(volatile unsigned long *)PORT2ADDR(port) = l;
170 delay();
171}
172
173void _insb(unsigned int port, void *addr, unsigned long count)
174{
175 if (port >= 0x300 && port < 0x320)
176 _ne_insb(PORT2ADDR_NE(port), addr, count);
177 else {
178 unsigned char *buf = addr;
179 unsigned char *portp = PORT2ADDR(port);
180 while (count--)
181 *buf++ = *(volatile unsigned char *)portp;
182 }
183}
184
185void _insw(unsigned int port, void *addr, unsigned long count)
186{
187 unsigned short *buf = addr;
188 unsigned short *portp;
189
190 if (port >= 0x300 && port < 0x320) {
191 portp = PORT2ADDR_NE(port);
192 while (count--)
193 *buf++ = _ne_inw(portp);
194 } else {
195 portp = PORT2ADDR(port);
196 while (count--)
197 *buf++ = *(volatile unsigned short *)portp;
198 }
199}
200
201void _insl(unsigned int port, void *addr, unsigned long count)
202{
203 unsigned long *buf = addr;
204 unsigned long *portp;
205
206 portp = PORT2ADDR(port);
207 while (count--)
208 *buf++ = *(volatile unsigned long *)portp;
209}
210
211void _outsb(unsigned int port, const void *addr, unsigned long count)
212{
213 const unsigned char *buf = addr;
214 unsigned char *portp;
215
216 if (port >= 0x300 && port < 0x320) {
217 portp = PORT2ADDR_NE(port);
218 while (count--)
219 _ne_outb(*buf++, portp);
220 } else {
221 portp = PORT2ADDR(port);
222 while (count--)
223 *(volatile unsigned char *)portp = *buf++;
224 }
225}
226
227void _outsw(unsigned int port, const void *addr, unsigned long count)
228{
229 const unsigned short *buf = addr;
230 unsigned short *portp;
231
232 if (port >= 0x300 && port < 0x320) {
233 portp = PORT2ADDR_NE(port);
234 while (count--)
235 _ne_outw(*buf++, portp);
236 } else {
237 portp = PORT2ADDR(port);
238 while (count--)
239 *(volatile unsigned short *)portp = *buf++;
240 }
241}
242
243void _outsl(unsigned int port, const void *addr, unsigned long count)
244{
245 const unsigned long *buf = addr;
246 unsigned char *portp;
247
248 portp = PORT2ADDR(port);
249 while (count--)
250 *(volatile unsigned long *)portp = *buf++;
251}