1 /* $Id: io_generic.c,v 1.2 2003/05/04 19:29:53 lethal Exp $
3 * linux/arch/sh/kernel/io_generic.c
5 * Copyright (C) 2000 Niibe Yutaka
6 * Copyright (C) 2005 Paul Mundt
8 * Generic I/O routine. These can be used where a machine specific version
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
15 #include <linux/module.h>
17 #include <asm/machvec.h>
20 /* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
22 /* I'm not sure SH7709 has this kind of bug */
23 #define dummy_read() ctrl_inb(0xba000000)
28 unsigned long generic_io_base;
30 static inline void delay(void)
35 u8 generic_inb(unsigned long port)
37 return ctrl_inb((unsigned long __force)ioport_map(port, 1));
40 u16 generic_inw(unsigned long port)
42 return ctrl_inw((unsigned long __force)ioport_map(port, 2));
45 u32 generic_inl(unsigned long port)
47 return ctrl_inl((unsigned long __force)ioport_map(port, 4));
50 u8 generic_inb_p(unsigned long port)
52 unsigned long v = generic_inb(port);
58 u16 generic_inw_p(unsigned long port)
60 unsigned long v = generic_inw(port);
66 u32 generic_inl_p(unsigned long port)
68 unsigned long v = generic_inl(port);
75 * insb/w/l all read a series of bytes/words/longs from a fixed port
76 * address. However as the port address doesn't change we only need to
77 * convert the port address to real address once.
80 void generic_insb(unsigned long port, void *dst, unsigned long count)
82 volatile u8 *port_addr;
85 port_addr = (volatile u8 *)ioport_map(port, 1);
90 void generic_insw(unsigned long port, void *dst, unsigned long count)
92 volatile u16 *port_addr;
95 port_addr = (volatile u16 *)ioport_map(port, 2);
102 void generic_insl(unsigned long port, void *dst, unsigned long count)
104 volatile u32 *port_addr;
107 port_addr = (volatile u32 *)ioport_map(port, 4);
114 void generic_outb(u8 b, unsigned long port)
116 ctrl_outb(b, (unsigned long __force)ioport_map(port, 1));
119 void generic_outw(u16 b, unsigned long port)
121 ctrl_outw(b, (unsigned long __force)ioport_map(port, 2));
124 void generic_outl(u32 b, unsigned long port)
126 ctrl_outl(b, (unsigned long __force)ioport_map(port, 4));
129 void generic_outb_p(u8 b, unsigned long port)
131 generic_outb(b, port);
135 void generic_outw_p(u16 b, unsigned long port)
137 generic_outw(b, port);
141 void generic_outl_p(u32 b, unsigned long port)
143 generic_outl(b, port);
148 * outsb/w/l all write a series of bytes/words/longs to a fixed port
149 * address. However as the port address doesn't change we only need to
150 * convert the port address to real address once.
152 void generic_outsb(unsigned long port, const void *src, unsigned long count)
154 volatile u8 *port_addr;
157 port_addr = (volatile u8 __force *)ioport_map(port, 1);
163 void generic_outsw(unsigned long port, const void *src, unsigned long count)
165 volatile u16 *port_addr;
166 const u16 *buf = src;
168 port_addr = (volatile u16 __force *)ioport_map(port, 2);
176 void generic_outsl(unsigned long port, const void *src, unsigned long count)
178 volatile u32 *port_addr;
179 const u32 *buf = src;
181 port_addr = (volatile u32 __force *)ioport_map(port, 4);
188 u8 generic_readb(void __iomem *addr)
190 return ctrl_inb((unsigned long __force)addr);
193 u16 generic_readw(void __iomem *addr)
195 return ctrl_inw((unsigned long __force)addr);
198 u32 generic_readl(void __iomem *addr)
200 return ctrl_inl((unsigned long __force)addr);
203 void generic_writeb(u8 b, void __iomem *addr)
205 ctrl_outb(b, (unsigned long __force)addr);
208 void generic_writew(u16 b, void __iomem *addr)
210 ctrl_outw(b, (unsigned long __force)addr);
213 void generic_writel(u32 b, void __iomem *addr)
215 ctrl_outl(b, (unsigned long __force)addr);
218 void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
220 return (void __iomem *)(addr + generic_io_base);
223 void generic_ioport_unmap(void __iomem *addr)