blob: 73648cbe3678a147ed2cb66cb5ecf53ca2a719ab [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/sh/boards/se/73180/io.c
3 *
4 * Copyright (C) 2003 YOSHII Takashi <yoshii-takashi@hitachi-ul.co.jp>
5 * Based on arch/sh/boards/se/7300/io.c
6 *
7 * I/O routine for SH-Mobile3 73180 SolutionEngine.
8 *
9 */
10
11#include <linux/config.h>
12#include <linux/kernel.h>
13#include <asm/mach/se73180.h>
14#include <asm/io.h>
15
16#define badio(fn, a) panic("bad i/o operation %s for %08lx.", #fn, a)
17
18struct iop {
19 unsigned long start, end;
20 unsigned long base;
21 struct iop *(*check) (struct iop * p, unsigned long port);
22 unsigned char (*inb) (struct iop * p, unsigned long port);
23 unsigned short (*inw) (struct iop * p, unsigned long port);
24 void (*outb) (struct iop * p, unsigned char value, unsigned long port);
25 void (*outw) (struct iop * p, unsigned short value, unsigned long port);
26};
27
28struct iop *
29simple_check(struct iop *p, unsigned long port)
30{
31 if ((p->start <= port) && (port <= p->end))
32 return p;
33 else
34 badio(check, port);
35}
36
37struct iop *
38ide_check(struct iop *p, unsigned long port)
39{
40 if (((0x1f0 <= port) && (port <= 0x1f7)) || (port == 0x3f7))
41 return p;
42 return NULL;
43}
44
45unsigned char
46simple_inb(struct iop *p, unsigned long port)
47{
48 return *(unsigned char *) (p->base + port);
49}
50
51unsigned short
52simple_inw(struct iop *p, unsigned long port)
53{
54 return *(unsigned short *) (p->base + port);
55}
56
57void
58simple_outb(struct iop *p, unsigned char value, unsigned long port)
59{
60 *(unsigned char *) (p->base + port) = value;
61}
62
63void
64simple_outw(struct iop *p, unsigned short value, unsigned long port)
65{
66 *(unsigned short *) (p->base + port) = value;
67}
68
69unsigned char
70pcc_inb(struct iop *p, unsigned long port)
71{
72 unsigned long addr = p->base + port + 0x40000;
73 unsigned long v;
74
75 if (port & 1)
76 addr += 0x00400000;
77 v = *(volatile unsigned char *) addr;
78 return v;
79}
80
81void
82pcc_outb(struct iop *p, unsigned char value, unsigned long port)
83{
84 unsigned long addr = p->base + port + 0x40000;
85
86 if (port & 1)
87 addr += 0x00400000;
88 *(volatile unsigned char *) addr = value;
89}
90
91unsigned char
92bad_inb(struct iop *p, unsigned long port)
93{
94 badio(inb, port);
95}
96
97void
98bad_outb(struct iop *p, unsigned char value, unsigned long port)
99{
100 badio(inw, port);
101}
102
103/* MSTLANEX01 LAN at 0xb400:0000 */
104static struct iop laniop = {
105 .start = 0x300,
106 .end = 0x30f,
107 .base = 0xb4000000,
108 .check = simple_check,
109 .inb = simple_inb,
110 .inw = simple_inw,
111 .outb = simple_outb,
112 .outw = simple_outw,
113};
114
115/* NE2000 pc card NIC */
116static struct iop neiop = {
117 .start = 0x280,
118 .end = 0x29f,
119 .base = 0xb0600000 + 0x80, /* soft 0x280 -> hard 0x300 */
120 .check = simple_check,
121 .inb = pcc_inb,
122 .inw = simple_inw,
123 .outb = pcc_outb,
124 .outw = simple_outw,
125};
126
127/* CF in CF slot */
128static struct iop cfiop = {
129 .base = 0xb0600000,
130 .check = ide_check,
131 .inb = pcc_inb,
132 .inw = simple_inw,
133 .outb = pcc_outb,
134 .outw = simple_outw,
135};
136
137static __inline__ struct iop *
138port2iop(unsigned long port)
139{
140 if (0) ;
141#if defined(CONFIG_SMC91111)
142 else if (laniop.check(&laniop, port))
143 return &laniop;
144#endif
145#if defined(CONFIG_NE2000)
146 else if (neiop.check(&neiop, port))
147 return &neiop;
148#endif
149#if defined(CONFIG_IDE)
150 else if (cfiop.check(&cfiop, port))
151 return &cfiop;
152#endif
153 else
154 return &neiop; /* fallback */
155}
156
157static inline void
158delay(void)
159{
160 ctrl_inw(0xac000000);
161 ctrl_inw(0xac000000);
162}
163
164unsigned char
165sh73180se_inb(unsigned long port)
166{
167 struct iop *p = port2iop(port);
168 return (p->inb) (p, port);
169}
170
171unsigned char
172sh73180se_inb_p(unsigned long port)
173{
174 unsigned char v = sh73180se_inb(port);
175 delay();
176 return v;
177}
178
179unsigned short
180sh73180se_inw(unsigned long port)
181{
182 struct iop *p = port2iop(port);
183 return (p->inw) (p, port);
184}
185
186unsigned int
187sh73180se_inl(unsigned long port)
188{
189 badio(inl, port);
190}
191
192void
193sh73180se_outb(unsigned char value, unsigned long port)
194{
195 struct iop *p = port2iop(port);
196 (p->outb) (p, value, port);
197}
198
199void
200sh73180se_outb_p(unsigned char value, unsigned long port)
201{
202 sh73180se_outb(value, port);
203 delay();
204}
205
206void
207sh73180se_outw(unsigned short value, unsigned long port)
208{
209 struct iop *p = port2iop(port);
210 (p->outw) (p, value, port);
211}
212
213void
214sh73180se_outl(unsigned int value, unsigned long port)
215{
216 badio(outl, port);
217}
218
219void
220sh73180se_insb(unsigned long port, void *addr, unsigned long count)
221{
222 unsigned char *a = addr;
223 struct iop *p = port2iop(port);
224 while (count--)
225 *a++ = (p->inb) (p, port);
226}
227
228void
229sh73180se_insw(unsigned long port, void *addr, unsigned long count)
230{
231 unsigned short *a = addr;
232 struct iop *p = port2iop(port);
233 while (count--)
234 *a++ = (p->inw) (p, port);
235}
236
237void
238sh73180se_insl(unsigned long port, void *addr, unsigned long count)
239{
240 badio(insl, port);
241}
242
243void
244sh73180se_outsb(unsigned long port, const void *addr, unsigned long count)
245{
246 unsigned char *a = (unsigned char *) addr;
247 struct iop *p = port2iop(port);
248 while (count--)
249 (p->outb) (p, *a++, port);
250}
251
252void
253sh73180se_outsw(unsigned long port, const void *addr, unsigned long count)
254{
255 unsigned short *a = (unsigned short *) addr;
256 struct iop *p = port2iop(port);
257 while (count--)
258 (p->outw) (p, *a++, port);
259}
260
261void
262sh73180se_outsl(unsigned long port, const void *addr, unsigned long count)
263{
264 badio(outsw, port);
265}