2 * linux/arch/sh/boards/superh/microdev/io.c
4 * Copyright (C) 2003 Sean McGoogan (Sean.McGoogan@superh.com)
5 * Copyright (C) 2003, 2004 SuperH, Inc.
6 * Copyright (C) 2004 Paul Mundt
8 * SuperH SH4-202 MicroDev board support.
10 * May be copied or modified under the terms of the GNU General Public
11 * License. See linux/COPYING for more information.
14 #include <linux/init.h>
15 #include <linux/pci.h>
16 #include <linux/wait.h>
18 #include <mach/microdev.h>
21 * we need to have a 'safe' address to re-direct all I/O requests
22 * that we do not explicitly wish to handle. This safe address
23 * must have the following properies:
25 * * writes are ignored (no exception)
26 * * reads are benign (no side-effects)
27 * * accesses of width 1, 2 and 4-bytes are all valid.
29 * The Processor Version Register (PVR) has these properties.
31 #define PVR 0xff000030 /* Processor Version Register */
34 #define IO_IDE2_BASE 0x170ul /* I/O base for SMSC FDC37C93xAPM IDE #2 */
35 #define IO_IDE1_BASE 0x1f0ul /* I/O base for SMSC FDC37C93xAPM IDE #1 */
36 #define IO_ISP1161_BASE 0x290ul /* I/O port for Philips ISP1161x USB chip */
37 #define IO_SERIAL2_BASE 0x2f8ul /* I/O base for SMSC FDC37C93xAPM Serial #2 */
38 #define IO_LAN91C111_BASE 0x300ul /* I/O base for SMSC LAN91C111 Ethernet chip */
39 #define IO_IDE2_MISC 0x376ul /* I/O misc for SMSC FDC37C93xAPM IDE #2 */
40 #define IO_SUPERIO_BASE 0x3f0ul /* I/O base for SMSC FDC37C93xAPM SuperIO chip */
41 #define IO_IDE1_MISC 0x3f6ul /* I/O misc for SMSC FDC37C93xAPM IDE #1 */
42 #define IO_SERIAL1_BASE 0x3f8ul /* I/O base for SMSC FDC37C93xAPM Serial #1 */
44 #define IO_ISP1161_EXTENT 0x04ul /* I/O extent for Philips ISP1161x USB chip */
45 #define IO_LAN91C111_EXTENT 0x10ul /* I/O extent for SMSC LAN91C111 Ethernet chip */
46 #define IO_SUPERIO_EXTENT 0x02ul /* I/O extent for SMSC FDC37C93xAPM SuperIO chip */
47 #define IO_IDE_EXTENT 0x08ul /* I/O extent for IDE Task Register set */
48 #define IO_SERIAL_EXTENT 0x10ul
50 #define IO_LAN91C111_PHYS 0xa7500000ul /* Physical address of SMSC LAN91C111 Ethernet chip */
51 #define IO_ISP1161_PHYS 0xa7700000ul /* Physical address of Philips ISP1161x USB chip */
52 #define IO_SUPERIO_PHYS 0xa7800000ul /* Physical address of SMSC FDC37C93xAPM SuperIO chip */
55 * map I/O ports to memory-mapped addresses
57 static unsigned long microdev_isa_port2addr(unsigned long offset
)
61 if ((offset
>= IO_LAN91C111_BASE
) &&
62 (offset
< IO_LAN91C111_BASE
+ IO_LAN91C111_EXTENT
)) {
64 * SMSC LAN91C111 Ethernet chip
66 result
= IO_LAN91C111_PHYS
+ offset
- IO_LAN91C111_BASE
;
67 } else if ((offset
>= IO_SUPERIO_BASE
) &&
68 (offset
< IO_SUPERIO_BASE
+ IO_SUPERIO_EXTENT
)) {
70 * SMSC FDC37C93xAPM SuperIO chip
72 * Configuration Registers
74 result
= IO_SUPERIO_PHYS
+ (offset
<< 1);
75 } else if (((offset
>= IO_IDE1_BASE
) &&
76 (offset
< IO_IDE1_BASE
+ IO_IDE_EXTENT
)) ||
77 (offset
== IO_IDE1_MISC
)) {
79 * SMSC FDC37C93xAPM SuperIO chip
83 result
= IO_SUPERIO_PHYS
+ (offset
<< 1);
84 } else if (((offset
>= IO_IDE2_BASE
) &&
85 (offset
< IO_IDE2_BASE
+ IO_IDE_EXTENT
)) ||
86 (offset
== IO_IDE2_MISC
)) {
88 * SMSC FDC37C93xAPM SuperIO chip
92 result
= IO_SUPERIO_PHYS
+ (offset
<< 1);
93 } else if ((offset
>= IO_SERIAL1_BASE
) &&
94 (offset
< IO_SERIAL1_BASE
+ IO_SERIAL_EXTENT
)) {
96 * SMSC FDC37C93xAPM SuperIO chip
100 result
= IO_SUPERIO_PHYS
+ (offset
<< 1);
101 } else if ((offset
>= IO_SERIAL2_BASE
) &&
102 (offset
< IO_SERIAL2_BASE
+ IO_SERIAL_EXTENT
)) {
104 * SMSC FDC37C93xAPM SuperIO chip
108 result
= IO_SUPERIO_PHYS
+ (offset
<< 1);
109 } else if ((offset
>= IO_ISP1161_BASE
) &&
110 (offset
< IO_ISP1161_BASE
+ IO_ISP1161_EXTENT
)) {
112 * Philips USB ISP1161x chip
114 result
= IO_ISP1161_PHYS
+ offset
- IO_ISP1161_BASE
;
119 printk("Warning: unexpected port in %s( offset = 0x%lx )\n",
127 #define PORT2ADDR(x) (microdev_isa_port2addr(x))
129 static inline void delay(void)
131 #if defined(CONFIG_PCI)
132 /* System board present, just make a dummy SRAM access. (CS0 will be
133 mapped to PCI memory, probably good to avoid it.) */
134 __raw_readw(0xa6800000);
136 /* CS0 will be mapped to flash, ROM etc so safe to access it. */
137 __raw_readw(0xa0000000);
141 unsigned char microdev_inb(unsigned long port
)
144 if (port
>= PCIBIOS_MIN_IO
)
145 return microdev_pci_inb(port
);
147 return *(volatile unsigned char*)PORT2ADDR(port
);
150 unsigned short microdev_inw(unsigned long port
)
153 if (port
>= PCIBIOS_MIN_IO
)
154 return microdev_pci_inw(port
);
156 return *(volatile unsigned short*)PORT2ADDR(port
);
159 unsigned int microdev_inl(unsigned long port
)
162 if (port
>= PCIBIOS_MIN_IO
)
163 return microdev_pci_inl(port
);
165 return *(volatile unsigned int*)PORT2ADDR(port
);
168 void microdev_outw(unsigned short b
, unsigned long port
)
171 if (port
>= PCIBIOS_MIN_IO
) {
172 microdev_pci_outw(b
, port
);
176 *(volatile unsigned short*)PORT2ADDR(port
) = b
;
179 void microdev_outb(unsigned char b
, unsigned long port
)
182 if (port
>= PCIBIOS_MIN_IO
) {
183 microdev_pci_outb(b
, port
);
189 * There is a board feature with the current SH4-202 MicroDev in
190 * that the 2 byte enables (nBE0 and nBE1) are tied together (and
191 * to the Chip Select Line (Ethernet_CS)). Due to this connectivity,
192 * it is not possible to safely perform 8-bit writes to the
193 * Ethernet registers, as 16-bits will be consumed from the Data
194 * lines (corrupting the other byte). Hence, this function is
195 * written to implement 16-bit read/modify/write for all byte-wide
198 * Note: there is no problem with byte READS (even or odd).
200 * Sean McGoogan - 16th June 2003.
202 if ((port
>= IO_LAN91C111_BASE
) &&
203 (port
< IO_LAN91C111_BASE
+ IO_LAN91C111_EXTENT
)) {
205 * Then are trying to perform a byte-write to the
206 * LAN91C111. This needs special care.
208 if (port
% 2 == 1) { /* is the port odd ? */
209 /* unset bit-0, i.e. make even */
210 const unsigned long evenPort
= port
-1;
214 * do a 16-bit read/write to write to 'port',
215 * preserving even byte.
217 * Even addresses are bits 0-7
218 * Odd addresses are bits 8-15
220 word
= microdev_inw(evenPort
);
221 word
= (word
& 0xffu
) | (b
<< 8);
222 microdev_outw(word
, evenPort
);
224 /* else, we are trying to do an even byte write */
228 * do a 16-bit read/write to write to 'port',
229 * preserving odd byte.
231 * Even addresses are bits 0-7
232 * Odd addresses are bits 8-15
234 word
= microdev_inw(port
);
235 word
= (word
& 0xff00u
) | (b
);
236 microdev_outw(word
, port
);
239 *(volatile unsigned char*)PORT2ADDR(port
) = b
;
243 void microdev_outl(unsigned int b
, unsigned long port
)
246 if (port
>= PCIBIOS_MIN_IO
) {
247 microdev_pci_outl(b
, port
);
251 *(volatile unsigned int*)PORT2ADDR(port
) = b
;
254 unsigned char microdev_inb_p(unsigned long port
)
256 unsigned char v
= microdev_inb(port
);
261 unsigned short microdev_inw_p(unsigned long port
)
263 unsigned short v
= microdev_inw(port
);
268 unsigned int microdev_inl_p(unsigned long port
)
270 unsigned int v
= microdev_inl(port
);
275 void microdev_outb_p(unsigned char b
, unsigned long port
)
277 microdev_outb(b
, port
);
281 void microdev_outw_p(unsigned short b
, unsigned long port
)
283 microdev_outw(b
, port
);
287 void microdev_outl_p(unsigned int b
, unsigned long port
)
289 microdev_outl(b
, port
);
293 void microdev_insb(unsigned long port
, void *buffer
, unsigned long count
)
295 volatile unsigned char *port_addr
;
296 unsigned char *buf
= buffer
;
298 port_addr
= (volatile unsigned char *)PORT2ADDR(port
);
304 void microdev_insw(unsigned long port
, void *buffer
, unsigned long count
)
306 volatile unsigned short *port_addr
;
307 unsigned short *buf
= buffer
;
309 port_addr
= (volatile unsigned short *)PORT2ADDR(port
);
315 void microdev_insl(unsigned long port
, void *buffer
, unsigned long count
)
317 volatile unsigned long *port_addr
;
318 unsigned int *buf
= buffer
;
320 port_addr
= (volatile unsigned long *)PORT2ADDR(port
);
326 void microdev_outsb(unsigned long port
, const void *buffer
, unsigned long count
)
328 volatile unsigned char *port_addr
;
329 const unsigned char *buf
= buffer
;
331 port_addr
= (volatile unsigned char *)PORT2ADDR(port
);
337 void microdev_outsw(unsigned long port
, const void *buffer
, unsigned long count
)
339 volatile unsigned short *port_addr
;
340 const unsigned short *buf
= buffer
;
342 port_addr
= (volatile unsigned short *)PORT2ADDR(port
);
348 void microdev_outsl(unsigned long port
, const void *buffer
, unsigned long count
)
350 volatile unsigned long *port_addr
;
351 const unsigned int *buf
= buffer
;
353 port_addr
= (volatile unsigned long *)PORT2ADDR(port
);