1 /*
2  * linux/arch/sh/kernel/io_adx.c
3  *
4  * Copyright (C) 2001 A&D Co., Ltd.
5  *
6  * I/O routine and setup routines for A&D ADX Board
7  *
8  * This file is subject to the terms and conditions of the GNU General Public
9  * License.  See the file "COPYING" in the main directory of this archive
10  * for more details.
11  *
12  */
13 
14 #include <asm/io.h>
15 #include <asm/machvec.h>
16 #include <linux/module.h>
17 
18 #define PORT2ADDR(x) (adx_isa_port2addr(x))
19 
delay(void)20 static inline void delay(void)
21 {
22 	ctrl_inw(0xa0000000);
23 }
24 
adx_inb(unsigned long port)25 unsigned char adx_inb(unsigned long port)
26 {
27 	return *(volatile unsigned char*)PORT2ADDR(port);
28 }
29 
adx_inw(unsigned long port)30 unsigned short adx_inw(unsigned long port)
31 {
32 	return *(volatile unsigned short*)PORT2ADDR(port);
33 }
34 
adx_inl(unsigned long port)35 unsigned int adx_inl(unsigned long port)
36 {
37 	return *(volatile unsigned long*)PORT2ADDR(port);
38 }
39 
adx_inb_p(unsigned long port)40 unsigned char adx_inb_p(unsigned long port)
41 {
42 	unsigned long v = *(volatile unsigned char*)PORT2ADDR(port);
43 
44 	delay();
45 	return v;
46 }
47 
adx_inw_p(unsigned long port)48 unsigned short adx_inw_p(unsigned long port)
49 {
50 	unsigned long v = *(volatile unsigned short*)PORT2ADDR(port);
51 
52 	delay();
53 	return v;
54 }
55 
adx_inl_p(unsigned long port)56 unsigned int adx_inl_p(unsigned long port)
57 {
58 	unsigned long v = *(volatile unsigned long*)PORT2ADDR(port);
59 
60 	delay();
61 	return v;
62 }
63 
adx_insb(unsigned long port,void * buffer,unsigned long count)64 void adx_insb(unsigned long port, void *buffer, unsigned long count)
65 {
66 	unsigned char *buf = buffer;
67 	while(count--) *buf++ = inb(port);
68 }
69 
adx_insw(unsigned long port,void * buffer,unsigned long count)70 void adx_insw(unsigned long port, void *buffer, unsigned long count)
71 {
72 	unsigned short *buf = buffer;
73 	while(count--) *buf++ = inw(port);
74 }
75 
adx_insl(unsigned long port,void * buffer,unsigned long count)76 void adx_insl(unsigned long port, void *buffer, unsigned long count)
77 {
78 	unsigned long *buf = buffer;
79 	while(count--) *buf++ = inl(port);
80 }
81 
adx_outb(unsigned char b,unsigned long port)82 void adx_outb(unsigned char b, unsigned long port)
83 {
84 	*(volatile unsigned char*)PORT2ADDR(port) = b;
85 }
86 
adx_outw(unsigned short b,unsigned long port)87 void adx_outw(unsigned short b, unsigned long port)
88 {
89 	*(volatile unsigned short*)PORT2ADDR(port) = b;
90 }
91 
adx_outl(unsigned int b,unsigned long port)92 void adx_outl(unsigned int b, unsigned long port)
93 {
94 	*(volatile unsigned long*)PORT2ADDR(port) = b;
95 }
96 
adx_outb_p(unsigned char b,unsigned long port)97 void adx_outb_p(unsigned char b, unsigned long port)
98 {
99 	*(volatile unsigned char*)PORT2ADDR(port) = b;
100 	delay();
101 }
102 
adx_outw_p(unsigned short b,unsigned long port)103 void adx_outw_p(unsigned short b, unsigned long port)
104 {
105 	*(volatile unsigned short*)PORT2ADDR(port) = b;
106 	delay();
107 }
108 
adx_outl_p(unsigned int b,unsigned long port)109 void adx_outl_p(unsigned int b, unsigned long port)
110 {
111 	*(volatile unsigned long*)PORT2ADDR(port) = b;
112 	delay();
113 }
114 
adx_outsb(unsigned long port,const void * buffer,unsigned long count)115 void adx_outsb(unsigned long port, const void *buffer, unsigned long count)
116 {
117 	const unsigned char *buf = buffer;
118 	while(count--) outb(*buf++, port);
119 }
120 
adx_outsw(unsigned long port,const void * buffer,unsigned long count)121 void adx_outsw(unsigned long port, const void *buffer, unsigned long count)
122 {
123 	const unsigned short *buf = buffer;
124 	while(count--) outw(*buf++, port);
125 }
126 
adx_outsl(unsigned long port,const void * buffer,unsigned long count)127 void adx_outsl(unsigned long port, const void *buffer, unsigned long count)
128 {
129 	const unsigned long *buf = buffer;
130 	while(count--) outl(*buf++, port);
131 }
132 
adx_readb(unsigned long addr)133 unsigned char adx_readb(unsigned long addr)
134 {
135 	return *(volatile unsigned char*)addr;
136 }
137 
adx_readw(unsigned long addr)138 unsigned short adx_readw(unsigned long addr)
139 {
140 	return *(volatile unsigned short*)addr;
141 }
142 
adx_readl(unsigned long addr)143 unsigned int adx_readl(unsigned long addr)
144 {
145 	return *(volatile unsigned long*)addr;
146 }
147 
adx_writeb(unsigned char b,unsigned long addr)148 void adx_writeb(unsigned char b, unsigned long addr)
149 {
150 	*(volatile unsigned char*)addr = b;
151 }
152 
adx_writew(unsigned short b,unsigned long addr)153 void adx_writew(unsigned short b, unsigned long addr)
154 {
155 	*(volatile unsigned short*)addr = b;
156 }
157 
adx_writel(unsigned int b,unsigned long addr)158 void adx_writel(unsigned int b, unsigned long addr)
159 {
160 	*(volatile unsigned long*)addr = b;
161 }
162 
adx_ioremap(unsigned long offset,unsigned long size)163 void *adx_ioremap(unsigned long offset, unsigned long size)
164 {
165 	return (void *)P2SEGADDR(offset);
166 }
167 
168 EXPORT_SYMBOL (adx_ioremap);
169 
adx_iounmap(void * addr)170 void adx_iounmap(void *addr)
171 {
172 }
173 
174 EXPORT_SYMBOL(adx_iounmap);
175 
176 #include <linux/vmalloc.h>
177 extern void *cf_io_base;
178 
adx_isa_port2addr(unsigned long offset)179 unsigned long adx_isa_port2addr(unsigned long offset)
180 {
181   /* CompactFlash (IDE) */
182 	if (((offset >= 0x1f0) && (offset <= 0x1f7)) || (offset == 0x3f6)) {
183 		return (unsigned long)cf_io_base + offset;
184 	}
185 
186   /* eth0 */
187 	if ((offset >= 0x300) && (offset <= 0x30f)) {
188 		return 0xa5000000 + offset;	/* COMM BOARD (AREA1) */
189 	}
190 
191 	return offset + 0xb0000000; /* IOBUS (AREA 4)*/
192 }
193