blob: 476650e42dbc05ff8e466866e87a5b56555b2ec5 [file] [log] [blame]
Paul Mundt959f85f2006-09-27 16:43:28 +09001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (C) 2002 David McCullough <davidm@snapgear.com>
3 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
4 * Based largely on io_se.c.
5 *
6 * I/O routine for Hitachi 7751 SolutionEngine.
7 *
8 * Initial version only to support LAN access; some
9 * placeholder code from io_se.c left in with the
10 * expectation of later SuperIO and PCMCIA access.
11 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/kernel.h>
13#include <linux/types.h>
14#include <linux/pci.h>
15#include <asm/io.h>
16#include <asm/addrspace.h>
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#ifdef CONFIG_SH_SECUREEDGE5410
19unsigned short secureedge5410_ioport;
20#endif
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static inline volatile __u16 *port2adr(unsigned int port)
23{
Paul Mundt373e68b2006-09-27 15:41:24 +090024 maybebadio((unsigned long)port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 return (volatile __u16*)port;
26}
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028/*
29 * General outline: remap really low stuff [eventually] to SuperIO,
30 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
31 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
32 * should be way beyond the window, and is used w/o translation for
33 * compatibility.
34 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035unsigned char snapgear_inb(unsigned long port)
36{
37 if (PXSEG(port))
38 return *(volatile unsigned char *)port;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 else
Paul Mundt959f85f2006-09-27 16:43:28 +090040 return (*port2adr(port)) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043unsigned char snapgear_inb_p(unsigned long port)
44{
45 unsigned char v;
46
47 if (PXSEG(port))
48 v = *(volatile unsigned char *)port;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 else
Paul Mundt959f85f2006-09-27 16:43:28 +090050 v = (*port2adr(port))&0xff;
51 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 return v;
53}
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055unsigned short snapgear_inw(unsigned long port)
56{
57 if (PXSEG(port))
58 return *(volatile unsigned short *)port;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 else if (port >= 0x2000)
60 return *port2adr(port);
61 else
Paul Mundt373e68b2006-09-27 15:41:24 +090062 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 return 0;
64}
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066unsigned int snapgear_inl(unsigned long port)
67{
68 if (PXSEG(port))
69 return *(volatile unsigned long *)port;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 else if (port >= 0x2000)
71 return *port2adr(port);
72 else
Paul Mundt373e68b2006-09-27 15:41:24 +090073 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return 0;
75}
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077void snapgear_outb(unsigned char value, unsigned long port)
78{
79
80 if (PXSEG(port))
81 *(volatile unsigned char *)port = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 else
83 *(port2adr(port)) = value;
84}
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086void snapgear_outb_p(unsigned char value, unsigned long port)
87{
88 if (PXSEG(port))
89 *(volatile unsigned char *)port = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 else
91 *(port2adr(port)) = value;
Paul Mundt959f85f2006-09-27 16:43:28 +090092 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095void snapgear_outw(unsigned short value, unsigned long port)
96{
97 if (PXSEG(port))
98 *(volatile unsigned short *)port = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 else if (port >= 0x2000)
100 *port2adr(port) = value;
101 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900102 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105void snapgear_outl(unsigned int value, unsigned long port)
106{
107 if (PXSEG(port))
108 *(volatile unsigned long *)port = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900110 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
113void snapgear_insl(unsigned long port, void *addr, unsigned long count)
114{
Paul Mundt373e68b2006-09-27 15:41:24 +0900115 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116}
117
118void snapgear_outsl(unsigned long port, const void *addr, unsigned long count)
119{
Paul Mundt373e68b2006-09-27 15:41:24 +0900120 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}