blob: 1308e618e044d1a5aaa996ac934e26cb15201163 [file] [log] [blame]
Yoshinori Satof36af3fd2006-11-05 16:21:09 +09001/* $Id: io.c,v 1.5 2004/02/22 23:08:43 kkojima Exp $
2 *
3 * linux/arch/sh/boards/se/7206/io.c
4 *
5 * Copyright (C) 2006 Yoshinori Sato
6 *
7 * I/O routine for Hitachi 7206 SolutionEngine.
8 *
9 */
10
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <asm/io.h>
14#include <asm/se7206.h>
15
16
17static inline void delay(void)
18{
19 ctrl_inw(0x20000000); /* P2 ROM Area */
20}
21
22/* MS7750 requires special versions of in*, out* routines, since
23 PC-like io ports are located at upper half byte of 16-bit word which
24 can be accessed only with 16-bit wide. */
25
26static inline volatile __u16 *
27port2adr(unsigned int port)
28{
Paul Mundtdfcb7602007-09-13 12:59:32 +090029 if (port >= 0x2000 && port < 0x2020)
Yoshinori Satof36af3fd2006-11-05 16:21:09 +090030 return (volatile __u16 *) (PA_MRSHPC + (port - 0x2000));
Paul Mundtdfcb7602007-09-13 12:59:32 +090031 else if (port >= 0x300 && port < 0x310)
Yoshinori Satof36af3fd2006-11-05 16:21:09 +090032 return (volatile __u16 *) (PA_SMSC + (port - 0x300));
Paul Mundt8f3dc132007-09-18 15:41:39 +090033
34 return (volatile __u16 *)port;
Yoshinori Satof36af3fd2006-11-05 16:21:09 +090035}
36
37unsigned char se7206_inb(unsigned long port)
38{
Paul Mundtdfcb7602007-09-13 12:59:32 +090039 return (*port2adr(port)) & 0xff;
Yoshinori Satof36af3fd2006-11-05 16:21:09 +090040}
41
42unsigned char se7206_inb_p(unsigned long port)
43{
44 unsigned long v;
45
Paul Mundtdfcb7602007-09-13 12:59:32 +090046 v = (*port2adr(port)) & 0xff;
Yoshinori Satof36af3fd2006-11-05 16:21:09 +090047 delay();
48 return v;
49}
50
51unsigned short se7206_inw(unsigned long port)
52{
53 return *port2adr(port);;
54}
55
Yoshinori Satof36af3fd2006-11-05 16:21:09 +090056void se7206_outb(unsigned char value, unsigned long port)
57{
58 *(port2adr(port)) = value;
59}
60
61void se7206_outb_p(unsigned char value, unsigned long port)
62{
63 *(port2adr(port)) = value;
64 delay();
65}
66
67void se7206_outw(unsigned short value, unsigned long port)
68{
69 *port2adr(port) = value;
70}
71
Yoshinori Satof36af3fd2006-11-05 16:21:09 +090072void se7206_insb(unsigned long port, void *addr, unsigned long count)
73{
74 volatile __u16 *p = port2adr(port);
75 __u8 *ap = addr;
76
77 while (count--)
78 *ap++ = *p;
79}
80
81void se7206_insw(unsigned long port, void *addr, unsigned long count)
82{
83 volatile __u16 *p = port2adr(port);
84 __u16 *ap = addr;
85 while (count--)
86 *ap++ = *p;
87}
88
Yoshinori Satof36af3fd2006-11-05 16:21:09 +090089void se7206_outsb(unsigned long port, const void *addr, unsigned long count)
90{
91 volatile __u16 *p = port2adr(port);
92 const __u8 *ap = addr;
93
94 while (count--)
95 *p = *ap++;
96}
97
98void se7206_outsw(unsigned long port, const void *addr, unsigned long count)
99{
100 volatile __u16 *p = port2adr(port);
101 const __u16 *ap = addr;
102 while (count--)
103 *p = *ap++;
104}