2 * linux/arch/sh/boards/systemh/io.c
4 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
5 * Based largely on io_se.c.
7 * I/O routine for Hitachi 7751 Systemh.
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/pci.h>
14 #include <asm/systemh7751.h>
15 #include <asm/addrspace.h>
17 #include "../../../drivers/pci/pci-sh7751.h"
20 * The 7751 SystemH Engine uses the built-in PCI controller (PCIC)
21 * of the 7751 processor, and has a SuperIO accessible on its memory
25 #define PCIIOBR (volatile long *)PCI_REG(SH7751_PCIIOBR)
26 #define PCIMBR (volatile long *)PCI_REG(SH7751_PCIMBR)
27 #define PCI_IO_AREA SH7751_PCI_IO_BASE
28 #define PCI_MEM_AREA SH7751_PCI_CONFIG_BASE
30 #define PCI_IOMAP(adr) (PCI_IO_AREA + (adr & ~SH7751_PCIIOBR_MASK))
31 #define ETHER_IOMAP(adr) (0xB3000000 + (adr)) /*map to 16bits access area
33 static inline void delay(void)
38 static inline volatile __u16 *
39 port2adr(unsigned int port)
42 return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
43 maybebadio((unsigned long)port);
44 return (volatile __u16*)port;
47 /* In case someone configures the kernel w/o PCI support: in that */
48 /* scenario, don't ever bother to check for PCI-window addresses */
50 /* NOTE: WINDOW CHECK MAY BE A BIT OFF, HIGH PCIBIOS_MIN_IO WRAPS? */
51 #if defined(CONFIG_PCI)
52 #define CHECK_SH7751_PCIIO(port) \
53 ((port >= PCIBIOS_MIN_IO) && (port < (PCIBIOS_MIN_IO + SH7751_PCI_IO_SIZE)))
55 #define CHECK_SH7751_PCIIO(port) (0)
59 * General outline: remap really low stuff [eventually] to SuperIO,
60 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
61 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
62 * should be way beyond the window, and is used w/o translation for
65 unsigned char sh7751systemh_inb(unsigned long port)
68 return *(volatile unsigned char *)port;
69 else if (CHECK_SH7751_PCIIO(port))
70 return *(volatile unsigned char *)PCI_IOMAP(port);
71 else if (port <= 0x3F1)
72 return *(volatile unsigned char *)ETHER_IOMAP(port);
74 return (*port2adr(port))&0xff;
77 unsigned char sh7751systemh_inb_p(unsigned long port)
82 v = *(volatile unsigned char *)port;
83 else if (CHECK_SH7751_PCIIO(port))
84 v = *(volatile unsigned char *)PCI_IOMAP(port);
85 else if (port <= 0x3F1)
86 v = *(volatile unsigned char *)ETHER_IOMAP(port);
88 v = (*port2adr(port))&0xff;
93 unsigned short sh7751systemh_inw(unsigned long port)
96 return *(volatile unsigned short *)port;
97 else if (CHECK_SH7751_PCIIO(port))
98 return *(volatile unsigned short *)PCI_IOMAP(port);
99 else if (port >= 0x2000)
100 return *port2adr(port);
101 else if (port <= 0x3F1)
102 return *(volatile unsigned int *)ETHER_IOMAP(port);
108 unsigned int sh7751systemh_inl(unsigned long port)
111 return *(volatile unsigned long *)port;
112 else if (CHECK_SH7751_PCIIO(port))
113 return *(volatile unsigned int *)PCI_IOMAP(port);
114 else if (port >= 0x2000)
115 return *port2adr(port);
116 else if (port <= 0x3F1)
117 return *(volatile unsigned int *)ETHER_IOMAP(port);
123 void sh7751systemh_outb(unsigned char value, unsigned long port)
127 *(volatile unsigned char *)port = value;
128 else if (CHECK_SH7751_PCIIO(port))
129 *((unsigned char*)PCI_IOMAP(port)) = value;
130 else if (port <= 0x3F1)
131 *(volatile unsigned char *)ETHER_IOMAP(port) = value;
133 *(port2adr(port)) = value;
136 void sh7751systemh_outb_p(unsigned char value, unsigned long port)
139 *(volatile unsigned char *)port = value;
140 else if (CHECK_SH7751_PCIIO(port))
141 *((unsigned char*)PCI_IOMAP(port)) = value;
142 else if (port <= 0x3F1)
143 *(volatile unsigned char *)ETHER_IOMAP(port) = value;
145 *(port2adr(port)) = value;
149 void sh7751systemh_outw(unsigned short value, unsigned long port)
152 *(volatile unsigned short *)port = value;
153 else if (CHECK_SH7751_PCIIO(port))
154 *((unsigned short *)PCI_IOMAP(port)) = value;
155 else if (port >= 0x2000)
156 *port2adr(port) = value;
157 else if (port <= 0x3F1)
158 *(volatile unsigned short *)ETHER_IOMAP(port) = value;
163 void sh7751systemh_outl(unsigned int value, unsigned long port)
166 *(volatile unsigned long *)port = value;
167 else if (CHECK_SH7751_PCIIO(port))
168 *((unsigned long*)PCI_IOMAP(port)) = value;
173 void sh7751systemh_insb(unsigned long port, void *addr, unsigned long count)
175 unsigned char *p = addr;
176 while (count--) *p++ = sh7751systemh_inb(port);
179 void sh7751systemh_insw(unsigned long port, void *addr, unsigned long count)
181 unsigned short *p = addr;
182 while (count--) *p++ = sh7751systemh_inw(port);
185 void sh7751systemh_insl(unsigned long port, void *addr, unsigned long count)
190 void sh7751systemh_outsb(unsigned long port, const void *addr, unsigned long count)
192 unsigned char *p = (unsigned char*)addr;
193 while (count--) sh7751systemh_outb(*p++, port);
196 void sh7751systemh_outsw(unsigned long port, const void *addr, unsigned long count)
198 unsigned short *p = (unsigned short*)addr;
199 while (count--) sh7751systemh_outw(*p++, port);
202 void sh7751systemh_outsl(unsigned long port, const void *addr, unsigned long count)