Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / m32r / platforms / m32104ut / io.c
blobff2bb3b58bb5e5b6c8cf0fc0ce1f792141c46a5b
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/arch/m32r/platforms/m32104ut/io.c
5 * Typical I/O routines for M32104UT board.
7 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
8 * Hitoshi Yamamoto, Mamoru Sakugawa,
9 * Naoto Sugai, Hayato Fujiwara
12 #include <asm/m32r.h>
13 #include <asm/page.h>
14 #include <asm/io.h>
15 #include <asm/byteorder.h>
17 #if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
18 #include <linux/types.h>
20 #define M32R_PCC_IOMAP_SIZE 0x1000
22 #define M32R_PCC_IOSTART0 0x1000
23 #define M32R_PCC_IOEND0 (M32R_PCC_IOSTART0 + M32R_PCC_IOMAP_SIZE - 1)
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 */
31 #define PORT2ADDR(port) _port2addr(port)
33 static inline void *_port2addr(unsigned long port)
35 return (void *)(port | NONCACHE_OFFSET);
38 #if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
39 static inline void *__port2addr_ata(unsigned long port)
41 static int dummy_reg;
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;
56 #endif
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.
63 #define LAN_IOSTART (0x300 | NONCACHE_OFFSET)
64 #define LAN_IOEND (0x320 | NONCACHE_OFFSET)
65 static inline void *_port2addr_ne(unsigned long port)
67 return (void *)(port + NONCACHE_OFFSET + 0x01000000);
70 static inline void delay(void)
72 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
76 * NIC I/O function
79 #define PORT2ADDR_NE(port) _port2addr_ne(port)
81 static inline unsigned char _ne_inb(void *portp)
83 return *(volatile unsigned char *)portp;
86 static inline unsigned short _ne_inw(void *portp)
88 return (unsigned short)le16_to_cpu(*(volatile unsigned short *)portp);
91 static inline void _ne_insb(void *portp, void *addr, unsigned long count)
93 unsigned char *buf = (unsigned char *)addr;
95 while (count--)
96 *buf++ = _ne_inb(portp);
99 static inline void _ne_outb(unsigned char b, void *portp)
101 *(volatile unsigned char *)portp = b;
104 static inline void _ne_outw(unsigned short w, void *portp)
106 *(volatile unsigned short *)portp = cpu_to_le16(w);
109 unsigned char _inb(unsigned long port)
111 if (port >= LAN_IOSTART && port < LAN_IOEND)
112 return _ne_inb(PORT2ADDR_NE(port));
114 return *(volatile unsigned char *)PORT2ADDR(port);
117 unsigned short _inw(unsigned long port)
119 if (port >= LAN_IOSTART && port < LAN_IOEND)
120 return _ne_inw(PORT2ADDR_NE(port));
122 return *(volatile unsigned short *)PORT2ADDR(port);
125 unsigned long _inl(unsigned long port)
127 return *(volatile unsigned long *)PORT2ADDR(port);
130 unsigned char _inb_p(unsigned long port)
132 unsigned char v = _inb(port);
133 delay();
134 return (v);
137 unsigned short _inw_p(unsigned long port)
139 unsigned short v = _inw(port);
140 delay();
141 return (v);
144 unsigned long _inl_p(unsigned long port)
146 unsigned long v = _inl(port);
147 delay();
148 return (v);
151 void _outb(unsigned char b, unsigned long port)
153 if (port >= LAN_IOSTART && port < LAN_IOEND)
154 _ne_outb(b, PORT2ADDR_NE(port));
155 else
156 *(volatile unsigned char *)PORT2ADDR(port) = b;
159 void _outw(unsigned short w, unsigned long port)
161 if (port >= LAN_IOSTART && port < LAN_IOEND)
162 _ne_outw(w, PORT2ADDR_NE(port));
163 else
164 *(volatile unsigned short *)PORT2ADDR(port) = w;
167 void _outl(unsigned long l, unsigned long port)
169 *(volatile unsigned long *)PORT2ADDR(port) = l;
172 void _outb_p(unsigned char b, unsigned long port)
174 _outb(b, port);
175 delay();
178 void _outw_p(unsigned short w, unsigned long port)
180 _outw(w, port);
181 delay();
184 void _outl_p(unsigned long l, unsigned long port)
186 _outl(l, port);
187 delay();
190 void _insb(unsigned int port, void *addr, unsigned long count)
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;
202 void _insw(unsigned int port, void *addr, unsigned long count)
204 unsigned short *buf = addr;
205 unsigned short *portp;
207 if (port >= LAN_IOSTART && port < LAN_IOEND) {
209 * This portion is only used by smc91111.c to read data
210 * from the DATA_REG. Do not swap the data.
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;
233 void _insl(unsigned int port, void *addr, unsigned long count)
235 unsigned long *buf = addr;
236 unsigned long *portp;
238 portp = PORT2ADDR(port);
239 while (count--)
240 *buf++ = *(volatile unsigned long *)portp;
243 void _outsb(unsigned int port, const void *addr, unsigned long count)
245 const unsigned char *buf = addr;
246 unsigned char *portp;
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++;
259 void _outsw(unsigned int port, const void *addr, unsigned long count)
261 const unsigned short *buf = addr;
262 unsigned short *portp;
264 if (port >= LAN_IOSTART && port < LAN_IOEND) {
266 * This portion is only used by smc91111.c to write data
267 * into the DATA_REG. Do not swap the data.
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++;
290 void _outsl(unsigned int port, const void *addr, unsigned long count)
292 const unsigned long *buf = addr;
293 unsigned char *portp;
295 portp = PORT2ADDR(port);
296 while (count--)
297 *(volatile unsigned long *)portp = *buf++;