blob: 66626c03e1eeb4b8e72f09871f6e83f1daa1b1c5 [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>
Paul Mundt9c575482007-02-15 18:20:52 +090017#include <asm/cacheflush.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 Mundt9c575482007-02-15 18:20:52 +090099 flush_dcache_all();
Paul Mundtb66c1a32006-01-16 22:14:15 -0800100 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
Paul Mundtb66c1a32006-01-16 22:14:15 -0800103void generic_insl(unsigned long port, void *dst, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800105 volatile u32 *port_addr;
106 u32 *buf = dst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Paul Mundtb66c1a32006-01-16 22:14:15 -0800108 port_addr = (volatile u32 *)ioport_map(port, 4);
109 while (count--)
110 *buf++ = *port_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Paul Mundtb66c1a32006-01-16 22:14:15 -0800112 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113}
114
Paul Mundtb66c1a32006-01-16 22:14:15 -0800115void generic_outb(u8 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800117 ctrl_outb(b, (unsigned long __force)ioport_map(port, 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
Paul Mundtb66c1a32006-01-16 22:14:15 -0800120void generic_outw(u16 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800122 ctrl_outw(b, (unsigned long __force)ioport_map(port, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
Paul Mundtb66c1a32006-01-16 22:14:15 -0800125void generic_outl(u32 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800127 ctrl_outl(b, (unsigned long __force)ioport_map(port, 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128}
129
Paul Mundtb66c1a32006-01-16 22:14:15 -0800130void generic_outb_p(u8 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800132 generic_outb(b, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 delay();
134}
135
Paul Mundtb66c1a32006-01-16 22:14:15 -0800136void generic_outw_p(u16 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800138 generic_outw(b, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 delay();
140}
141
Paul Mundtb66c1a32006-01-16 22:14:15 -0800142void generic_outl_p(u32 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800144 generic_outl(b, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 delay();
146}
147
148/*
149 * outsb/w/l all write a series of bytes/words/longs to a fixed port
150 * address. However as the port address doesn't change we only need to
151 * convert the port address to real address once.
152 */
Paul Mundtb66c1a32006-01-16 22:14:15 -0800153void generic_outsb(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800155 volatile u8 *port_addr;
156 const u8 *buf = src;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Paul Mundtb66c1a32006-01-16 22:14:15 -0800158 port_addr = (volatile u8 __force *)ioport_map(port, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Paul Mundtb66c1a32006-01-16 22:14:15 -0800160 while (count--)
161 *port_addr = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
Paul Mundtb66c1a32006-01-16 22:14:15 -0800164void generic_outsw(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800166 volatile u16 *port_addr;
167 const u16 *buf = src;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Paul Mundtb66c1a32006-01-16 22:14:15 -0800169 port_addr = (volatile u16 __force *)ioport_map(port, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Paul Mundtb66c1a32006-01-16 22:14:15 -0800171 while (count--)
172 *port_addr = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Paul Mundt9c575482007-02-15 18:20:52 +0900174 flush_dcache_all();
Paul Mundtb66c1a32006-01-16 22:14:15 -0800175 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
Paul Mundtb66c1a32006-01-16 22:14:15 -0800178void generic_outsl(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800180 volatile u32 *port_addr;
181 const u32 *buf = src;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Paul Mundtb66c1a32006-01-16 22:14:15 -0800183 port_addr = (volatile u32 __force *)ioport_map(port, 4);
184 while (count--)
185 *port_addr = *buf++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Paul Mundtb66c1a32006-01-16 22:14:15 -0800187 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188}
189
Paul Mundtb66c1a32006-01-16 22:14:15 -0800190u8 generic_readb(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800192 return ctrl_inb((unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
Paul Mundtb66c1a32006-01-16 22:14:15 -0800195u16 generic_readw(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800197 return ctrl_inw((unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
Paul Mundtb66c1a32006-01-16 22:14:15 -0800200u32 generic_readl(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800202 return ctrl_inl((unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203}
204
Paul Mundtb66c1a32006-01-16 22:14:15 -0800205void generic_writeb(u8 b, void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800207 ctrl_outb(b, (unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208}
209
Paul Mundtb66c1a32006-01-16 22:14:15 -0800210void generic_writew(u16 b, void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800212 ctrl_outw(b, (unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213}
214
Paul Mundtb66c1a32006-01-16 22:14:15 -0800215void generic_writel(u32 b, void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800217 ctrl_outl(b, (unsigned long __force)addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218}
219
Paul Mundtb66c1a32006-01-16 22:14:15 -0800220void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800222 return (void __iomem *)(addr + generic_io_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Paul Mundtb66c1a32006-01-16 22:14:15 -0800225void generic_ioport_unmap(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
227}