]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - arch/m32r/platforms/oaks32r/io.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[mirror_ubuntu-eoan-kernel.git] / arch / m32r / platforms / oaks32r / io.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
1da177e4 2/*
3264f976 3 * linux/arch/m32r/platforms/oaks32r/io.c
1da177e4
LT
4 *
5 * Typical I/O routines for OAKS32R board.
6 *
23680863 7 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
1da177e4
LT
8 * Hitoshi Yamamoto, Mamoru Sakugawa
9 */
10
1da177e4
LT
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{
46ea178b 19 return (void *)(port | NONCACHE_OFFSET);
1da177e4
LT
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{
23680863 93 unsigned char v = _inb(port);
1da177e4
LT
94 delay();
95 return (v);
96}
97
98unsigned short _inw_p(unsigned long port)
99{
23680863 100 unsigned short v = _inw(port);
1da177e4
LT
101 delay();
102 return (v);
103}
104
105unsigned long _inl_p(unsigned long port)
106{
23680863 107 unsigned long v = _inl(port);
1da177e4
LT
108 delay();
109 return (v);
110}
111
112void _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
120void _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
128void _outl(unsigned long l, unsigned long port)
129{
130 *(volatile unsigned long *)PORT2ADDR(port) = l;
131}
132
133void _outb_p(unsigned char b, unsigned long port)
134{
23680863 135 _outb(b, port);
1da177e4
LT
136 delay();
137}
138
139void _outw_p(unsigned short w, unsigned long port)
140{
23680863 141 _outw(w, port);
1da177e4
LT
142 delay();
143}
144
145void _outl_p(unsigned long l, unsigned long port)
146{
23680863 147 _outl(l, port);
1da177e4
LT
148 delay();
149}
150
151void _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
163void _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
179void _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
189void _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
205void _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
221void _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}