2 * linux/arch/sh/kernel/io_7751se.c
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.
8 * I/O routine for Hitachi 7751 SolutionEngine.
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.
15 #include <linux/kernel.h>
16 #include <linux/types.h>
17 #include <linux/pci.h>
19 #include <asm/addrspace.h>
22 #include "../../drivers/pci/pci-sh7751.h"
24 #ifdef CONFIG_SH_SECUREEDGE5410
25 unsigned short secureedge5410_ioport;
29 * The SnapGear uses the built-in PCI controller (PCIC)
30 * of the 7751 processor
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
39 #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
42 #define maybebadio(name,port) \
43 printk("bad PC-like io %s for port 0x%lx at 0x%08x\n", \
44 #name, (port), (__u32) __builtin_return_address(0))
47 static inline void delay(void)
53 static inline volatile __u16 *port2adr(unsigned int port)
57 return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
59 maybebadio(name,(unsigned long)port);
60 return (volatile __u16*)port;
64 /* In case someone configures the kernel w/o PCI support: in that */
65 /* scenario, don't ever bother to check for PCI-window addresses */
67 /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
68 #if defined(CONFIG_PCI)
69 #define CHECK_SH7751_PCIIO(port) \
70 ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
72 #define CHECK_SH7751_PCIIO(port) (0)
76 * General outline: remap really low stuff [eventually] to SuperIO,
77 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
78 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
79 * should be way beyond the window, and is used w/o translation for
83 unsigned char snapgear_inb(unsigned long port)
86 return *(volatile unsigned char *)port;
87 else if (CHECK_SH7751_PCIIO(port))
88 return *(volatile unsigned char *)PCI_IOMAP(port);
90 return (*port2adr(port))&0xff;
94 unsigned char snapgear_inb_p(unsigned long port)
99 v = *(volatile unsigned char *)port;
100 else if (CHECK_SH7751_PCIIO(port))
101 v = *(volatile unsigned char *)PCI_IOMAP(port);
103 v = (*port2adr(port))&0xff;
109 unsigned short snapgear_inw(unsigned long port)
112 return *(volatile unsigned short *)port;
113 else if (CHECK_SH7751_PCIIO(port))
114 return *(volatile unsigned short *)PCI_IOMAP(port);
115 else if (port >= 0x2000)
116 return *port2adr(port);
118 maybebadio(inw, port);
123 unsigned int snapgear_inl(unsigned long port)
126 return *(volatile unsigned long *)port;
127 else if (CHECK_SH7751_PCIIO(port))
128 return *(volatile unsigned int *)PCI_IOMAP(port);
129 else if (port >= 0x2000)
130 return *port2adr(port);
132 maybebadio(inl, port);
137 void snapgear_outb(unsigned char value, unsigned long port)
141 *(volatile unsigned char *)port = value;
142 else if (CHECK_SH7751_PCIIO(port))
143 *((unsigned char*)PCI_IOMAP(port)) = value;
145 *(port2adr(port)) = value;
149 void snapgear_outb_p(unsigned char value, unsigned long port)
152 *(volatile unsigned char *)port = value;
153 else if (CHECK_SH7751_PCIIO(port))
154 *((unsigned char*)PCI_IOMAP(port)) = value;
156 *(port2adr(port)) = value;
161 void snapgear_outw(unsigned short value, unsigned long port)
164 *(volatile unsigned short *)port = value;
165 else if (CHECK_SH7751_PCIIO(port))
166 *((unsigned short *)PCI_IOMAP(port)) = value;
167 else if (port >= 0x2000)
168 *port2adr(port) = value;
170 maybebadio(outw, port);
174 void snapgear_outl(unsigned int value, unsigned long port)
177 *(volatile unsigned long *)port = value;
178 else if (CHECK_SH7751_PCIIO(port))
179 *((unsigned long*)PCI_IOMAP(port)) = value;
181 maybebadio(outl, port);
184 void snapgear_insl(unsigned long port, void *addr, unsigned long count)
186 maybebadio(insl, port);
189 void snapgear_outsl(unsigned long port, const void *addr, unsigned long count)
191 maybebadio(outsw, port);
194 /* Map ISA bus address to the real address. Only for PCMCIA. */
197 /* ISA page descriptor. */
198 static __u32 sh_isa_memmap[256];
202 static int sh_isa_mmap(__u32 start, __u32 length, __u32 offset)
206 if (start >= 0x100000 || (start & 0xfff) || (length != 0x1000))
210 sh_isa_memmap[idx] = 0xb8000000 + (offset &~ 0xfff);
212 printk("sh_isa_mmap: start %x len %x offset %x (idx %x paddr %x)\n",
213 start, length, offset, idx, sh_isa_memmap[idx]);
219 unsigned long snapgear_isa_port2addr(unsigned long offset)
223 idx = (offset >> 12) & 0xff;
225 return sh_isa_memmap[idx] + offset;