blob: 28ec7487de8ce2461e035964d20805a9f8f9c2ee [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: io_generic.c,v 1.2 2003/05/04 19:29:53 lethal Exp $
2 *
3 * linux/arch/sh/kernel/io_generic.c
4 *
5 * Copyright (C) 2000 Niibe Yutaka
Paul Mundtb66c1a32006-01-16 22:14:15 -08006 * Copyright (C) 2005 Paul Mundt
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * Generic I/O routine. These can be used where a machine specific version
9 * is not required.
10 *
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
13 * for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 */
Paul Mundtb66c1a32006-01-16 22:14:15 -080015#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/io.h>
17#include <asm/machvec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Paul Mundtb66c1a32006-01-16 22:14:15 -080019#ifdef CONFIG_CPU_SH3
20/* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
21 * workaround. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/* I'm not sure SH7709 has this kind of bug */
Paul Mundtb66c1a32006-01-16 22:14:15 -080023#define dummy_read() ctrl_inb(0xba000000)
24#else
25#define dummy_read()
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#endif
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028unsigned long generic_io_base;
29
30static inline void delay(void)
31{
32 ctrl_inw(0xa0000000);
33}
34
Paul Mundtb66c1a32006-01-16 22:14:15 -080035u8 generic_inb(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
Paul Mundtb66c1a32006-01-16 22:14:15 -080037 return ctrl_inb((unsigned long __force)ioport_map(port, 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
Paul Mundtb66c1a32006-01-16 22:14:15 -080040u16 generic_inw(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
Paul Mundtb66c1a32006-01-16 22:14:15 -080042 return ctrl_inw((unsigned long __force)ioport_map(port, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
Paul Mundtb66c1a32006-01-16 22:14:15 -080045u32 generic_inl(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
Paul Mundtb66c1a32006-01-16 22:14:15 -080047 return ctrl_inl((unsigned long __force)ioport_map(port, 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
Paul Mundtb66c1a32006-01-16 22:14:15 -080050u8 generic_inb_p(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Paul Mundtb66c1a32006-01-16 22:14:15 -080052 unsigned long v = generic_inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 delay();
55 return v;
56}
57
Paul Mundtb66c1a32006-01-16 22:14:15 -080058u16 generic_inw_p(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Paul Mundtb66c1a32006-01-16 22:14:15 -080060 unsigned long v = generic_inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62 delay();
63 return v;
64}
65
Paul Mundtb66c1a32006-01-16 22:14:15 -080066u32 generic_inl_p(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Paul Mundtb66c1a32006-01-16 22:14:15 -080068 unsigned long v = generic_inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 delay();
71 return v;
72}
73
74/*
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.
78 */
79
Paul Mundtb66c1a32006-01-16 22:14:15 -080080void generic_insb(unsigned long port, void *dst, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Paul Mundtb66c1a32006-01-16 22:14:15 -080082 volatile u8 *port_addr;
83 u8 *buf = dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Paul Mundtb66c1a32006-01-16 22:14:15 -080085 port_addr = (volatile u8 *)ioport_map(port, 1);
86 while (count--)
87 *buf++ = *port_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Paul Mundtb66c1a32006-01-16 22:14:15 -080090void generic_insw(unsigned long port, void *dst, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Paul Mundtb66c1a32006-01-16 22:14:15 -080092 volatile u16 *port_addr;
93 u16 *buf = dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Paul Mundtb66c1a32006-01-16 22:14:15 -080095 port_addr = (volatile u16 *)ioport_map(port, 2);
96 while (count--)
97 *buf++ = *port_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Paul Mundtb66c1a32006-01-16 22:14:15 -080099 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
Paul Mundtb66c1a32006-01-16 22:14:15 -0800102void generic_insl(unsigned long port, void *dst, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800104 volatile u32 *port_addr;
105 u32 *buf = dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Paul Mundtb66c1a32006-01-16 22:14:15 -0800107 port_addr = (volatile u32 *)ioport_map(port, 4);
108 while (count--)
109 *buf++ = *port_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Paul Mundtb66c1a32006-01-16 22:14:15 -0800111 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
Paul Mundtb66c1a32006-01-16 22:14:15 -0800114void generic_outb(u8 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800116 ctrl_outb(b, (unsigned long __force)ioport_map(port, 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117}
118
Paul Mundtb66c1a32006-01-16 22:14:15 -0800119void generic_outw(u16 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800121 ctrl_outw(b, (unsigned long __force)ioport_map(port, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
Paul Mundtb66c1a32006-01-16 22:14:15 -0800124void generic_outl(u32 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800126 ctrl_outl(b, (unsigned long __force)ioport_map(port, 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
Paul Mundtb66c1a32006-01-16 22:14:15 -0800129void generic_outb_p(u8 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800131 generic_outb(b, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 delay();
133}
134
Paul Mundtb66c1a32006-01-16 22:14:15 -0800135void generic_outw_p(u16 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800137 generic_outw(b, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 delay();
139}
140
Paul Mundtb66c1a32006-01-16 22:14:15 -0800141void generic_outl_p(u32 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800143 generic_outl(b, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 delay();
145}
146
147/*
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.
151 */
Paul Mundtb66c1a32006-01-16 22:14:15 -0800152void generic_outsb(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800154 volatile u8 *port_addr;
155 const u8 *buf = src;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Paul Mundtb66c1a32006-01-16 22:14:15 -0800157 port_addr = (volatile u8 __force *)ioport_map(port, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Paul Mundtb66c1a32006-01-16 22:14:15 -0800159 while (count--)
160 *port_addr = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
Paul Mundtb66c1a32006-01-16 22:14:15 -0800163void generic_outsw(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800165 volatile u16 *port_addr;
166 const u16 *buf = src;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Paul Mundtb66c1a32006-01-16 22:14:15 -0800168 port_addr = (volatile u16 __force *)ioport_map(port, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Paul Mundtb66c1a32006-01-16 22:14:15 -0800170 while (count--)
171 *port_addr = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Paul Mundtb66c1a32006-01-16 22:14:15 -0800173 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
Paul Mundtb66c1a32006-01-16 22:14:15 -0800176void generic_outsl(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800178 volatile u32 *port_addr;
179 const u32 *buf = src;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Paul Mundtb66c1a32006-01-16 22:14:15 -0800181 port_addr = (volatile u32 __force *)ioport_map(port, 4);
182 while (count--)
183 *port_addr = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Paul Mundtb66c1a32006-01-16 22:14:15 -0800185 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}
187
Paul Mundtb66c1a32006-01-16 22:14:15 -0800188u8 generic_readb(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800190 return ctrl_inb((unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191}
192
Paul Mundtb66c1a32006-01-16 22:14:15 -0800193u16 generic_readw(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800195 return ctrl_inw((unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196}
197
Paul Mundtb66c1a32006-01-16 22:14:15 -0800198u32 generic_readl(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800200 return ctrl_inl((unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202
Paul Mundtb66c1a32006-01-16 22:14:15 -0800203void generic_writeb(u8 b, void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800205 ctrl_outb(b, (unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
207
Paul Mundtb66c1a32006-01-16 22:14:15 -0800208void generic_writew(u16 b, void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800210 ctrl_outw(b, (unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211}
212
Paul Mundtb66c1a32006-01-16 22:14:15 -0800213void generic_writel(u32 b, void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800215 ctrl_outl(b, (unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
Paul Mundtb66c1a32006-01-16 22:14:15 -0800218void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800220 return (void __iomem *)(addr + generic_io_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Paul Mundtb66c1a32006-01-16 22:14:15 -0800223void generic_ioport_unmap(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
225}