2 * Copyright (C) 2000 David J. Mckay (david.mckay@st.com)
4 * May be copied or modified under the terms of the GNU General Public
5 * License. See linux/COPYING for more information.
7 * This file contains the I/O routines for use on the overdrive board
11 #include <linux/config.h>
12 #include <linux/types.h>
13 #include <linux/delay.h>
14 #include <asm/system.h>
15 #include <asm/processor.h>
17 #ifdef CONFIG_SH_CAYMAN
18 #include <asm/cayman.h>
22 * readX/writeX() are used to access memory mapped devices. On some
23 * architectures the memory mapped IO stuff needs to be accessed
24 * differently. On the SuperH architecture, we just read/write the
25 * memory location directly.
30 static int io_addr(int x) {
32 #ifdef CONFIG_SH_CAYMAN
33 return (x << 2) | smsc_superio_virt;
35 panic ("Illegal access to I/O port 0x%04x\n", x);
40 return (x + pciio_virt);
42 panic ("Illegal access to I/O port 0x%04x\n", x);
48 unsigned long inb(unsigned long port)
52 r = ctrl_inb(io_addr(port));
53 dprintk("inb(0x%x)=0x%x (0x%x)\n", port, r, io_addr(port));
57 unsigned long inw(unsigned long port)
61 r = ctrl_inw(io_addr(port));
62 dprintk("inw(0x%x)=0x%x (0x%x)\n", port, r, io_addr(port));
66 unsigned long inl(unsigned long port)
70 r = ctrl_inl(io_addr(port));
71 dprintk("inl(0x%x)=0x%x (0x%x)\n", port, r, io_addr(port));
75 void outb(unsigned long value, unsigned long port)
77 dprintk("outb(0x%x,0x%x) (0x%x)\n", value, port, io_addr(port));
78 ctrl_outb(value, io_addr(port));
81 void outw(unsigned long value, unsigned long port)
83 dprintk("outw(0x%x,0x%x) (0x%x)\n", value, port, io_addr(port));
84 ctrl_outw(value, io_addr(port));
87 void outl(unsigned long value, unsigned long port)
89 dprintk("outw(0x%x,0x%x) (0x%x)\n", value, port, io_addr(port));
90 ctrl_outl(value, io_addr(port));
93 /* This is horrible at the moment - needs more work to do something sensible */
96 #define OUT_DELAY(x,type) \
97 void out##x##_p(unsigned type value,unsigned long port){out##x(value,port);IO_DELAY();}
99 #define IN_DELAY(x,type) \
100 unsigned type in##x##_p(unsigned long port) {unsigned type tmp=in##x(port);IO_DELAY();return tmp;}
103 OUT_DELAY(b, long) OUT_DELAY(w, long) OUT_DELAY(l, long)
104 IN_DELAY(b, long) IN_DELAY(w, long) IN_DELAY(l, long)
106 /* Now for the string version of these functions */
107 void outsb(unsigned long port, const void *addr, unsigned long count)
110 unsigned char *p = (unsigned char *) addr;
112 for (i = 0; i < count; i++, p++) {
117 void insb(unsigned long port, void *addr, unsigned long count)
120 unsigned char *p = (unsigned char *) addr;
122 for (i = 0; i < count; i++, p++) {
127 /* For the 16 and 32 bit string functions, we have to worry about alignment.
128 * The SH does not do unaligned accesses, so we have to read as bytes and
129 * then write as a word or dword.
130 * This can be optimised a lot more, especially in the case where the data
134 void outsw(unsigned long port, const void *addr, unsigned long count)
138 unsigned char *p = (unsigned char *) addr;
140 for (i = 0; i < count; i++, p += 2) {
141 tmp = (*p) | ((*(p + 1)) << 8);
146 void insw(unsigned long port, void *addr, unsigned long count)
150 unsigned char *p = (unsigned char *) addr;
152 for (i = 0; i < count; i++, p += 2) {
155 p[1] = (tmp >> 8) & 0xff;
159 void outsl(unsigned long port, const void *addr, unsigned long count)
163 unsigned char *p = (unsigned char *) addr;
165 for (i = 0; i < count; i++, p += 4) {
166 tmp = (*p) | ((*(p + 1)) << 8) | ((*(p + 2)) << 16) |
172 void insl(unsigned long port, void *addr, unsigned long count)
176 unsigned char *p = (unsigned char *) addr;
178 for (i = 0; i < count; i++, p += 4) {
181 p[1] = (tmp >> 8) & 0xff;
182 p[2] = (tmp >> 16) & 0xff;
183 p[3] = (tmp >> 24) & 0xff;
188 void memcpy_toio(unsigned long to, const void *from, long count)
190 unsigned char *p = (unsigned char *) from;
198 void memcpy_fromio(void *to, unsigned long from, long count)
201 unsigned char *p = (unsigned char *) to;
203 for (i = 0; i < count; i++) {