io_generic.c 3.7 KB
Newer Older
P
Paul Mundt 已提交
1 2
/*
 * arch/sh/kernel/io_generic.c
L
Linus Torvalds 已提交
3 4
 *
 * Copyright (C) 2000  Niibe Yutaka
P
Paul Mundt 已提交
5
 * Copyright (C) 2005 - 2007 Paul Mundt
L
Linus Torvalds 已提交
6 7 8 9 10 11 12 13
 *
 * 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.
 */
14
#include <linux/module.h>
P
Paul Mundt 已提交
15
#include <linux/io.h>
L
Linus Torvalds 已提交
16 17
#include <asm/machvec.h>

18 19 20
#ifdef CONFIG_CPU_SH3
/* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
 * workaround. */
L
Linus Torvalds 已提交
21
/* I'm not sure SH7709 has this kind of bug */
P
Paul Mundt 已提交
22
#define dummy_read()	__raw_readb(0xba000000)
23 24
#else
#define dummy_read()
L
Linus Torvalds 已提交
25 26
#endif

27
unsigned long generic_io_base = 0;
L
Linus Torvalds 已提交
28

29
u8 generic_inb(unsigned long port)
L
Linus Torvalds 已提交
30
{
P
Paul Mundt 已提交
31
	return __raw_readb(__ioport_map(port, 1));
L
Linus Torvalds 已提交
32 33
}

34
u16 generic_inw(unsigned long port)
L
Linus Torvalds 已提交
35
{
P
Paul Mundt 已提交
36
	return __raw_readw(__ioport_map(port, 2));
L
Linus Torvalds 已提交
37 38
}

39
u32 generic_inl(unsigned long port)
L
Linus Torvalds 已提交
40
{
P
Paul Mundt 已提交
41
	return __raw_readl(__ioport_map(port, 4));
L
Linus Torvalds 已提交
42 43
}

44
u8 generic_inb_p(unsigned long port)
L
Linus Torvalds 已提交
45
{
46
	unsigned long v = generic_inb(port);
L
Linus Torvalds 已提交
47

P
Paul Mundt 已提交
48
	ctrl_delay();
L
Linus Torvalds 已提交
49 50 51
	return v;
}

52
u16 generic_inw_p(unsigned long port)
L
Linus Torvalds 已提交
53
{
54
	unsigned long v = generic_inw(port);
L
Linus Torvalds 已提交
55

P
Paul Mundt 已提交
56
	ctrl_delay();
L
Linus Torvalds 已提交
57 58 59
	return v;
}

60
u32 generic_inl_p(unsigned long port)
L
Linus Torvalds 已提交
61
{
62
	unsigned long v = generic_inl(port);
L
Linus Torvalds 已提交
63

P
Paul Mundt 已提交
64
	ctrl_delay();
L
Linus Torvalds 已提交
65 66 67 68 69 70 71 72 73
	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.
 */

74
void generic_insb(unsigned long port, void *dst, unsigned long count)
L
Linus Torvalds 已提交
75
{
76 77
	__raw_readsb(__ioport_map(port, 1), dst, count);
	dummy_read();
L
Linus Torvalds 已提交
78 79
}

80
void generic_insw(unsigned long port, void *dst, unsigned long count)
L
Linus Torvalds 已提交
81
{
82
	__raw_readsw(__ioport_map(port, 2), dst, count);
83
	dummy_read();
L
Linus Torvalds 已提交
84 85
}

86
void generic_insl(unsigned long port, void *dst, unsigned long count)
L
Linus Torvalds 已提交
87
{
88
	__raw_readsl(__ioport_map(port, 4), dst, count);
89
	dummy_read();
L
Linus Torvalds 已提交
90 91
}

92
void generic_outb(u8 b, unsigned long port)
L
Linus Torvalds 已提交
93
{
P
Paul Mundt 已提交
94
	__raw_writeb(b, __ioport_map(port, 1));
L
Linus Torvalds 已提交
95 96
}

97
void generic_outw(u16 b, unsigned long port)
L
Linus Torvalds 已提交
98
{
P
Paul Mundt 已提交
99
	__raw_writew(b, __ioport_map(port, 2));
L
Linus Torvalds 已提交
100 101
}

102
void generic_outl(u32 b, unsigned long port)
L
Linus Torvalds 已提交
103
{
P
Paul Mundt 已提交
104
	__raw_writel(b, __ioport_map(port, 4));
L
Linus Torvalds 已提交
105 106
}

107
void generic_outb_p(u8 b, unsigned long port)
L
Linus Torvalds 已提交
108
{
109
	generic_outb(b, port);
P
Paul Mundt 已提交
110
	ctrl_delay();
L
Linus Torvalds 已提交
111 112
}

113
void generic_outw_p(u16 b, unsigned long port)
L
Linus Torvalds 已提交
114
{
115
	generic_outw(b, port);
P
Paul Mundt 已提交
116
	ctrl_delay();
L
Linus Torvalds 已提交
117 118
}

119
void generic_outl_p(u32 b, unsigned long port)
L
Linus Torvalds 已提交
120
{
121
	generic_outl(b, port);
P
Paul Mundt 已提交
122
	ctrl_delay();
L
Linus Torvalds 已提交
123 124 125 126 127 128 129
}

/*
 * 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.
 */
130
void generic_outsb(unsigned long port, const void *src, unsigned long count)
L
Linus Torvalds 已提交
131
{
132 133
	__raw_writesb(__ioport_map(port, 1), src, count);
	dummy_read();
L
Linus Torvalds 已提交
134 135
}

136
void generic_outsw(unsigned long port, const void *src, unsigned long count)
L
Linus Torvalds 已提交
137
{
138
	__raw_writesw(__ioport_map(port, 2), src, count);
139
	dummy_read();
L
Linus Torvalds 已提交
140 141
}

142
void generic_outsl(unsigned long port, const void *src, unsigned long count)
L
Linus Torvalds 已提交
143
{
144
	__raw_writesl(__ioport_map(port, 4), src, count);
145
	dummy_read();
L
Linus Torvalds 已提交
146 147
}

148
void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
L
Linus Torvalds 已提交
149
{
150
#ifdef P1SEG
151 152
	if (PXSEG(addr) >= P1SEG)
		return (void __iomem *)addr;
153
#endif
154

155
	return (void __iomem *)(addr + generic_io_base);
L
Linus Torvalds 已提交
156 157
}

158
void generic_ioport_unmap(void __iomem *addr)
L
Linus Torvalds 已提交
159 160
{
}
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180

#ifndef CONFIG_GENERIC_IOMAP
void __iomem *ioport_map(unsigned long port, unsigned int nr)
{
	void __iomem *ret;

	ret = __ioport_map_trapped(port, nr);
	if (ret)
		return ret;

	return __ioport_map(port, nr);
}
EXPORT_SYMBOL(ioport_map);

void ioport_unmap(void __iomem *addr)
{
	sh_mv.mv_ioport_unmap(addr);
}
EXPORT_SYMBOL(ioport_unmap);
#endif /* CONFIG_GENERIC_IOMAP */