blob: 771ea42304410c7f706b95e5b59fb97da5884916 [file] [log] [blame]
Paul Mundt9c575482007-02-15 18:20:52 +09001/*
2 * arch/sh/kernel/io_generic.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 2000 Niibe Yutaka
Paul Mundt9c575482007-02-15 18:20:52 +09005 * Copyright (C) 2005 - 2007 Paul Mundt
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
Paul Mundtb66c1a32006-01-16 22:14:15 -080014#include <linux/module.h>
Paul Mundt9c575482007-02-15 18:20:52 +090015#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/machvec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Paul Mundtb66c1a32006-01-16 22:14:15 -080018#ifdef CONFIG_CPU_SH3
19/* SH3 has a PCMCIA bug that needs a dummy read from area 6 for a
20 * workaround. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070021/* I'm not sure SH7709 has this kind of bug */
Paul Mundtb66c1a32006-01-16 22:14:15 -080022#define dummy_read() ctrl_inb(0xba000000)
23#else
24#define dummy_read()
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#endif
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027unsigned long generic_io_base;
28
29static inline void delay(void)
30{
31 ctrl_inw(0xa0000000);
32}
33
Paul Mundtb66c1a32006-01-16 22:14:15 -080034u8 generic_inb(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Paul Mundtb66c1a32006-01-16 22:14:15 -080036 return ctrl_inb((unsigned long __force)ioport_map(port, 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070037}
38
Paul Mundtb66c1a32006-01-16 22:14:15 -080039u16 generic_inw(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
Paul Mundtb66c1a32006-01-16 22:14:15 -080041 return ctrl_inw((unsigned long __force)ioport_map(port, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Paul Mundtb66c1a32006-01-16 22:14:15 -080044u32 generic_inl(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Paul Mundtb66c1a32006-01-16 22:14:15 -080046 return ctrl_inl((unsigned long __force)ioport_map(port, 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
Paul Mundtb66c1a32006-01-16 22:14:15 -080049u8 generic_inb_p(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Paul Mundtb66c1a32006-01-16 22:14:15 -080051 unsigned long v = generic_inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 delay();
54 return v;
55}
56
Paul Mundtb66c1a32006-01-16 22:14:15 -080057u16 generic_inw_p(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Paul Mundtb66c1a32006-01-16 22:14:15 -080059 unsigned long v = generic_inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 delay();
62 return v;
63}
64
Paul Mundtb66c1a32006-01-16 22:14:15 -080065u32 generic_inl_p(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Paul Mundtb66c1a32006-01-16 22:14:15 -080067 unsigned long v = generic_inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 delay();
70 return v;
71}
72
73/*
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.
77 */
78
Paul Mundtb66c1a32006-01-16 22:14:15 -080079void generic_insb(unsigned long port, void *dst, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Paul Mundtb66c1a32006-01-16 22:14:15 -080081 volatile u8 *port_addr;
82 u8 *buf = dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Paul Mundtb66c1a32006-01-16 22:14:15 -080084 port_addr = (volatile u8 *)ioport_map(port, 1);
85 while (count--)
86 *buf++ = *port_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
Paul Mundtb66c1a32006-01-16 22:14:15 -080089void generic_insw(unsigned long port, void *dst, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
Paul Mundtb66c1a32006-01-16 22:14:15 -080091 volatile u16 *port_addr;
92 u16 *buf = dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Paul Mundtb66c1a32006-01-16 22:14:15 -080094 port_addr = (volatile u16 *)ioport_map(port, 2);
95 while (count--)
96 *buf++ = *port_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Paul Mundtb66c1a32006-01-16 22:14:15 -080098 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
Paul Mundtb66c1a32006-01-16 22:14:15 -0800101void generic_insl(unsigned long port, void *dst, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800103 volatile u32 *port_addr;
104 u32 *buf = dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Paul Mundtb66c1a32006-01-16 22:14:15 -0800106 port_addr = (volatile u32 *)ioport_map(port, 4);
107 while (count--)
108 *buf++ = *port_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Paul Mundtb66c1a32006-01-16 22:14:15 -0800110 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Paul Mundtb66c1a32006-01-16 22:14:15 -0800113void generic_outb(u8 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800115 ctrl_outb(b, (unsigned long __force)ioport_map(port, 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116}
117
Paul Mundtb66c1a32006-01-16 22:14:15 -0800118void generic_outw(u16 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800120 ctrl_outw(b, (unsigned long __force)ioport_map(port, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
Paul Mundtb66c1a32006-01-16 22:14:15 -0800123void generic_outl(u32 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800125 ctrl_outl(b, (unsigned long __force)ioport_map(port, 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Paul Mundtb66c1a32006-01-16 22:14:15 -0800128void generic_outb_p(u8 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800130 generic_outb(b, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 delay();
132}
133
Paul Mundtb66c1a32006-01-16 22:14:15 -0800134void generic_outw_p(u16 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800136 generic_outw(b, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 delay();
138}
139
Paul Mundtb66c1a32006-01-16 22:14:15 -0800140void generic_outl_p(u32 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800142 generic_outl(b, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 delay();
144}
145
146/*
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.
150 */
Paul Mundtb66c1a32006-01-16 22:14:15 -0800151void generic_outsb(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800153 volatile u8 *port_addr;
154 const u8 *buf = src;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Paul Mundtb66c1a32006-01-16 22:14:15 -0800156 port_addr = (volatile u8 __force *)ioport_map(port, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Paul Mundtb66c1a32006-01-16 22:14:15 -0800158 while (count--)
159 *port_addr = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
Paul Mundtb66c1a32006-01-16 22:14:15 -0800162void generic_outsw(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800164 volatile u16 *port_addr;
165 const u16 *buf = src;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Paul Mundtb66c1a32006-01-16 22:14:15 -0800167 port_addr = (volatile u16 __force *)ioport_map(port, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Paul Mundtb66c1a32006-01-16 22:14:15 -0800169 while (count--)
170 *port_addr = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Paul Mundtb66c1a32006-01-16 22:14:15 -0800172 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173}
174
Paul Mundtb66c1a32006-01-16 22:14:15 -0800175void generic_outsl(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800177 volatile u32 *port_addr;
178 const u32 *buf = src;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Paul Mundtb66c1a32006-01-16 22:14:15 -0800180 port_addr = (volatile u32 __force *)ioport_map(port, 4);
181 while (count--)
182 *port_addr = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Paul Mundtb66c1a32006-01-16 22:14:15 -0800184 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185}
186
Paul Mundtb66c1a32006-01-16 22:14:15 -0800187u8 generic_readb(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800189 return ctrl_inb((unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
191
Paul Mundtb66c1a32006-01-16 22:14:15 -0800192u16 generic_readw(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800194 return ctrl_inw((unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195}
196
Paul Mundtb66c1a32006-01-16 22:14:15 -0800197u32 generic_readl(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800199 return ctrl_inl((unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
201
Paul Mundtb66c1a32006-01-16 22:14:15 -0800202void generic_writeb(u8 b, void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800204 ctrl_outb(b, (unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
Paul Mundtb66c1a32006-01-16 22:14:15 -0800207void generic_writew(u16 b, void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800209 ctrl_outw(b, (unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210}
211
Paul Mundtb66c1a32006-01-16 22:14:15 -0800212void generic_writel(u32 b, void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800214 ctrl_outl(b, (unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
Paul Mundtb66c1a32006-01-16 22:14:15 -0800217void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800219 return (void __iomem *)(addr + generic_io_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Paul Mundtb66c1a32006-01-16 22:14:15 -0800222void generic_ioport_unmap(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
224}