2 * linux/arch/m32r/kernel/io_usrv.c
4 * Typical I/O routines for uServer board.
6 * Copyright (c) 2001 - 2003 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Takeo Takahashi
9 * This file is subject to the terms and conditions of the GNU General
10 * Public License. See the file "COPYING" in the main directory of this
11 * archive for more details.
15 #include <linux/config.h>
20 #include <linux/types.h>
21 #include "../drivers/m32r_cfc.h"
23 extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
24 extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
25 extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
26 extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
27 #define CFC_IOSTART CFC_IOPORT_BASE
28 #define CFC_IOEND (CFC_IOSTART + (M32R_PCC_MAPSIZE * M32R_MAX_PCC) - 1)
30 #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
31 #define UART0_REGSTART 0x04c20000
32 #define UART1_REGSTART 0x04c20100
33 #define UART_IOMAP_SIZE 8
34 #define UART0_IOSTART 0x3f8
35 #define UART0_IOEND (UART0_IOSTART + UART_IOMAP_SIZE - 1)
36 #define UART1_IOSTART 0x2f8
37 #define UART1_IOEND (UART1_IOSTART + UART_IOMAP_SIZE - 1)
38 #endif /* CONFIG_SERIAL_8250 || CONFIG_SERIAL_8250_MODULE */
40 #define PORT2ADDR(port) _port2addr(port)
42 static __inline__ void *_port2addr(unsigned long port)
44 #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
45 if (port >= UART0_IOSTART && port <= UART0_IOEND)
46 port = ((port - UART0_IOSTART) << 1) + UART0_REGSTART;
47 else if (port >= UART1_IOSTART && port <= UART1_IOEND)
48 port = ((port - UART1_IOSTART) << 1) + UART1_REGSTART;
49 #endif /* CONFIG_SERIAL_8250 || CONFIG_SERIAL_8250_MODULE */
50 return (void *)(port + NONCACHE_OFFSET);
53 static __inline__ void delay(void)
55 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
58 unsigned char _inb(unsigned long port)
60 if (port >= CFC_IOSTART && port <= CFC_IOEND) {
62 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
65 return *(volatile unsigned char *)PORT2ADDR(port);
68 unsigned short _inw(unsigned long port)
70 if (port >= CFC_IOSTART && port <= CFC_IOEND) {
72 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
75 return *(volatile unsigned short *)PORT2ADDR(port);
78 unsigned long _inl(unsigned long port)
80 if (port >= CFC_IOSTART && port <= CFC_IOEND) {
82 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
85 return *(volatile unsigned long *)PORT2ADDR(port);
88 unsigned char _inb_p(unsigned long port)
92 if (port >= CFC_IOSTART && port <= CFC_IOEND) {
93 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
96 b = *(volatile unsigned char *)PORT2ADDR(port);
102 unsigned short _inw_p(unsigned long port)
106 if (port >= CFC_IOSTART && port <= CFC_IOEND) {
107 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
110 w = *(volatile unsigned short *)PORT2ADDR(port);
116 unsigned long _inl_p(unsigned long port)
120 v = *(volatile unsigned long *)PORT2ADDR(port);
126 void _outb(unsigned char b, unsigned long port)
128 if (port >= CFC_IOSTART && port <= CFC_IOEND)
129 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
131 *(volatile unsigned char *)PORT2ADDR(port) = b;
134 void _outw(unsigned short w, unsigned long port)
136 if (port >= CFC_IOSTART && port <= CFC_IOEND)
137 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
139 *(volatile unsigned short *)PORT2ADDR(port) = w;
142 void _outl(unsigned long l, unsigned long port)
144 if (port >= CFC_IOSTART && port <= CFC_IOEND)
145 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
147 *(volatile unsigned long *)PORT2ADDR(port) = l;
150 void _outb_p(unsigned char b, unsigned long port)
152 if (port >= CFC_IOSTART && port <= CFC_IOEND)
153 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
155 *(volatile unsigned char *)PORT2ADDR(port) = b;
159 void _outw_p(unsigned short w, unsigned long port)
161 if (port >= CFC_IOSTART && port <= CFC_IOEND)
162 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
164 *(volatile unsigned short *)PORT2ADDR(port) = w;
168 void _outl_p(unsigned long l, unsigned long port)
170 *(volatile unsigned long *)PORT2ADDR(port) = l;
174 void _insb(unsigned int port, void * addr, unsigned long count)
176 if (port >= CFC_IOSTART && port <= CFC_IOEND)
177 pcc_ioread_byte(0, port, addr, sizeof(unsigned char), count, 1);
179 unsigned char *buf = addr;
180 unsigned char *portp = PORT2ADDR(port);
181 while(count--) *buf++ = *(volatile unsigned char *)portp;
185 void _insw(unsigned int port, void * addr, unsigned long count)
187 unsigned short *buf = addr;
188 unsigned short *portp;
190 if (port >= CFC_IOSTART && port <= CFC_IOEND)
191 pcc_ioread_word(0, port, addr, sizeof(unsigned short), count,
194 portp = PORT2ADDR(port);
195 while (count--) *buf++ = *(volatile unsigned short *)portp;
199 void _insl(unsigned int port, void * addr, unsigned long count)
201 unsigned long *buf = addr;
202 unsigned long *portp;
204 portp = PORT2ADDR(port);
206 *buf++ = *(volatile unsigned long *)portp;
209 void _outsb(unsigned int port, const void * addr, unsigned long count)
211 const unsigned char *buf = addr;
212 unsigned char *portp;
214 if (port >= CFC_IOSTART && port <= CFC_IOEND)
215 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
218 portp = PORT2ADDR(port);
220 *(volatile unsigned char *)portp = *buf++;
224 void _outsw(unsigned int port, const void * addr, unsigned long count)
226 const unsigned short *buf = addr;
227 unsigned short *portp;
229 if (port >= CFC_IOSTART && port <= CFC_IOEND)
230 pcc_iowrite_word(0, port, (void *)addr, sizeof(unsigned short),
233 portp = PORT2ADDR(port);
235 *(volatile unsigned short *)portp = *buf++;
239 void _outsl(unsigned int port, const void * addr, unsigned long count)
241 const unsigned long *buf = addr;
242 unsigned char *portp;
244 portp = PORT2ADDR(port);
246 *(volatile unsigned long *)portp = *buf++;