Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / sh / kernel / io_generic.c
CommitLineData
9c57548f
PM
1/*
2 * arch/sh/kernel/io_generic.c
1da177e4
LT
3 *
4 * Copyright (C) 2000 Niibe Yutaka
9c57548f 5 * Copyright (C) 2005 - 2007 Paul Mundt
1da177e4
LT
6 *
7 * Generic I/O routine. These can be used where a machine specific version
8 * is not required.
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
1da177e4 13 */
b66c1a39 14#include <linux/module.h>
9c57548f 15#include <linux/io.h>
1da177e4 16#include <asm/machvec.h>
1da177e4 17
b66c1a39
PM
18#ifdef CONFIG_CPU_SH3
19/* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
20 * workaround. */
1da177e4 21/* I'm not sure SH7709 has this kind of bug */
14866543 22#define dummy_read() __raw_readb(0xba000000)
b66c1a39
PM
23#else
24#define dummy_read()
1da177e4
LT
25#endif
26
1da177e4
LT
27unsigned long generic_io_base;
28
b66c1a39 29u8 generic_inb(unsigned long port)
1da177e4 30{
14866543 31 return __raw_readb(__ioport_map(port, 1));
1da177e4
LT
32}
33
b66c1a39 34u16 generic_inw(unsigned long port)
1da177e4 35{
14866543 36 return __raw_readw(__ioport_map(port, 2));
1da177e4
LT
37}
38
b66c1a39 39u32 generic_inl(unsigned long port)
1da177e4 40{
14866543 41 return __raw_readl(__ioport_map(port, 4));
1da177e4
LT
42}
43
b66c1a39 44u8 generic_inb_p(unsigned long port)
1da177e4 45{
b66c1a39 46 unsigned long v = generic_inb(port);
1da177e4 47
14866543 48 ctrl_delay();
1da177e4
LT
49 return v;
50}
51
b66c1a39 52u16 generic_inw_p(unsigned long port)
1da177e4 53{
b66c1a39 54 unsigned long v = generic_inw(port);
1da177e4 55
14866543 56 ctrl_delay();
1da177e4
LT
57 return v;
58}
59
b66c1a39 60u32 generic_inl_p(unsigned long port)
1da177e4 61{
b66c1a39 62 unsigned long v = generic_inl(port);
1da177e4 63
14866543 64 ctrl_delay();
1da177e4
LT
65 return v;
66}
67
68/*
69 * insb/w/l all read a series of bytes/words/longs from a fixed port
70 * address. However as the port address doesn't change we only need to
71 * convert the port address to real address once.
72 */
73
b66c1a39 74void generic_insb(unsigned long port, void *dst, unsigned long count)
1da177e4 75{
b66c1a39
PM
76 volatile u8 *port_addr;
77 u8 *buf = dst;
1da177e4 78
fa43972f 79 port_addr = (volatile u8 __force *)__ioport_map(port, 1);
b66c1a39
PM
80 while (count--)
81 *buf++ = *port_addr;
1da177e4
LT
82}
83
b66c1a39 84void generic_insw(unsigned long port, void *dst, unsigned long count)
1da177e4 85{
b66c1a39
PM
86 volatile u16 *port_addr;
87 u16 *buf = dst;
1da177e4 88
fa43972f 89 port_addr = (volatile u16 __force *)__ioport_map(port, 2);
b66c1a39
PM
90 while (count--)
91 *buf++ = *port_addr;
1da177e4 92
b66c1a39 93 dummy_read();
1da177e4
LT
94}
95
b66c1a39 96void generic_insl(unsigned long port, void *dst, unsigned long count)
1da177e4 97{
b66c1a39
PM
98 volatile u32 *port_addr;
99 u32 *buf = dst;
1da177e4 100
fa43972f 101 port_addr = (volatile u32 __force *)__ioport_map(port, 4);
b66c1a39
PM
102 while (count--)
103 *buf++ = *port_addr;
1da177e4 104
b66c1a39 105 dummy_read();
1da177e4
LT
106}
107
b66c1a39 108void generic_outb(u8 b, unsigned long port)
1da177e4 109{
14866543 110 __raw_writeb(b, __ioport_map(port, 1));
1da177e4
LT
111}
112
b66c1a39 113void generic_outw(u16 b, unsigned long port)
1da177e4 114{
14866543 115 __raw_writew(b, __ioport_map(port, 2));
1da177e4
LT
116}
117
b66c1a39 118void generic_outl(u32 b, unsigned long port)
1da177e4 119{
14866543 120 __raw_writel(b, __ioport_map(port, 4));
1da177e4
LT
121}
122
b66c1a39 123void generic_outb_p(u8 b, unsigned long port)
1da177e4 124{
b66c1a39 125 generic_outb(b, port);
14866543 126 ctrl_delay();
1da177e4
LT
127}
128
b66c1a39 129void generic_outw_p(u16 b, unsigned long port)
1da177e4 130{
b66c1a39 131 generic_outw(b, port);
14866543 132 ctrl_delay();
1da177e4
LT
133}
134
b66c1a39 135void generic_outl_p(u32 b, unsigned long port)
1da177e4 136{
b66c1a39 137 generic_outl(b, port);
14866543 138 ctrl_delay();
1da177e4
LT
139}
140
141/*
142 * outsb/w/l all write a series of bytes/words/longs to a fixed port
143 * address. However as the port address doesn't change we only need to
144 * convert the port address to real address once.
145 */
b66c1a39 146void generic_outsb(unsigned long port, const void *src, unsigned long count)
1da177e4 147{
b66c1a39
PM
148 volatile u8 *port_addr;
149 const u8 *buf = src;
1da177e4 150
e7cc9a73 151 port_addr = (volatile u8 __force *)__ioport_map(port, 1);
1da177e4 152
b66c1a39
PM
153 while (count--)
154 *port_addr = *buf++;
1da177e4
LT
155}
156
b66c1a39 157void generic_outsw(unsigned long port, const void *src, unsigned long count)
1da177e4 158{
b66c1a39
PM
159 volatile u16 *port_addr;
160 const u16 *buf = src;
1da177e4 161
e7cc9a73 162 port_addr = (volatile u16 __force *)__ioport_map(port, 2);
1da177e4 163
b66c1a39
PM
164 while (count--)
165 *port_addr = *buf++;
1da177e4 166
b66c1a39 167 dummy_read();
1da177e4
LT
168}
169
b66c1a39 170void generic_outsl(unsigned long port, const void *src, unsigned long count)
1da177e4 171{
b66c1a39
PM
172 volatile u32 *port_addr;
173 const u32 *buf = src;
1da177e4 174
e7cc9a73 175 port_addr = (volatile u32 __force *)__ioport_map(port, 4);
b66c1a39
PM
176 while (count--)
177 *port_addr = *buf++;
1da177e4 178
b66c1a39 179 dummy_read();
1da177e4
LT
180}
181
b66c1a39 182void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
1da177e4 183{
b66c1a39 184 return (void __iomem *)(addr + generic_io_base);
1da177e4 185}
1da177e4 186
b66c1a39 187void generic_ioport_unmap(void __iomem *addr)
1da177e4 188{
1da177e4 189}