blob: 9eb161dcc1042ea86a0154a7ec2bc324773578cc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m32r/kernel/io_usrv.c
3 *
4 * Typical I/O routines for uServer board.
5 *
Hirokazu Takata23680862005-06-21 17:16:10 -07006 * Copyright (c) 2001-2005 Hiroyuki Kondo, Hirokazu Takata,
7 * Hitoshi Yamamoto, Takeo Takahashi
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
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.
12 *
13 */
14
15#include <linux/config.h>
16#include <asm/m32r.h>
17#include <asm/page.h>
18#include <asm/io.h>
19
20#include <linux/types.h>
21#include "../drivers/m32r_cfc.h"
22
23extern void pcc_ioread_byte(int, unsigned long, void *, size_t, size_t, int);
24extern void pcc_ioread_word(int, unsigned long, void *, size_t, size_t, int);
25extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
26extern 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)
29
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 */
39
40#define PORT2ADDR(port) _port2addr(port)
41
Hirokazu Takata23680862005-06-21 17:16:10 -070042static inline void *_port2addr(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
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);
51}
52
Hirokazu Takata23680862005-06-21 17:16:10 -070053static inline void delay(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 __asm__ __volatile__ ("push r0; \n\t pop r0;" : : :"memory");
56}
57
58unsigned char _inb(unsigned long port)
59{
60 if (port >= CFC_IOSTART && port <= CFC_IOEND) {
61 unsigned char b;
62 pcc_ioread_byte(0, port, &b, sizeof(b), 1, 0);
63 return b;
64 } else
65 return *(volatile unsigned char *)PORT2ADDR(port);
66}
67
68unsigned short _inw(unsigned long port)
69{
70 if (port >= CFC_IOSTART && port <= CFC_IOEND) {
71 unsigned short w;
72 pcc_ioread_word(0, port, &w, sizeof(w), 1, 0);
73 return w;
74 } else
75 return *(volatile unsigned short *)PORT2ADDR(port);
76}
77
78unsigned long _inl(unsigned long port)
79{
80 if (port >= CFC_IOSTART && port <= CFC_IOEND) {
81 unsigned long l;
82 pcc_ioread_word(0, port, &l, sizeof(l), 1, 0);
83 return l;
84 } else
85 return *(volatile unsigned long *)PORT2ADDR(port);
86}
87
88unsigned char _inb_p(unsigned long port)
89{
Hirokazu Takata23680862005-06-21 17:16:10 -070090 unsigned char v = _inb(port);
91 delay();
92 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
95unsigned short _inw_p(unsigned long port)
96{
Hirokazu Takata23680862005-06-21 17:16:10 -070097 unsigned short v = _inw(port);
98 delay();
99 return v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
102unsigned long _inl_p(unsigned long port)
103{
Hirokazu Takata23680862005-06-21 17:16:10 -0700104 unsigned long v = _inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return v;
107}
108
109void _outb(unsigned char b, unsigned long port)
110{
111 if (port >= CFC_IOSTART && port <= CFC_IOEND)
112 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
113 else
114 *(volatile unsigned char *)PORT2ADDR(port) = b;
115}
116
117void _outw(unsigned short w, unsigned long port)
118{
119 if (port >= CFC_IOSTART && port <= CFC_IOEND)
120 pcc_iowrite_word(0, port, &w, sizeof(w), 1, 0);
121 else
122 *(volatile unsigned short *)PORT2ADDR(port) = w;
123}
124
125void _outl(unsigned long l, unsigned long port)
126{
127 if (port >= CFC_IOSTART && port <= CFC_IOEND)
128 pcc_iowrite_word(0, port, &l, sizeof(l), 1, 0);
129 else
130 *(volatile unsigned long *)PORT2ADDR(port) = l;
131}
132
133void _outb_p(unsigned char b, unsigned long port)
134{
Hirokazu Takata23680862005-06-21 17:16:10 -0700135 _outb(b, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 delay();
137}
138
139void _outw_p(unsigned short w, unsigned long port)
140{
Hirokazu Takata23680862005-06-21 17:16:10 -0700141 _outw(w, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 delay();
143}
144
145void _outl_p(unsigned long l, unsigned long port)
146{
Hirokazu Takata23680862005-06-21 17:16:10 -0700147 _outl(l, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 delay();
149}
150
151void _insb(unsigned int port, void * addr, unsigned long count)
152{
153 if (port >= CFC_IOSTART && port <= CFC_IOEND)
154 pcc_ioread_byte(0, port, addr, sizeof(unsigned char), count, 1);
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 >= CFC_IOSTART && port <= CFC_IOEND)
169 pcc_ioread_word(0, port, addr, sizeof(unsigned short), count,
170 1);
171 else {
172 portp = PORT2ADDR(port);
173 while (count--)
174 *buf++ = *(volatile unsigned short *)portp;
175 }
176}
177
178void _insl(unsigned int port, void * addr, unsigned long count)
179{
180 unsigned long *buf = addr;
181 unsigned long *portp;
182
183 portp = PORT2ADDR(port);
184 while (count--)
185 *buf++ = *(volatile unsigned long *)portp;
186}
187
188void _outsb(unsigned int port, const void * addr, unsigned long count)
189{
190 const unsigned char *buf = addr;
191 unsigned char *portp;
192
193 if (port >= CFC_IOSTART && port <= CFC_IOEND)
194 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
195 count, 1);
196 else {
197 portp = PORT2ADDR(port);
198 while (count--)
199 *(volatile unsigned char *)portp = *buf++;
200 }
201}
202
203void _outsw(unsigned int port, const void * addr, unsigned long count)
204{
205 const unsigned short *buf = addr;
206 unsigned short *portp;
207
208 if (port >= CFC_IOSTART && port <= CFC_IOEND)
209 pcc_iowrite_word(0, port, (void *)addr, sizeof(unsigned short),
210 count, 1);
211 else {
212 portp = PORT2ADDR(port);
213 while (count--)
214 *(volatile unsigned short *)portp = *buf++;
215 }
216}
217
218void _outsl(unsigned int port, const void * addr, unsigned long count)
219{
220 const unsigned long *buf = addr;
221 unsigned char *portp;
222
223 portp = PORT2ADDR(port);
224 while (count--)
225 *(volatile unsigned long *)portp = *buf++;
226}