]> git.ipfire.org Git - people/arne_f/kernel.git/blob - arch/m32r/platforms/m32104ut/io.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[people/arne_f/kernel.git] / arch / m32r / platforms / m32104ut / io.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/arch/m32r/platforms/m32104ut/io.c
4 *
5 * Typical I/O routines for M32104UT board.
6 *
7 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
8 * Hitoshi Yamamoto, Mamoru Sakugawa,
9 * Naoto Sugai, Hayato Fujiwara
10 */
11
12 #include <asm/m32r.h>
13 #include <asm/page.h>
14 #include <asm/io.h>
15 #include <asm/byteorder.h>
16
17 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
18 #include <linux/types.h>
19
20 #define M32R_PCC_IOMAP_SIZE 0x1000
21
22 #define M32R_PCC_IOSTART0 0x1000
23 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
24
25 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
26 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
27 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
28 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
29 #endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
30
31 #define PORT2ADDR(port) _port2addr(port)
32
33 static inline void *_port2addr(unsigned long port)
34 {
35 return (void *)(port | NONCACHE_OFFSET);
36 }
37
38 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
39 static inline void *__port2addr_ata(unsigned long port)
40 {
41 static int dummy_reg;
42
43 switch (port) {
44 case 0x1f0: return (void *)(0x0c002000 | NONCACHE_OFFSET);
45 case 0x1f1: return (void *)(0x0c012800 | NONCACHE_OFFSET);
46 case 0x1f2: return (void *)(0x0c012002 | NONCACHE_OFFSET);
47 case 0x1f3: return (void *)(0x0c012802 | NONCACHE_OFFSET);
48 case 0x1f4: return (void *)(0x0c012004 | NONCACHE_OFFSET);
49 case 0x1f5: return (void *)(0x0c012804 | NONCACHE_OFFSET);
50 case 0x1f6: return (void *)(0x0c012006 | NONCACHE_OFFSET);
51 case 0x1f7: return (void *)(0x0c012806 | NONCACHE_OFFSET);
52 case 0x3f6: return (void *)(0x0c01200e | NONCACHE_OFFSET);
53 default: return (void *)&dummy_reg;
54 }
55 }
56 #endif
57
58 /*
59 * M32104T-LAN is located in the extended bus space
60 * from 0x01000000 to 0x01ffffff on physical address.
61 * The base address of LAN controller(LAN91C111) is 0x300.
62 */
63 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
64 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
65 static inline void *_port2addr_ne(unsigned long port)
66 {
67 return (void *)(port + NONCACHE_OFFSET + 0x01000000);
68 }
69
70 static inline void delay(void)
71 {
72 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
73 }
74
75 /*
76 * NIC I/O function
77 */
78
79 #define PORT2ADDR_NE(port) _port2addr_ne(port)
80
81 static inline unsigned char _ne_inb(void *portp)
82 {
83 return *(volatile unsigned char *)portp;
84 }
85
86 static inline unsigned short _ne_inw(void *portp)
87 {
88 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
89 }
90
91 static inline void _ne_insb(void *portp, void *addr, unsigned long count)
92 {
93 unsigned char *buf = (unsigned char *)addr;
94
95 while (count--)
96 *buf++ = _ne_inb(portp);
97 }
98
99 static inline void _ne_outb(unsigned char b, void *portp)
100 {
101 *(volatile unsigned char *)portp = b;
102 }
103
104 static inline void _ne_outw(unsigned short w, void *portp)
105 {
106 *(volatile unsigned short *)portp = cpu_to_le16(w);
107 }
108
109 unsigned char _inb(unsigned long port)
110 {
111 if (port >= LAN_IOSTART && port < LAN_IOEND)
112 return _ne_inb(PORT2ADDR_NE(port));
113
114 return *(volatile unsigned char *)PORT2ADDR(port);
115 }
116
117 unsigned short _inw(unsigned long port)
118 {
119 if (port >= LAN_IOSTART && port < LAN_IOEND)
120 return _ne_inw(PORT2ADDR_NE(port));
121
122 return *(volatile unsigned short *)PORT2ADDR(port);
123 }
124
125 unsigned long _inl(unsigned long port)
126 {
127 return *(volatile unsigned long *)PORT2ADDR(port);
128 }
129
130 unsigned char _inb_p(unsigned long port)
131 {
132 unsigned char v = _inb(port);
133 delay();
134 return (v);
135 }
136
137 unsigned short _inw_p(unsigned long port)
138 {
139 unsigned short v = _inw(port);
140 delay();
141 return (v);
142 }
143
144 unsigned long _inl_p(unsigned long port)
145 {
146 unsigned long v = _inl(port);
147 delay();
148 return (v);
149 }
150
151 void _outb(unsigned char b, unsigned long port)
152 {
153 if (port >= LAN_IOSTART && port < LAN_IOEND)
154 _ne_outb(b, PORT2ADDR_NE(port));
155 else
156 *(volatile unsigned char *)PORT2ADDR(port) = b;
157 }
158
159 void _outw(unsigned short w, unsigned long port)
160 {
161 if (port >= LAN_IOSTART && port < LAN_IOEND)
162 _ne_outw(w, PORT2ADDR_NE(port));
163 else
164 *(volatile unsigned short *)PORT2ADDR(port) = w;
165 }
166
167 void _outl(unsigned long l, unsigned long port)
168 {
169 *(volatile unsigned long *)PORT2ADDR(port) = l;
170 }
171
172 void _outb_p(unsigned char b, unsigned long port)
173 {
174 _outb(b, port);
175 delay();
176 }
177
178 void _outw_p(unsigned short w, unsigned long port)
179 {
180 _outw(w, port);
181 delay();
182 }
183
184 void _outl_p(unsigned long l, unsigned long port)
185 {
186 _outl(l, port);
187 delay();
188 }
189
190 void _insb(unsigned int port, void *addr, unsigned long count)
191 {
192 if (port >= LAN_IOSTART && port < LAN_IOEND)
193 _ne_insb(PORT2ADDR_NE(port), addr, count);
194 else {
195 unsigned char *buf = addr;
196 unsigned char *portp = PORT2ADDR(port);
197 while (count--)
198 *buf++ = *(volatile unsigned char *)portp;
199 }
200 }
201
202 void _insw(unsigned int port, void *addr, unsigned long count)
203 {
204 unsigned short *buf = addr;
205 unsigned short *portp;
206
207 if (port >= LAN_IOSTART && port < LAN_IOEND) {
208 /*
209 * This portion is only used by smc91111.c to read data
210 * from the DATA_REG. Do not swap the data.
211 */
212 portp = PORT2ADDR_NE(port);
213 while (count--)
214 *buf++ = *(volatile unsigned short *)portp;
215 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
216 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
217 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
218 count, 1);
219 #endif
220 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
221 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
222 portp = __port2addr_ata(port);
223 while (count--)
224 *buf++ = *(volatile unsigned short *)portp;
225 #endif
226 } else {
227 portp = PORT2ADDR(port);
228 while (count--)
229 *buf++ = *(volatile unsigned short *)portp;
230 }
231 }
232
233 void _insl(unsigned int port, void *addr, unsigned long count)
234 {
235 unsigned long *buf = addr;
236 unsigned long *portp;
237
238 portp = PORT2ADDR(port);
239 while (count--)
240 *buf++ = *(volatile unsigned long *)portp;
241 }
242
243 void _outsb(unsigned int port, const void *addr, unsigned long count)
244 {
245 const unsigned char *buf = addr;
246 unsigned char *portp;
247
248 if (port >= LAN_IOSTART && port < LAN_IOEND) {
249 portp = PORT2ADDR_NE(port);
250 while (count--)
251 _ne_outb(*buf++, portp);
252 } else {
253 portp = PORT2ADDR(port);
254 while (count--)
255 *(volatile unsigned char *)portp = *buf++;
256 }
257 }
258
259 void _outsw(unsigned int port, const void *addr, unsigned long count)
260 {
261 const unsigned short *buf = addr;
262 unsigned short *portp;
263
264 if (port >= LAN_IOSTART && port < LAN_IOEND) {
265 /*
266 * This portion is only used by smc91111.c to write data
267 * into the DATA_REG. Do not swap the data.
268 */
269 portp = PORT2ADDR_NE(port);
270 while (count--)
271 *(volatile unsigned short *)portp = *buf++;
272 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
273 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
274 portp = __port2addr_ata(port);
275 while (count--)
276 *(volatile unsigned short *)portp = *buf++;
277 #endif
278 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
279 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
280 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
281 count, 1);
282 #endif
283 } else {
284 portp = PORT2ADDR(port);
285 while (count--)
286 *(volatile unsigned short *)portp = *buf++;
287 }
288 }
289
290 void _outsl(unsigned int port, const void *addr, unsigned long count)
291 {
292 const unsigned long *buf = addr;
293 unsigned char *portp;
294
295 portp = PORT2ADDR(port);
296 while (count--)
297 *(volatile unsigned long *)portp = *buf++;
298 }