aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/boards/overdrive/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sh/boards/overdrive/io.c')
-rw-r--r--arch/sh/boards/overdrive/io.c173
1 files changed, 173 insertions, 0 deletions
diff --git a/arch/sh/boards/overdrive/io.c b/arch/sh/boards/overdrive/io.c
new file mode 100644
index 000000000000..65f3fd0563d3
--- /dev/null
+++ b/arch/sh/boards/overdrive/io.c
@@ -0,0 +1,173 @@
1/*
2 * Copyright (C) 2000 David J. Mckay (david.mckay@st.com)
3 *
4 * May be copied or modified under the terms of the GNU General Public
5 * License. See linux/COPYING for more information.
6 *
7 * This file contains the I/O routines for use on the overdrive board
8 *
9 */
10
11#include <linux/config.h>
12#include <linux/types.h>
13#include <linux/delay.h>
14#include <asm/processor.h>
15#include <asm/io.h>
16#include <asm/addrspace.h>
17
18#include <asm/overdrive/overdrive.h>
19
20/*
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.
25 */
26
27#define dprintk(x...)
28
29/* Translates an IO address to where it is mapped in memory */
30
31#define io_addr(x) (((unsigned)(x))|PCI_GTIO_BASE)
32
33unsigned char od_inb(unsigned long port)
34{
35dprintk("od_inb(%x)\n", port);
36 return readb(io_addr(port)) & 0xff;
37}
38
39
40unsigned short od_inw(unsigned long port)
41{
42dprintk("od_inw(%x)\n", port);
43 return readw(io_addr(port)) & 0xffff;
44}
45
46unsigned int od_inl(unsigned long port)
47{
48dprintk("od_inl(%x)\n", port);
49 return readl(io_addr(port));
50}
51
52void od_outb(unsigned char value, unsigned long port)
53{
54dprintk("od_outb(%x, %x)\n", value, port);
55 writeb(value, io_addr(port));
56}
57
58void od_outw(unsigned short value, unsigned long port)
59{
60dprintk("od_outw(%x, %x)\n", value, port);
61 writew(value, io_addr(port));
62}
63
64void od_outl(unsigned int value, unsigned long port)
65{
66dprintk("od_outl(%x, %x)\n", value, port);
67 writel(value, io_addr(port));
68}
69
70/* This is horrible at the moment - needs more work to do something sensible */
71#define IO_DELAY() udelay(10)
72
73#define OUT_DELAY(x,type) \
74void od_out##x##_p(unsigned type value,unsigned long port){out##x(value,port);IO_DELAY();}
75
76#define IN_DELAY(x,type) \
77unsigned type od_in##x##_p(unsigned long port) {unsigned type tmp=in##x(port);IO_DELAY();return tmp;}
78
79
80OUT_DELAY(b,char)
81OUT_DELAY(w,short)
82OUT_DELAY(l,int)
83
84IN_DELAY(b,char)
85IN_DELAY(w,short)
86IN_DELAY(l,int)
87
88
89/* Now for the string version of these functions */
90void od_outsb(unsigned long port, const void *addr, unsigned long count)
91{
92 int i;
93 unsigned char *p = (unsigned char *) addr;
94
95 for (i = 0; i < count; i++, p++) {
96 outb(*p, port);
97 }
98}
99
100
101void od_insb(unsigned long port, void *addr, unsigned long count)
102{
103 int i;
104 unsigned char *p = (unsigned char *) addr;
105
106 for (i = 0; i < count; i++, p++) {
107 *p = inb(port);
108 }
109}
110
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
115 * is aligned
116 */
117
118void od_outsw(unsigned long port, const void *addr, unsigned long count)
119{
120 int i;
121 unsigned short tmp;
122 unsigned char *p = (unsigned char *) addr;
123
124 for (i = 0; i < count; i++, p += 2) {
125 tmp = (*p) | ((*(p + 1)) << 8);
126 outw(tmp, port);
127 }
128}
129
130
131void od_insw(unsigned long port, void *addr, unsigned long count)
132{
133 int i;
134 unsigned short tmp;
135 unsigned char *p = (unsigned char *) addr;
136
137 for (i = 0; i < count; i++, p += 2) {
138 tmp = inw(port);
139 p[0] = tmp & 0xff;
140 p[1] = (tmp >> 8) & 0xff;
141 }
142}
143
144
145void od_outsl(unsigned long port, const void *addr, unsigned long count)
146{
147 int i;
148 unsigned tmp;
149 unsigned char *p = (unsigned char *) addr;
150
151 for (i = 0; i < count; i++, p += 4) {
152 tmp = (*p) | ((*(p + 1)) << 8) | ((*(p + 2)) << 16) |
153 ((*(p + 3)) << 24);
154 outl(tmp, port);
155 }
156}
157
158
159void od_insl(unsigned long port, void *addr, unsigned long count)
160{
161 int i;
162 unsigned tmp;
163 unsigned char *p = (unsigned char *) addr;
164
165 for (i = 0; i < count; i++, p += 4) {
166 tmp = inl(port);
167 p[0] = tmp & 0xff;
168 p[1] = (tmp >> 8) & 0xff;
169 p[2] = (tmp >> 16) & 0xff;
170 p[3] = (tmp >> 24) & 0xff;
171
172 }
173}