2 * linux/arch/sh/boards/renesas/hs7751rvoip/io.c
4 * Copyright (C) 2001 Ian da Silva, Jeremy Siegel
5 * Based largely on io_se.c.
7 * I/O routine for Renesas Technology sales HS7751RVoIP
9 * Initial version only to support LAN access; some
10 * placeholder code from io_hs7751rvoip.c left in with the
11 * expectation of later SuperIO and PCMCIA access.
13 #include <linux/kernel.h>
14 #include <linux/types.h>
15 #include <linux/module.h>
16 #include <linux/pci.h>
18 #include <asm/hs7751rvoip.h>
19 #include <asm/addrspace.h>
21 extern void *area6_io8_base
; /* Area 6 8bit I/O Base address */
22 extern void *area5_io16_base
; /* Area 5 16bit I/O Base address */
25 * The 7751R HS7751RVoIP uses the built-in PCI controller (PCIC)
26 * of the 7751R processor, and has a SuperIO accessible via the PCI.
27 * The board also includes a PCMCIA controller on its memory bus,
28 * like the other Solution Engine boards.
31 #define CODEC_IO_BASE 0x1000
32 #define CODEC_IOMAP(a) ((unsigned long)area6_io8_base + ((a) - CODEC_IO_BASE))
34 static inline unsigned long port2adr(unsigned int port
)
36 if ((0x1f0 <= port
&& port
< 0x1f8) || port
== 0x3f6)
38 return ((unsigned long)area5_io16_base
+ 0x0c);
40 return ((unsigned long)area5_io16_base
+ 0x800 +
43 maybebadio((unsigned long)port
);
47 /* The 7751R HS7751RVoIP seems to have everything hooked */
48 /* up pretty normally (nothing on high-bytes only...) so this */
49 /* shouldn't be needed */
50 static inline int shifted_port(unsigned long port
)
52 /* For IDE registers, value is not shifted */
53 if ((0x1f0 <= port
&& port
< 0x1f8) || port
== 0x3f6)
59 #if defined(CONFIG_HS7751RVOIP_CODEC)
60 #define codec_port(port) \
61 ((CODEC_IO_BASE <= (port)) && ((port) < (CODEC_IO_BASE + 0x20)))
63 #define codec_port(port) (0)
67 * General outline: remap really low stuff [eventually] to SuperIO,
68 * stuff in PCI IO space (at or above window at pci.h:PCIBIOS_MIN_IO)
69 * is mapped through the PCI IO window. Stuff with high bits (PXSEG)
70 * should be way beyond the window, and is used w/o translation for
73 unsigned char hs7751rvoip_inb(unsigned long port
)
76 return ctrl_inb(port
);
77 else if (codec_port(port
))
78 return ctrl_inb(CODEC_IOMAP(port
));
79 else if (is_pci_ioaddr(port
) || shifted_port(port
))
80 return ctrl_inb(pci_ioaddr(port
));
82 return ctrl_inw(port2adr(port
)) & 0xff;
85 unsigned char hs7751rvoip_inb_p(unsigned long port
)
91 else if (codec_port(port
))
92 v
= ctrl_inb(CODEC_IOMAP(port
));
93 else if (is_pci_ioaddr(port
) || shifted_port(port
))
94 v
= ctrl_inb(pci_ioaddr(port
));
96 v
= ctrl_inw(port2adr(port
)) & 0xff;
101 unsigned short hs7751rvoip_inw(unsigned long port
)
104 return ctrl_inw(port
);
105 else if (is_pci_ioaddr(port
) || shifted_port(port
))
106 return ctrl_inw(pci_ioaddr(port
));
112 unsigned int hs7751rvoip_inl(unsigned long port
)
115 return ctrl_inl(port
);
116 else if (is_pci_ioaddr(port
) || shifted_port(port
))
117 return ctrl_inl(pci_ioaddr(port
));
123 void hs7751rvoip_outb(unsigned char value
, unsigned long port
)
127 ctrl_outb(value
, port
);
128 else if (codec_port(port
))
129 ctrl_outb(value
, CODEC_IOMAP(port
));
130 else if (is_pci_ioaddr(port
) || shifted_port(port
))
131 ctrl_outb(value
, pci_ioaddr(port
));
133 ctrl_outb(value
, port2adr(port
));
136 void hs7751rvoip_outb_p(unsigned char value
, unsigned long port
)
139 ctrl_outb(value
, port
);
140 else if (codec_port(port
))
141 ctrl_outb(value
, CODEC_IOMAP(port
));
142 else if (is_pci_ioaddr(port
) || shifted_port(port
))
143 ctrl_outb(value
, pci_ioaddr(port
));
145 ctrl_outw(value
, port2adr(port
));
150 void hs7751rvoip_outw(unsigned short value
, unsigned long port
)
153 ctrl_outw(value
, port
);
154 else if (is_pci_ioaddr(port
) || shifted_port(port
))
155 ctrl_outw(value
, pci_ioaddr(port
));
160 void hs7751rvoip_outl(unsigned int value
, unsigned long port
)
163 ctrl_outl(value
, port
);
164 else if (is_pci_ioaddr(port
) || shifted_port(port
))
165 ctrl_outl(value
, pci_ioaddr(port
));
170 void hs7751rvoip_insb(unsigned long port
, void *addr
, unsigned long count
)
176 *buf
++ = ctrl_inb(port
);
177 else if (codec_port(port
))
179 *buf
++ = ctrl_inb(CODEC_IOMAP(port
));
180 else if (is_pci_ioaddr(port
) || shifted_port(port
)) {
181 volatile u8
*bp
= (volatile u8
*)pci_ioaddr(port
);
186 volatile u16
*p
= (volatile u16
*)port2adr(port
);
193 void hs7751rvoip_insw(unsigned long port
, void *addr
, unsigned long count
)
199 p
= (volatile u16
*)port
;
200 else if (is_pci_ioaddr(port
) || shifted_port(port
))
201 p
= (volatile u16
*)pci_ioaddr(port
);
203 p
= (volatile u16
*)port2adr(port
);
208 void hs7751rvoip_insl(unsigned long port
, void *addr
, unsigned long count
)
211 if (is_pci_ioaddr(port
) || shifted_port(port
)) {
212 volatile u32
*p
= (volatile u32
*)pci_ioaddr(port
);
221 void hs7751rvoip_outsb(unsigned long port
, const void *addr
, unsigned long count
)
223 const u8
*buf
= addr
;
227 ctrl_outb(*buf
++, port
);
228 else if (codec_port(port
))
230 ctrl_outb(*buf
++, CODEC_IOMAP(port
));
231 else if (is_pci_ioaddr(port
) || shifted_port(port
)) {
232 volatile u8
*bp
= (volatile u8
*)pci_ioaddr(port
);
237 volatile u16
*p
= (volatile u16
*)port2adr(port
);
244 void hs7751rvoip_outsw(unsigned long port
, const void *addr
, unsigned long count
)
247 const u16
*buf
= addr
;
250 p
= (volatile u16
*)port
;
251 else if (is_pci_ioaddr(port
) || shifted_port(port
))
252 p
= (volatile u16
*)pci_ioaddr(port
);
254 p
= (volatile u16
*)port2adr(port
);
260 void hs7751rvoip_outsl(unsigned long port
, const void *addr
, unsigned long count
)
262 const u32
*buf
= addr
;
264 if (is_pci_ioaddr(port
) || shifted_port(port
)) {
265 volatile u32
*p
= (volatile u32
*)pci_ioaddr(port
);
273 void __iomem
*hs7751rvoip_ioport_map(unsigned long port
, unsigned int size
)
276 return (void __iomem
*)port
;
277 else if (unlikely(codec_port(port
) && (size
== 1)))
278 return (void __iomem
*)CODEC_IOMAP(port
);
279 else if (is_pci_ioaddr(port
))
280 return (void __iomem
*)pci_ioaddr(port
);
282 return (void __iomem
*)port2adr(port
);