blob: 0f4824264557deae48a2b6719a475ea3f0b21175 [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;
Paul Mundt959f85f2006-09-27 16:43:28 +090039 else if (is_pci_ioaddr(port))
40 return *(volatile unsigned char *)pci_ioaddr(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 else
Paul Mundt959f85f2006-09-27 16:43:28 +090042 return (*port2adr(port)) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045unsigned char snapgear_inb_p(unsigned long port)
46{
47 unsigned char v;
48
49 if (PXSEG(port))
50 v = *(volatile unsigned char *)port;
Paul Mundt959f85f2006-09-27 16:43:28 +090051 else if (is_pci_ioaddr(port))
52 v = *(volatile unsigned char *)pci_ioaddr(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 else
Paul Mundt959f85f2006-09-27 16:43:28 +090054 v = (*port2adr(port))&0xff;
55 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 return v;
57}
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059unsigned short snapgear_inw(unsigned long port)
60{
61 if (PXSEG(port))
62 return *(volatile unsigned short *)port;
Paul Mundt959f85f2006-09-27 16:43:28 +090063 else if (is_pci_ioaddr(port))
64 return *(volatile unsigned short *)pci_ioaddr(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 else if (port >= 0x2000)
66 return *port2adr(port);
67 else
Paul Mundt373e68b2006-09-27 15:41:24 +090068 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 return 0;
70}
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072unsigned int snapgear_inl(unsigned long port)
73{
74 if (PXSEG(port))
75 return *(volatile unsigned long *)port;
Paul Mundt959f85f2006-09-27 16:43:28 +090076 else if (is_pci_ioaddr(port))
77 return *(volatile unsigned int *)pci_ioaddr(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 else if (port >= 0x2000)
79 return *port2adr(port);
80 else
Paul Mundt373e68b2006-09-27 15:41:24 +090081 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 return 0;
83}
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085void snapgear_outb(unsigned char value, unsigned long port)
86{
87
88 if (PXSEG(port))
89 *(volatile unsigned char *)port = value;
Paul Mundt959f85f2006-09-27 16:43:28 +090090 else if (is_pci_ioaddr(port))
91 *((unsigned char*)pci_ioaddr(port)) = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 else
93 *(port2adr(port)) = value;
94}
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096void snapgear_outb_p(unsigned char value, unsigned long port)
97{
98 if (PXSEG(port))
99 *(volatile unsigned char *)port = value;
Paul Mundt959f85f2006-09-27 16:43:28 +0900100 else if (is_pci_ioaddr(port))
101 *((unsigned char*)pci_ioaddr(port)) = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 else
103 *(port2adr(port)) = value;
Paul Mundt959f85f2006-09-27 16:43:28 +0900104 ctrl_delay();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107void snapgear_outw(unsigned short value, unsigned long port)
108{
109 if (PXSEG(port))
110 *(volatile unsigned short *)port = value;
Paul Mundt959f85f2006-09-27 16:43:28 +0900111 else if (is_pci_ioaddr(port))
112 *((unsigned short *)pci_ioaddr(port)) = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 else if (port >= 0x2000)
114 *port2adr(port) = value;
115 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900116 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117}
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119void snapgear_outl(unsigned int value, unsigned long port)
120{
121 if (PXSEG(port))
122 *(volatile unsigned long *)port = value;
Paul Mundt959f85f2006-09-27 16:43:28 +0900123 else if (is_pci_ioaddr(port))
124 *((unsigned long*)pci_ioaddr(port)) = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900126 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
129void snapgear_insl(unsigned long port, void *addr, unsigned long count)
130{
Paul Mundt373e68b2006-09-27 15:41:24 +0900131 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
134void snapgear_outsl(unsigned long port, const void *addr, unsigned long count)
135{
Paul Mundt373e68b2006-09-27 15:41:24 +0900136 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}