]> git.ipfire.org Git - thirdparty/kernel/linux.git/blame - arch/m32r/platforms/mappi/io.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[thirdparty/kernel/linux.git] / arch / m32r / platforms / mappi / io.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4 2/*
3264f976 3 * linux/arch/m32r/platforms/mappi/io.c
1da177e4
LT
4 *
5 * Typical I/O routines for Mappi board.
6 *
23680863
HT
7 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
8 * Hitoshi Yamamoto
1da177e4
LT
9 */
10
1da177e4
LT
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_PCC)
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#define M32R_PCC_IOSTART1 0x2000
24#define M32R_PCC_IOEND1 (M32R_PCC_IOSTART1 + M32R_PCC_IOMAP_SIZE - 1)
25
26extern void pcc_ioread(int, unsigned long, void *, size_t, size_t, int);
27extern void pcc_iowrite(int, unsigned long, void *, size_t, size_t, int);
28#endif /* CONFIG_PCMCIA && CONFIG_M32R_PCC */
29
30#define PORT2ADDR(port) _port2addr(port)
31
32static inline void *_port2addr(unsigned long port)
33{
46ea178b 34 return (void *)(port | NONCACHE_OFFSET);
1da177e4
LT
35}
36
37static inline void *_port2addr_ne(unsigned long port)
38{
39 return (void *)((port<<1) + NONCACHE_OFFSET + 0x0C000000);
40}
41
42static inline void delay(void)
43{
44 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
45}
46
47/*
48 * NIC I/O function
49 */
50
51#define PORT2ADDR_NE(port) _port2addr_ne(port)
52
53static inline unsigned char _ne_inb(void *portp)
54{
55 return (unsigned char) *(volatile unsigned short *)portp;
56}
57
58static inline unsigned short _ne_inw(void *portp)
59{
60 unsigned short tmp;
61
62 tmp = *(volatile unsigned short *)portp;
63 return le16_to_cpu(tmp);
64}
65
66static inline void _ne_outb(unsigned char b, void *portp)
67{
68 *(volatile unsigned short *)portp = (unsigned short)b;
69}
70
71static inline void _ne_outw(unsigned short w, void *portp)
72{
73 *(volatile unsigned short *)portp = cpu_to_le16(w);
74}
75
76unsigned char _inb(unsigned long port)
77{
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
92
93 return *(volatile unsigned char *)PORT2ADDR(port);
94}
95
96unsigned short _inw(unsigned long port)
97{
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);
113}
114
115unsigned long _inl(unsigned long port)
116{
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);
129}
130
131unsigned char _inb_p(unsigned long port)
132{
23680863 133 unsigned char v = _inb(port);
1da177e4
LT
134 delay();
135 return (v);
136}
137
138unsigned short _inw_p(unsigned long port)
139{
23680863 140 unsigned short v = _inw(port);
1da177e4
LT
141 delay();
142 return (v);
143}
144
145unsigned long _inl_p(unsigned long port)
146{
23680863 147 unsigned long v = _inl(port);
1da177e4
LT
148 delay();
149 return (v);
150}
151
152void _outb(unsigned char b, unsigned long port)
153{
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;
165}
166
167void _outw(unsigned short w, unsigned long port)
168{
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;
180}
181
182void _outl(unsigned long l, unsigned long port)
183{
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;
192}
193
194void _outb_p(unsigned char b, unsigned long port)
195{
23680863 196 _outb(b, port);
1da177e4
LT
197 delay();
198}
199
200void _outw_p(unsigned short w, unsigned long port)
201{
23680863 202 _outw(w, port);
1da177e4
LT
203 delay();
204}
205
206void _outl_p(unsigned long l, unsigned long port)
207{
23680863 208 _outl(l, port);
1da177e4
LT
209 delay();
210}
211
212void _insb(unsigned int port, void *addr, unsigned long count)
213{
214 unsigned short *buf = addr;
215 unsigned short *portp;
216
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;
233 }
234}
235
236void _insw(unsigned int port, void *addr, unsigned long count)
237{
238 unsigned short *buf = addr;
239 unsigned short *portp;
240
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;
257 }
258}
259
260void _insl(unsigned int port, void *addr, unsigned long count)
261{
262 unsigned long *buf = addr;
263 unsigned long *portp;
264
265 portp = PORT2ADDR(port);
266 while (count--)
267 *buf++ = *(volatile unsigned long *)portp;
268}
269
270void _outsb(unsigned int port, const void *addr, unsigned long count)
271{
272 const unsigned char *buf = addr;
273 unsigned char *portp;
274
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++;
291 }
292}
293
294void _outsw(unsigned int port, const void *addr, unsigned long count)
295{
296 const unsigned short *buf = addr;
297 unsigned short *portp;
298
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++;
315 }
316}
317
318void _outsl(unsigned int port, const void *addr, unsigned long count)
319{
320 const unsigned long *buf = addr;
321 unsigned char *portp;
322
323 portp = PORT2ADDR(port);
324 while (count--)
325 *(volatile unsigned long *)portp = *buf++;
326}