2 * linux/arch/sh/kernel/io_microdev.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/config.h>
15 #include <linux/init.h>
16 #include <linux/pci.h>
17 #include <linux/wait.h>
19 #include <asm/mach/io.h>
22 * we need to have a 'safe' address to re-direct all I/O requests
23 * that we do not explicitly wish to handle. This safe address
24 * must have the following properies:
26 * * writes are ignored (no exception)
27 * * reads are benign (no side-effects)
28 * * accesses of width 1, 2 and 4-bytes are all valid.
30 * The Processor Version Register (PVR) has these properties.
32 #define PVR 0xff000030 /* Processor Version Register */
35 #define IO_IDE2_BASE 0x170ul /* I/O base for SMSC FDC37C93xAPM IDE #2 */
36 #define IO_IDE1_BASE 0x1f0ul /* I/O base for SMSC FDC37C93xAPM IDE #1 */
37 #define IO_ISP1161_BASE 0x290ul /* I/O port for Philips ISP1161x USB chip */
38 #define IO_SERIAL2_BASE 0x2f8ul /* I/O base for SMSC FDC37C93xAPM Serial #2 */
39 #define IO_LAN91C111_BASE 0x300ul /* I/O base for SMSC LAN91C111 Ethernet chip */
40 #define IO_IDE2_MISC 0x376ul /* I/O misc for SMSC FDC37C93xAPM IDE #2 */
41 #define IO_SUPERIO_BASE 0x3f0ul /* I/O base for SMSC FDC37C93xAPM SuperIO chip */
42 #define IO_IDE1_MISC 0x3f6ul /* I/O misc for SMSC FDC37C93xAPM IDE #1 */
43 #define IO_SERIAL1_BASE 0x3f8ul /* I/O base for SMSC FDC37C93xAPM Serial #1 */
45 #define IO_ISP1161_EXTENT 0x04ul /* I/O extent for Philips ISP1161x USB chip */
46 #define IO_LAN91C111_EXTENT 0x10ul /* I/O extent for SMSC LAN91C111 Ethernet chip */
47 #define IO_SUPERIO_EXTENT 0x02ul /* I/O extent for SMSC FDC37C93xAPM SuperIO chip */
48 #define IO_IDE_EXTENT 0x08ul /* I/O extent for IDE Task Register set */
49 #define IO_SERIAL_EXTENT 0x10ul
51 #define IO_LAN91C111_PHYS 0xa7500000ul /* Physical address of SMSC LAN91C111 Ethernet chip */
52 #define IO_ISP1161_PHYS 0xa7700000ul /* Physical address of Philips ISP1161x USB chip */
53 #define IO_SUPERIO_PHYS 0xa7800000ul /* Physical address of SMSC FDC37C93xAPM SuperIO chip */
55 #define PORT2ADDR(x) (microdev_isa_port2addr(x))
58 static inline void delay(void)
60 #if defined(CONFIG_PCI)
61 /* System board present, just make a dummy SRAM access. (CS0 will be
62 mapped to PCI memory, probably good to avoid it.) */
65 /* CS0 will be mapped to flash, ROM etc so safe to access it. */
70 unsigned char microdev_inb(unsigned long port
)
73 if (port
>= PCIBIOS_MIN_IO
)
74 return microdev_pci_inb(port
);
76 return *(volatile unsigned char*)PORT2ADDR(port
);
79 unsigned short microdev_inw(unsigned long port
)
82 if (port
>= PCIBIOS_MIN_IO
)
83 return microdev_pci_inw(port
);
85 return *(volatile unsigned short*)PORT2ADDR(port
);
88 unsigned int microdev_inl(unsigned long port
)
91 if (port
>= PCIBIOS_MIN_IO
)
92 return microdev_pci_inl(port
);
94 return *(volatile unsigned int*)PORT2ADDR(port
);
97 void microdev_outb(unsigned char b
, unsigned long port
)
100 if (port
>= PCIBIOS_MIN_IO
) {
101 microdev_pci_outb(b
, port
);
107 * There is a board feature with the current SH4-202 MicroDev in
108 * that the 2 byte enables (nBE0 and nBE1) are tied together (and
109 * to the Chip Select Line (Ethernet_CS)). Due to this conectivity,
110 * it is not possible to safely perform 8-bit writes to the
111 * Ethernet registers, as 16-bits will be consumed from the Data
112 * lines (corrupting the other byte). Hence, this function is
113 * written to impliment 16-bit read/modify/write for all byte-wide
116 * Note: there is no problem with byte READS (even or odd).
118 * Sean McGoogan - 16th June 2003.
120 if ((port
>= IO_LAN91C111_BASE
) &&
121 (port
< IO_LAN91C111_BASE
+ IO_LAN91C111_EXTENT
)) {
123 * Then are trying to perform a byte-write to the
124 * LAN91C111. This needs special care.
126 if (port
% 2 == 1) { /* is the port odd ? */
127 /* unset bit-0, i.e. make even */
128 const unsigned long evenPort
= port
-1;
132 * do a 16-bit read/write to write to 'port',
133 * preserving even byte.
135 * Even addresses are bits 0-7
136 * Odd addresses are bits 8-15
138 word
= microdev_inw(evenPort
);
139 word
= (word
& 0xffu
) | (b
<< 8);
140 microdev_outw(word
, evenPort
);
142 /* else, we are trying to do an even byte write */
146 * do a 16-bit read/write to write to 'port',
147 * preserving odd byte.
149 * Even addresses are bits 0-7
150 * Odd addresses are bits 8-15
152 word
= microdev_inw(port
);
153 word
= (word
& 0xff00u
) | (b
);
154 microdev_outw(word
, port
);
157 *(volatile unsigned char*)PORT2ADDR(port
) = b
;
161 void microdev_outw(unsigned short b
, unsigned long port
)
164 if (port
>= PCIBIOS_MIN_IO
) {
165 microdev_pci_outw(b
, port
);
169 *(volatile unsigned short*)PORT2ADDR(port
) = b
;
172 void microdev_outl(unsigned int b
, unsigned long port
)
175 if (port
>= PCIBIOS_MIN_IO
) {
176 microdev_pci_outl(b
, port
);
180 *(volatile unsigned int*)PORT2ADDR(port
) = b
;
183 unsigned char microdev_inb_p(unsigned long port
)
185 unsigned char v
= microdev_inb(port
);
190 unsigned short microdev_inw_p(unsigned long port
)
192 unsigned short v
= microdev_inw(port
);
197 unsigned int microdev_inl_p(unsigned long port
)
199 unsigned int v
= microdev_inl(port
);
204 void microdev_outb_p(unsigned char b
, unsigned long port
)
206 microdev_outb(b
, port
);
210 void microdev_outw_p(unsigned short b
, unsigned long port
)
212 microdev_outw(b
, port
);
216 void microdev_outl_p(unsigned int b
, unsigned long port
)
218 microdev_outl(b
, port
);
222 void microdev_insb(unsigned long port
, void *buffer
, unsigned long count
)
224 volatile unsigned char *port_addr
;
225 unsigned char *buf
= buffer
;
227 port_addr
= (volatile unsigned char *)PORT2ADDR(port
);
233 void microdev_insw(unsigned long port
, void *buffer
, unsigned long count
)
235 volatile unsigned short *port_addr
;
236 unsigned short *buf
= buffer
;
238 port_addr
= (volatile unsigned short *)PORT2ADDR(port
);
244 void microdev_insl(unsigned long port
, void *buffer
, unsigned long count
)
246 volatile unsigned long *port_addr
;
247 unsigned int *buf
= buffer
;
249 port_addr
= (volatile unsigned long *)PORT2ADDR(port
);
255 void microdev_outsb(unsigned long port
, const void *buffer
, unsigned long count
)
257 volatile unsigned char *port_addr
;
258 const unsigned char *buf
= buffer
;
260 port_addr
= (volatile unsigned char *)PORT2ADDR(port
);
266 void microdev_outsw(unsigned long port
, const void *buffer
, unsigned long count
)
268 volatile unsigned short *port_addr
;
269 const unsigned short *buf
= buffer
;
271 port_addr
= (volatile unsigned short *)PORT2ADDR(port
);
277 void microdev_outsl(unsigned long port
, const void *buffer
, unsigned long count
)
279 volatile unsigned long *port_addr
;
280 const unsigned int *buf
= buffer
;
282 port_addr
= (volatile unsigned long *)PORT2ADDR(port
);
289 * map I/O ports to memory-mapped addresses
291 unsigned long microdev_isa_port2addr(unsigned long offset
)
293 unsigned long result
;
295 if ((offset
>= IO_LAN91C111_BASE
) &&
296 (offset
< IO_LAN91C111_BASE
+ IO_LAN91C111_EXTENT
)) {
298 * SMSC LAN91C111 Ethernet chip
300 result
= IO_LAN91C111_PHYS
+ offset
- IO_LAN91C111_BASE
;
301 } else if ((offset
>= IO_SUPERIO_BASE
) &&
302 (offset
< IO_SUPERIO_BASE
+ IO_SUPERIO_EXTENT
)) {
304 * SMSC FDC37C93xAPM SuperIO chip
306 * Configuration Registers
308 result
= IO_SUPERIO_PHYS
+ (offset
<< 1);
310 } else if (offset
== KBD_DATA_REG
|| offset
== KBD_CNTL_REG
||
311 offset
== KBD_STATUS_REG
) {
313 * SMSC FDC37C93xAPM SuperIO chip
315 * PS/2 Keyboard + Mouse (ports 0x60 and 0x64).
317 result
= IO_SUPERIO_PHYS
+ (offset
<< 1);
319 } else if (((offset
>= IO_IDE1_BASE
) &&
320 (offset
< IO_IDE1_BASE
+ IO_IDE_EXTENT
)) ||
321 (offset
== IO_IDE1_MISC
)) {
323 * SMSC FDC37C93xAPM SuperIO chip
327 result
= IO_SUPERIO_PHYS
+ (offset
<< 1);
328 } else if (((offset
>= IO_IDE2_BASE
) &&
329 (offset
< IO_IDE2_BASE
+ IO_IDE_EXTENT
)) ||
330 (offset
== IO_IDE2_MISC
)) {
332 * SMSC FDC37C93xAPM SuperIO chip
336 result
= IO_SUPERIO_PHYS
+ (offset
<< 1);
337 } else if ((offset
>= IO_SERIAL1_BASE
) &&
338 (offset
< IO_SERIAL1_BASE
+ IO_SERIAL_EXTENT
)) {
340 * SMSC FDC37C93xAPM SuperIO chip
344 result
= IO_SUPERIO_PHYS
+ (offset
<< 1);
345 } else if ((offset
>= IO_SERIAL2_BASE
) &&
346 (offset
< IO_SERIAL2_BASE
+ IO_SERIAL_EXTENT
)) {
348 * SMSC FDC37C93xAPM SuperIO chip
352 result
= IO_SUPERIO_PHYS
+ (offset
<< 1);
353 } else if ((offset
>= IO_ISP1161_BASE
) &&
354 (offset
< IO_ISP1161_BASE
+ IO_ISP1161_EXTENT
)) {
356 * Philips USB ISP1161x chip
358 result
= IO_ISP1161_PHYS
+ offset
- IO_ISP1161_BASE
;
363 printk("Warning: unexpected port in %s( offset = 0x%lx )\n",
364 __FUNCTION__
, offset
);