blob: b8fa6524760af3be77c391b1a92ffbd0ba4362ca [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 Mundt14866542008-10-04 05:25:52 +090022#define dummy_read() __raw_readb(0xba000000)
Paul Mundtb66c1a32006-01-16 22:14:15 -080023#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
Paul Mundtb66c1a32006-01-16 22:14:15 -080029u8 generic_inb(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Paul Mundt14866542008-10-04 05:25:52 +090031 return __raw_readb(__ioport_map(port, 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070032}
33
Paul Mundtb66c1a32006-01-16 22:14:15 -080034u16 generic_inw(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Paul Mundt14866542008-10-04 05:25:52 +090036 return __raw_readw(__ioport_map(port, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -070037}
38
Paul Mundtb66c1a32006-01-16 22:14:15 -080039u32 generic_inl(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
Paul Mundt14866542008-10-04 05:25:52 +090041 return __raw_readl(__ioport_map(port, 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Paul Mundtb66c1a32006-01-16 22:14:15 -080044u8 generic_inb_p(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Paul Mundtb66c1a32006-01-16 22:14:15 -080046 unsigned long v = generic_inb(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Paul Mundt14866542008-10-04 05:25:52 +090048 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 return v;
50}
51
Paul Mundtb66c1a32006-01-16 22:14:15 -080052u16 generic_inw_p(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Paul Mundtb66c1a32006-01-16 22:14:15 -080054 unsigned long v = generic_inw(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Paul Mundt14866542008-10-04 05:25:52 +090056 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 return v;
58}
59
Paul Mundtb66c1a32006-01-16 22:14:15 -080060u32 generic_inl_p(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Paul Mundtb66c1a32006-01-16 22:14:15 -080062 unsigned long v = generic_inl(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Paul Mundt14866542008-10-04 05:25:52 +090064 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 return v;
66}
67
68/*
69 * insb/w/l all read a series of bytes/words/longs from a fixed port
70 * address. However as the port address doesn't change we only need to
71 * convert the port address to real address once.
72 */
73
Paul Mundtb66c1a32006-01-16 22:14:15 -080074void generic_insb(unsigned long port, void *dst, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Stuart Menefy8af57f82009-08-24 17:26:39 +090076 __raw_readsb(__ioport_map(port, 1), dst, count);
77 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
Paul Mundtb66c1a32006-01-16 22:14:15 -080080void generic_insw(unsigned long port, void *dst, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Stuart Menefy8af57f82009-08-24 17:26:39 +090082 __raw_readsw(__ioport_map(port, 2), dst, count);
Paul Mundtb66c1a32006-01-16 22:14:15 -080083 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Paul Mundtb66c1a32006-01-16 22:14:15 -080086void generic_insl(unsigned long port, void *dst, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Stuart Menefy8af57f82009-08-24 17:26:39 +090088 __raw_readsl(__ioport_map(port, 4), dst, count);
Paul Mundtb66c1a32006-01-16 22:14:15 -080089 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Paul Mundtb66c1a32006-01-16 22:14:15 -080092void generic_outb(u8 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Paul Mundt14866542008-10-04 05:25:52 +090094 __raw_writeb(b, __ioport_map(port, 1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Paul Mundtb66c1a32006-01-16 22:14:15 -080097void generic_outw(u16 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Paul Mundt14866542008-10-04 05:25:52 +090099 __raw_writew(b, __ioport_map(port, 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
Paul Mundtb66c1a32006-01-16 22:14:15 -0800102void generic_outl(u32 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Paul Mundt14866542008-10-04 05:25:52 +0900104 __raw_writel(b, __ioport_map(port, 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Paul Mundtb66c1a32006-01-16 22:14:15 -0800107void generic_outb_p(u8 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800109 generic_outb(b, port);
Paul Mundt14866542008-10-04 05:25:52 +0900110 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Paul Mundtb66c1a32006-01-16 22:14:15 -0800113void generic_outw_p(u16 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800115 generic_outw(b, port);
Paul Mundt14866542008-10-04 05:25:52 +0900116 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117}
118
Paul Mundtb66c1a32006-01-16 22:14:15 -0800119void generic_outl_p(u32 b, unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
Paul Mundtb66c1a32006-01-16 22:14:15 -0800121 generic_outl(b, port);
Paul Mundt14866542008-10-04 05:25:52 +0900122 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
125/*
126 * outsb/w/l all write a series of bytes/words/longs to a fixed port
127 * address. However as the port address doesn't change we only need to
128 * convert the port address to real address once.
129 */
Paul Mundtb66c1a32006-01-16 22:14:15 -0800130void generic_outsb(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Stuart Menefy8af57f82009-08-24 17:26:39 +0900132 __raw_writesb(__ioport_map(port, 1), src, count);
133 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Paul Mundtb66c1a32006-01-16 22:14:15 -0800136void generic_outsw(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Stuart Menefy8af57f82009-08-24 17:26:39 +0900138 __raw_writesw(__ioport_map(port, 2), src, count);
Paul Mundtb66c1a32006-01-16 22:14:15 -0800139 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
141
Paul Mundtb66c1a32006-01-16 22:14:15 -0800142void generic_outsl(unsigned long port, const void *src, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Stuart Menefy8af57f82009-08-24 17:26:39 +0900144 __raw_writesl(__ioport_map(port, 4), src, count);
Paul Mundtb66c1a32006-01-16 22:14:15 -0800145 dummy_read();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
Paul Mundtb66c1a32006-01-16 22:14:15 -0800148void __iomem *generic_ioport_map(unsigned long addr, unsigned int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Paul Mundt48ff3e02009-09-28 15:04:04 +0900150 if (PXSEG(addr) >= P1SEG)
151 return (void __iomem *)addr;
152
Paul Mundtb66c1a32006-01-16 22:14:15 -0800153 return (void __iomem *)(addr + generic_io_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Paul Mundtb66c1a32006-01-16 22:14:15 -0800156void generic_ioport_unmap(void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
158}