v2.6.22.24-op1
[linux-2.6.22.y-op.git] / arch / sh / kernel / io_generic.c
blob771ea42304410c7f706b95e5b59fb97da5884916
1 /*
2 * arch/sh/kernel/io_generic.c
4 * Copyright (C) 2000 Niibe Yutaka
5 * Copyright (C) 2005 - 2007 Paul Mundt
7 * Generic I/O routine. These can be used where a machine specific version
8 * is not required.
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.
14 #include <linux/module.h>
15 #include <linux/io.h>
16 #include <asm/machvec.h>
18 #ifdef CONFIG_CPU_SH3
19 /* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
20 * workaround. */
21 /* I'm not sure SH7709 has this kind of bug */
22 #define dummy_read() ctrl_inb(0xba000000)
23 #else
24 #define dummy_read()
25 #endif
27 unsigned long generic_io_base;
29 static inline void delay(void)
31 ctrl_inw(0xa0000000);
34 u8 generic_inb(unsigned long port)
36 return ctrl_inb((unsigned long __force)ioport_map(port, 1));
39 u16 generic_inw(unsigned long port)
41 return ctrl_inw((unsigned long __force)ioport_map(port, 2));
44 u32 generic_inl(unsigned long port)
46 return ctrl_inl((unsigned long __force)ioport_map(port, 4));
49 u8 generic_inb_p(unsigned long port)
51 unsigned long v = generic_inb(port);
53 delay();
54 return v;
57 u16 generic_inw_p(unsigned long port)
59 unsigned long v = generic_inw(port);
61 delay();
62 return v;
65 u32 generic_inl_p(unsigned long port)
67 unsigned long v = generic_inl(port);
69 delay();
70 return v;
74 * insb/w/l all read a series of bytes/words/longs from a fixed port
75 * address. However as the port address doesn't change we only need to
76 * convert the port address to real address once.
79 void generic_insb(unsigned long port, void *dst, unsigned long count)
81 volatile u8 *port_addr;
82 u8 *buf = dst;
84 port_addr = (volatile u8 *)ioport_map(port, 1);
85 while (count--)
86 *buf++ = *port_addr;
89 void generic_insw(unsigned long port, void *dst, unsigned long count)
91 volatile u16 *port_addr;
92 u16 *buf = dst;
94 port_addr = (volatile u16 *)ioport_map(port, 2);
95 while (count--)
96 *buf++ = *port_addr;
98 dummy_read();
101 void generic_insl(unsigned long port, void *dst, unsigned long count)
103 volatile u32 *port_addr;
104 u32 *buf = dst;
106 port_addr = (volatile u32 *)ioport_map(port, 4);
107 while (count--)
108 *buf++ = *port_addr;
110 dummy_read();
113 void generic_outb(u8 b, unsigned long port)
115 ctrl_outb(b, (unsigned long __force)ioport_map(port, 1));
118 void generic_outw(u16 b, unsigned long port)
120 ctrl_outw(b, (unsigned long __force)ioport_map(port, 2));
123 void generic_outl(u32 b, unsigned long port)
125 ctrl_outl(b, (unsigned long __force)ioport_map(port, 4));
128 void generic_outb_p(u8 b, unsigned long port)
130 generic_outb(b, port);
131 delay();
134 void generic_outw_p(u16 b, unsigned long port)
136 generic_outw(b, port);
137 delay();
140 void generic_outl_p(u32 b, unsigned long port)
142 generic_outl(b, port);
143 delay();
147 * outsb/w/l all write a series of bytes/words/longs to a fixed port
148 * address. However as the port address doesn't change we only need to
149 * convert the port address to real address once.
151 void generic_outsb(unsigned long port, const void *src, unsigned long count)
153 volatile u8 *port_addr;
154 const u8 *buf = src;
156 port_addr = (volatile u8 __force *)ioport_map(port, 1);
158 while (count--)
159 *port_addr = *buf++;
162 void generic_outsw(unsigned long port, const void *src, unsigned long count)
164 volatile u16 *port_addr;
165 const u16 *buf = src;
167 port_addr = (volatile u16 __force *)ioport_map(port, 2);
169 while (count--)
170 *port_addr = *buf++;
172 dummy_read();
175 void generic_outsl(unsigned long port, const void *src, unsigned long count)
177 volatile u32 *port_addr;
178 const u32 *buf = src;
180 port_addr = (volatile u32 __force *)ioport_map(port, 4);
181 while (count--)
182 *port_addr = *buf++;
184 dummy_read();
187 u8 generic_readb(void __iomem *addr)
189 return ctrl_inb((unsigned long __force)addr);
192 u16 generic_readw(void __iomem *addr)
194 return ctrl_inw((unsigned long __force)addr);
197 u32 generic_readl(void __iomem *addr)
199 return ctrl_inl((unsigned long __force)addr);
202 void generic_writeb(u8 b, void __iomem *addr)
204 ctrl_outb(b, (unsigned long __force)addr);
207 void generic_writew(u16 b, void __iomem *addr)
209 ctrl_outw(b, (unsigned long __force)addr);
212 void generic_writel(u32 b, void __iomem *addr)
214 ctrl_outl(b, (unsigned long __force)addr);
217 void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
219 return (void __iomem *)(addr + generic_io_base);
222 void generic_ioport_unmap(void __iomem *addr)