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/processor.h>
16 #include <asm/addrspace.h>
18 #include <asm/overdrive/overdrive.h>
21 * readX/writeX() are used to access memory mapped devices. On some
22 * architectures the memory mapped IO stuff needs to be accessed
23 * differently. On the SuperH architecture, we just read/write the
24 * memory location directly.
29 /* Translates an IO address to where it is mapped in memory */
31 #define io_addr(x) (((unsigned)(x))|PCI_GTIO_BASE)
33 unsigned char od_inb(unsigned long port)
35 dprintk("od_inb(%x)\n", port);
36 return readb(io_addr(port)) & 0xff;
40 unsigned short od_inw(unsigned long port)
42 dprintk("od_inw(%x)\n", port);
43 return readw(io_addr(port)) & 0xffff;
46 unsigned int od_inl(unsigned long port)
48 dprintk("od_inl(%x)\n", port);
49 return readl(io_addr(port));
52 void od_outb(unsigned char value, unsigned long port)
54 dprintk("od_outb(%x, %x)\n", value, port);
55 writeb(value, io_addr(port));
58 void od_outw(unsigned short value, unsigned long port)
60 dprintk("od_outw(%x, %x)\n", value, port);
61 writew(value, io_addr(port));
64 void od_outl(unsigned int value, unsigned long port)
66 dprintk("od_outl(%x, %x)\n", value, port);
67 writel(value, io_addr(port));
70 /* This is horrible at the moment - needs more work to do something sensible */
71 #define IO_DELAY() udelay(10)
73 #define OUT_DELAY(x,type) \
74 void od_out##x##_p(unsigned type value,unsigned long port){out##x(value,port);IO_DELAY();}
76 #define IN_DELAY(x,type) \
77 unsigned type od_in##x##_p(unsigned long port) {unsigned type tmp=in##x(port);IO_DELAY();return tmp;}
89 /* Now for the string version of these functions */
90 void od_outsb(unsigned long port, const void *addr, unsigned long count)
93 unsigned char *p = (unsigned char *) addr;
95 for (i = 0; i < count; i++, p++) {
101 void od_insb(unsigned long port, void *addr, unsigned long count)
104 unsigned char *p = (unsigned char *) addr;
106 for (i = 0; i < count; i++, p++) {
111 /* For the 16 and 32 bit string functions, we have to worry about alignment.
112 * The SH does not do unaligned accesses, so we have to read as bytes and
113 * then write as a word or dword.
114 * This can be optimised a lot more, especially in the case where the data
118 void od_outsw(unsigned long port, const void *addr, unsigned long count)
122 unsigned char *p = (unsigned char *) addr;
124 for (i = 0; i < count; i++, p += 2) {
125 tmp = (*p) | ((*(p + 1)) << 8);
131 void od_insw(unsigned long port, void *addr, unsigned long count)
135 unsigned char *p = (unsigned char *) addr;
137 for (i = 0; i < count; i++, p += 2) {
140 p[1] = (tmp >> 8) & 0xff;
145 void od_outsl(unsigned long port, const void *addr, unsigned long count)
149 unsigned char *p = (unsigned char *) addr;
151 for (i = 0; i < count; i++, p += 4) {
152 tmp = (*p) | ((*(p + 1)) << 8) | ((*(p + 2)) << 16) |
159 void od_insl(unsigned long port, void *addr, unsigned long count)
163 unsigned char *p = (unsigned char *) addr;
165 for (i = 0; i < count; i++, p += 4) {
168 p[1] = (tmp >> 8) & 0xff;
169 p[2] = (tmp >> 16) & 0xff;
170 p[3] = (tmp >> 24) & 0xff;