blob: 9f700b8392bb4d3cad12a96c73cb05a599b2fd51 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/sh/kernel/io_7751se.c
3 *
4 * Copyright (C) 2002 David McCullough <davidm@snapgear.com>
5 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
6 * Based largely on io_se.c.
7 *
8 * I/O routine for Hitachi 7751 SolutionEngine.
9 *
10 * Initial version only to support LAN access; some
11 * placeholder code from io_se.c left in with the
12 * expectation of later SuperIO and PCMCIA access.
13 */
14
15#include <linux/kernel.h>
16#include <linux/types.h>
17#include <linux/pci.h>
18#include <asm/io.h>
19#include <asm/addrspace.h>
20
21#include <asm/pci.h>
22#include "../../drivers/pci/pci-sh7751.h"
23
24#ifdef CONFIG_SH_SECUREEDGE5410
25unsigned short secureedge5410_ioport;
26#endif
27
28/*
29 * The SnapGear uses the built-in PCI controller (PCIC)
30 * of the 7751 processor
Paul Mundt373e68b2006-09-27 15:41:24 +090031 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR)
34#define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR)
35#define PCI_IO_AREA SH7751_PCI_IO_BASE
36#define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static inline void delay(void)
41{
42 ctrl_inw(0xa0000000);
43}
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static inline volatile __u16 *port2adr(unsigned int port)
46{
Paul Mundt373e68b2006-09-27 15:41:24 +090047 maybebadio((unsigned long)port);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return (volatile __u16*)port;
49}
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/* In case someone configures the kernel w/o PCI support: in that */
52/* scenario, don't ever bother to check for PCI-window addresses */
53
54/* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
55#if defined(CONFIG_PCI)
56#define CHECK_SH7751_PCIIO(port) \
57 ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
58#else
59#define CHECK_SH7751_PCIIO(port) (0)
60#endif
61
62/*
63 * General outline: remap really low stuff [eventually] to SuperIO,
64 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
65 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
66 * should be way beyond the window, and is used w/o translation for
67 * compatibility.
68 */
69
70unsigned char snapgear_inb(unsigned long port)
71{
72 if (PXSEG(port))
73 return *(volatile unsigned char *)port;
74 else if (CHECK_SH7751_PCIIO(port))
75 return *(volatile unsigned char *)PCI_IOMAP(port);
76 else
77 return (*port2adr(port))&0xff;
78}
79
80
81unsigned char snapgear_inb_p(unsigned long port)
82{
83 unsigned char v;
84
85 if (PXSEG(port))
86 v = *(volatile unsigned char *)port;
87 else if (CHECK_SH7751_PCIIO(port))
88 v = *(volatile unsigned char *)PCI_IOMAP(port);
89 else
90 v = (*port2adr(port))&0xff;
91 delay();
92 return v;
93}
94
95
96unsigned short snapgear_inw(unsigned long port)
97{
98 if (PXSEG(port))
99 return *(volatile unsigned short *)port;
100 else if (CHECK_SH7751_PCIIO(port))
101 return *(volatile unsigned short *)PCI_IOMAP(port);
102 else if (port >= 0x2000)
103 return *port2adr(port);
104 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900105 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return 0;
107}
108
109
110unsigned int snapgear_inl(unsigned long port)
111{
112 if (PXSEG(port))
113 return *(volatile unsigned long *)port;
114 else if (CHECK_SH7751_PCIIO(port))
115 return *(volatile unsigned int *)PCI_IOMAP(port);
116 else if (port >= 0x2000)
117 return *port2adr(port);
118 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900119 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return 0;
121}
122
123
124void snapgear_outb(unsigned char value, unsigned long port)
125{
126
127 if (PXSEG(port))
128 *(volatile unsigned char *)port = value;
129 else if (CHECK_SH7751_PCIIO(port))
130 *((unsigned char*)PCI_IOMAP(port)) = value;
131 else
132 *(port2adr(port)) = value;
133}
134
135
136void snapgear_outb_p(unsigned char value, unsigned long port)
137{
138 if (PXSEG(port))
139 *(volatile unsigned char *)port = value;
140 else if (CHECK_SH7751_PCIIO(port))
141 *((unsigned char*)PCI_IOMAP(port)) = value;
142 else
143 *(port2adr(port)) = value;
144 delay();
145}
146
147
148void snapgear_outw(unsigned short value, unsigned long port)
149{
150 if (PXSEG(port))
151 *(volatile unsigned short *)port = value;
152 else if (CHECK_SH7751_PCIIO(port))
153 *((unsigned short *)PCI_IOMAP(port)) = value;
154 else if (port >= 0x2000)
155 *port2adr(port) = value;
156 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900157 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158}
159
160
161void snapgear_outl(unsigned int value, unsigned long port)
162{
163 if (PXSEG(port))
164 *(volatile unsigned long *)port = value;
165 else if (CHECK_SH7751_PCIIO(port))
166 *((unsigned long*)PCI_IOMAP(port)) = value;
167 else
Paul Mundt373e68b2006-09-27 15:41:24 +0900168 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
171void snapgear_insl(unsigned long port, void *addr, unsigned long count)
172{
Paul Mundt373e68b2006-09-27 15:41:24 +0900173 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
176void snapgear_outsl(unsigned long port, const void *addr, unsigned long count)
177{
Paul Mundt373e68b2006-09-27 15:41:24 +0900178 maybebadio(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179}