• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *  linux/arch/m32r/platforms/oaks32r/io.c
4  *
5  *  Typical I/O routines for OAKS32R board.
6  *
7  *  Copyright (c) 2001-2005  Hiroyuki Kondo, Hirokazu Takata,
8  *                           Hitoshi Yamamoto, Mamoru Sakugawa
9  */
10 
11 #include <asm/m32r.h>
12 #include <asm/page.h>
13 #include <asm/io.h>
14 
15 #define PORT2ADDR(port)  _port2addr(port)
16 
_port2addr(unsigned long port)17 static inline void *_port2addr(unsigned long port)
18 {
19 	return (void *)(port | NONCACHE_OFFSET);
20 }
21 
_port2addr_ne(unsigned long port)22 static inline  void *_port2addr_ne(unsigned long port)
23 {
24 	return (void *)((port<<1) + NONCACHE_OFFSET + 0x02000000);
25 }
26 
delay(void)27 static 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 
_ne_inb(void * portp)38 static inline unsigned char _ne_inb(void *portp)
39 {
40 	return *(volatile unsigned char *)(portp+1);
41 }
42 
_ne_inw(void * portp)43 static 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 
_ne_insb(void * portp,void * addr,unsigned long count)52 static 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 
_ne_outb(unsigned char b,void * portp)59 static inline void _ne_outb(unsigned char b, void *portp)
60 {
61 	*(volatile unsigned char *)(portp+1) = b;
62 }
63 
_ne_outw(unsigned short w,void * portp)64 static 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 
_inb(unsigned long port)70 unsigned 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 
_inw(unsigned long port)78 unsigned 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 
_inl(unsigned long port)86 unsigned long _inl(unsigned long port)
87 {
88 	return *(volatile unsigned long *)PORT2ADDR(port);
89 }
90 
_inb_p(unsigned long port)91 unsigned char _inb_p(unsigned long port)
92 {
93 	unsigned char v = _inb(port);
94 	delay();
95 	return (v);
96 }
97 
_inw_p(unsigned long port)98 unsigned short _inw_p(unsigned long port)
99 {
100 	unsigned short v = _inw(port);
101 	delay();
102 	return (v);
103 }
104 
_inl_p(unsigned long port)105 unsigned long _inl_p(unsigned long port)
106 {
107 	unsigned long v = _inl(port);
108 	delay();
109 	return (v);
110 }
111 
_outb(unsigned char b,unsigned long port)112 void _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 
_outw(unsigned short w,unsigned long port)120 void _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 
_outl(unsigned long l,unsigned long port)128 void _outl(unsigned long l, unsigned long port)
129 {
130 	*(volatile unsigned long *)PORT2ADDR(port) = l;
131 }
132 
_outb_p(unsigned char b,unsigned long port)133 void _outb_p(unsigned char b, unsigned long port)
134 {
135 	_outb(b, port);
136 	delay();
137 }
138 
_outw_p(unsigned short w,unsigned long port)139 void _outw_p(unsigned short w, unsigned long port)
140 {
141 	_outw(w, port);
142 	delay();
143 }
144 
_outl_p(unsigned long l,unsigned long port)145 void _outl_p(unsigned long l, unsigned long port)
146 {
147 	_outl(l, port);
148 	delay();
149 }
150 
_insb(unsigned int port,void * addr,unsigned long count)151 void _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 
_insw(unsigned int port,void * addr,unsigned long count)163 void _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 
_insl(unsigned int port,void * addr,unsigned long count)179 void _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 
_outsb(unsigned int port,const void * addr,unsigned long count)189 void _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 
_outsw(unsigned int port,const void * addr,unsigned long count)205 void _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 
_outsl(unsigned int port,const void * addr,unsigned long count)221 void _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 }
230