io_generic.c 4.4 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
/* $Id: io_generic.c,v 1.2 2003/05/04 19:29:53 lethal Exp $
 *
 * linux/arch/sh/kernel/io_generic.c
 *
 * Copyright (C) 2000  Niibe Yutaka
6
 * Copyright (C) 2005  Paul Mundt
L
Linus Torvalds 已提交
7 8 9 10 11 12 13 14
 *
 * Generic I/O routine. These can be used where a machine specific version
 * is not required.
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */
15
#include <linux/module.h>
L
Linus Torvalds 已提交
16 17 18
#include <asm/io.h>
#include <asm/machvec.h>

19 20 21
#ifdef CONFIG_CPU_SH3
/* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
 * workaround. */
L
Linus Torvalds 已提交
22
/* I'm not sure SH7709 has this kind of bug */
23 24 25
#define dummy_read()	ctrl_inb(0xba000000)
#else
#define dummy_read()
L
Linus Torvalds 已提交
26 27 28 29 30 31 32 33 34
#endif

unsigned long generic_io_base;

static inline void delay(void)
{
	ctrl_inw(0xa0000000);
}

35
u8 generic_inb(unsigned long port)
L
Linus Torvalds 已提交
36
{
37
	return ctrl_inb((unsigned long __force)ioport_map(port, 1));
L
Linus Torvalds 已提交
38 39
}

40
u16 generic_inw(unsigned long port)
L
Linus Torvalds 已提交
41
{
42
	return ctrl_inw((unsigned long __force)ioport_map(port, 2));
L
Linus Torvalds 已提交
43 44
}

45
u32 generic_inl(unsigned long port)
L
Linus Torvalds 已提交
46
{
47
	return ctrl_inl((unsigned long __force)ioport_map(port, 4));
L
Linus Torvalds 已提交
48 49
}

50
u8 generic_inb_p(unsigned long port)
L
Linus Torvalds 已提交
51
{
52
	unsigned long v = generic_inb(port);
L
Linus Torvalds 已提交
53 54 55 56 57

	delay();
	return v;
}

58
u16 generic_inw_p(unsigned long port)
L
Linus Torvalds 已提交
59
{
60
	unsigned long v = generic_inw(port);
L
Linus Torvalds 已提交
61 62 63 64 65

	delay();
	return v;
}

66
u32 generic_inl_p(unsigned long port)
L
Linus Torvalds 已提交
67
{
68
	unsigned long v = generic_inl(port);
L
Linus Torvalds 已提交
69 70 71 72 73 74 75 76 77 78 79

	delay();
	return v;
}

/*
 * insb/w/l all read a series of bytes/words/longs from a fixed port
 * address. However as the port address doesn't change we only need to
 * convert the port address to real address once.
 */

80
void generic_insb(unsigned long port, void *dst, unsigned long count)
L
Linus Torvalds 已提交
81
{
82 83
	volatile u8 *port_addr;
	u8 *buf = dst;
L
Linus Torvalds 已提交
84

85 86 87
	port_addr = (volatile u8 *)ioport_map(port, 1);
	while (count--)
		*buf++ = *port_addr;
L
Linus Torvalds 已提交
88 89
}

90
void generic_insw(unsigned long port, void *dst, unsigned long count)
L
Linus Torvalds 已提交
91
{
92 93
	volatile u16 *port_addr;
	u16 *buf = dst;
L
Linus Torvalds 已提交
94

95 96 97
	port_addr = (volatile u16 *)ioport_map(port, 2);
	while (count--)
		*buf++ = *port_addr;
L
Linus Torvalds 已提交
98

99
	dummy_read();
L
Linus Torvalds 已提交
100 101
}

102
void generic_insl(unsigned long port, void *dst, unsigned long count)
L
Linus Torvalds 已提交
103
{
104 105
	volatile u32 *port_addr;
	u32 *buf = dst;
L
Linus Torvalds 已提交
106

107 108 109
	port_addr = (volatile u32 *)ioport_map(port, 4);
	while (count--)
		*buf++ = *port_addr;
L
Linus Torvalds 已提交
110

111
	dummy_read();
L
Linus Torvalds 已提交
112 113
}

114
void generic_outb(u8 b, unsigned long port)
L
Linus Torvalds 已提交
115
{
116
	ctrl_outb(b, (unsigned long __force)ioport_map(port, 1));
L
Linus Torvalds 已提交
117 118
}

119
void generic_outw(u16 b, unsigned long port)
L
Linus Torvalds 已提交
120
{
121
	ctrl_outw(b, (unsigned long __force)ioport_map(port, 2));
L
Linus Torvalds 已提交
122 123
}

124
void generic_outl(u32 b, unsigned long port)
L
Linus Torvalds 已提交
125
{
126
	ctrl_outl(b, (unsigned long __force)ioport_map(port, 4));
L
Linus Torvalds 已提交
127 128
}

129
void generic_outb_p(u8 b, unsigned long port)
L
Linus Torvalds 已提交
130
{
131
	generic_outb(b, port);
L
Linus Torvalds 已提交
132 133 134
	delay();
}

135
void generic_outw_p(u16 b, unsigned long port)
L
Linus Torvalds 已提交
136
{
137
	generic_outw(b, port);
L
Linus Torvalds 已提交
138 139 140
	delay();
}

141
void generic_outl_p(u32 b, unsigned long port)
L
Linus Torvalds 已提交
142
{
143
	generic_outl(b, port);
L
Linus Torvalds 已提交
144 145 146 147 148 149 150 151
	delay();
}

/*
 * outsb/w/l all write a series of bytes/words/longs to a fixed port
 * address. However as the port address doesn't change we only need to
 * convert the port address to real address once.
 */
152
void generic_outsb(unsigned long port, const void *src, unsigned long count)
L
Linus Torvalds 已提交
153
{
154 155
	volatile u8 *port_addr;
	const u8 *buf = src;
L
Linus Torvalds 已提交
156

157
	port_addr = (volatile u8 __force *)ioport_map(port, 1);
L
Linus Torvalds 已提交
158

159 160
	while (count--)
		*port_addr = *buf++;
L
Linus Torvalds 已提交
161 162
}

163
void generic_outsw(unsigned long port, const void *src, unsigned long count)
L
Linus Torvalds 已提交
164
{
165 166
	volatile u16 *port_addr;
	const u16 *buf = src;
L
Linus Torvalds 已提交
167

168
	port_addr = (volatile u16 __force *)ioport_map(port, 2);
L
Linus Torvalds 已提交
169

170 171
	while (count--)
		*port_addr = *buf++;
L
Linus Torvalds 已提交
172

173
	dummy_read();
L
Linus Torvalds 已提交
174 175
}

176
void generic_outsl(unsigned long port, const void *src, unsigned long count)
L
Linus Torvalds 已提交
177
{
178 179
	volatile u32 *port_addr;
	const u32 *buf = src;
L
Linus Torvalds 已提交
180

181 182 183
	port_addr = (volatile u32 __force *)ioport_map(port, 4);
	while (count--)
		*port_addr = *buf++;
L
Linus Torvalds 已提交
184

185
	dummy_read();
L
Linus Torvalds 已提交
186 187
}

188
u8 generic_readb(void __iomem *addr)
L
Linus Torvalds 已提交
189
{
190
	return ctrl_inb((unsigned long __force)addr);
L
Linus Torvalds 已提交
191 192
}

193
u16 generic_readw(void __iomem *addr)
L
Linus Torvalds 已提交
194
{
195
	return ctrl_inw((unsigned long __force)addr);
L
Linus Torvalds 已提交
196 197
}

198
u32 generic_readl(void __iomem *addr)
L
Linus Torvalds 已提交
199
{
200
	return ctrl_inl((unsigned long __force)addr);
L
Linus Torvalds 已提交
201 202
}

203
void generic_writeb(u8 b, void __iomem *addr)
L
Linus Torvalds 已提交
204
{
205
	ctrl_outb(b, (unsigned long __force)addr);
L
Linus Torvalds 已提交
206 207
}

208
void generic_writew(u16 b, void __iomem *addr)
L
Linus Torvalds 已提交
209
{
210
	ctrl_outw(b, (unsigned long __force)addr);
L
Linus Torvalds 已提交
211 212
}

213
void generic_writel(u32 b, void __iomem *addr)
L
Linus Torvalds 已提交
214
{
215
	ctrl_outl(b, (unsigned long __force)addr);
L
Linus Torvalds 已提交
216 217
}

218
void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
L
Linus Torvalds 已提交
219
{
220
	return (void __iomem *)(addr + generic_io_base);
L
Linus Torvalds 已提交
221 222
}

223
void generic_ioport_unmap(void __iomem *addr)
L
Linus Torvalds 已提交
224 225
{
}