1 /* $Id: io_generic.c,v 1.2 2003/05/04 19:29:53 lethal Exp $
3 * linux/arch/sh/kernel/io_generic.c
5 * Copyright (C) 2000 Niibe Yutaka
7 * Generic I/O routine. These can be used where a machine specific version
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
17 #include <asm/machvec.h>
18 #include <linux/module.h>
20 #if defined(CONFIG_CPU_SH3)
21 /* I'm not sure SH7709 has this kind of bug */
22 #define SH3_PCMCIA_BUG_WORKAROUND 1
23 #define DUMMY_READ_AREA6 0xba000000
26 #define PORT2ADDR(x) (sh_mv.mv_isa_port2addr(x))
28 unsigned long generic_io_base
;
30 static inline void delay(void)
35 unsigned char generic_inb(unsigned long port
)
37 return *(volatile unsigned char*)PORT2ADDR(port
);
40 unsigned short generic_inw(unsigned long port
)
42 return *(volatile unsigned short*)PORT2ADDR(port
);
45 unsigned int generic_inl(unsigned long port
)
47 return *(volatile unsigned long*)PORT2ADDR(port
);
50 unsigned char generic_inb_p(unsigned long port
)
52 unsigned long v
= *(volatile unsigned char*)PORT2ADDR(port
);
58 unsigned short generic_inw_p(unsigned long port
)
60 unsigned long v
= *(volatile unsigned short*)PORT2ADDR(port
);
66 unsigned int generic_inl_p(unsigned long port
)
68 unsigned long v
= *(volatile unsigned long*)PORT2ADDR(port
);
75 * insb/w/l all read a series of bytes/words/longs from a fixed port
76 * address. However as the port address doesn't change we only need to
77 * convert the port address to real address once.
80 void generic_insb(unsigned long port
, void *buffer
, unsigned long count
)
82 volatile unsigned char *port_addr
;
83 unsigned char *buf
=buffer
;
85 port_addr
= (volatile unsigned char *)PORT2ADDR(port
);
91 void generic_insw(unsigned long port
, void *buffer
, unsigned long count
)
93 volatile unsigned short *port_addr
;
94 unsigned short *buf
=buffer
;
96 port_addr
= (volatile unsigned short *)PORT2ADDR(port
);
100 #ifdef SH3_PCMCIA_BUG_WORKAROUND
101 ctrl_inb (DUMMY_READ_AREA6
);
105 void generic_insl(unsigned long port
, void *buffer
, unsigned long count
)
107 volatile unsigned long *port_addr
;
108 unsigned long *buf
=buffer
;
110 port_addr
= (volatile unsigned long *)PORT2ADDR(port
);
114 #ifdef SH3_PCMCIA_BUG_WORKAROUND
115 ctrl_inb (DUMMY_READ_AREA6
);
119 void generic_outb(unsigned char b
, unsigned long port
)
121 *(volatile unsigned char*)PORT2ADDR(port
) = b
;
124 void generic_outw(unsigned short b
, unsigned long port
)
126 *(volatile unsigned short*)PORT2ADDR(port
) = b
;
129 void generic_outl(unsigned int b
, unsigned long port
)
131 *(volatile unsigned long*)PORT2ADDR(port
) = b
;
134 void generic_outb_p(unsigned char b
, unsigned long port
)
136 *(volatile unsigned char*)PORT2ADDR(port
) = b
;
140 void generic_outw_p(unsigned short b
, unsigned long port
)
142 *(volatile unsigned short*)PORT2ADDR(port
) = b
;
146 void generic_outl_p(unsigned int b
, unsigned long port
)
148 *(volatile unsigned long*)PORT2ADDR(port
) = b
;
153 * outsb/w/l all write a series of bytes/words/longs to a fixed port
154 * address. However as the port address doesn't change we only need to
155 * convert the port address to real address once.
158 void generic_outsb(unsigned long port
, const void *buffer
, unsigned long count
)
160 volatile unsigned char *port_addr
;
161 const unsigned char *buf
=buffer
;
163 port_addr
= (volatile unsigned char *)PORT2ADDR(port
);
169 void generic_outsw(unsigned long port
, const void *buffer
, unsigned long count
)
171 volatile unsigned short *port_addr
;
172 const unsigned short *buf
=buffer
;
174 port_addr
= (volatile unsigned short *)PORT2ADDR(port
);
179 #ifdef SH3_PCMCIA_BUG_WORKAROUND
180 ctrl_inb (DUMMY_READ_AREA6
);
184 void generic_outsl(unsigned long port
, const void *buffer
, unsigned long count
)
186 volatile unsigned long *port_addr
;
187 const unsigned long *buf
=buffer
;
189 port_addr
= (volatile unsigned long *)PORT2ADDR(port
);
194 #ifdef SH3_PCMCIA_BUG_WORKAROUND
195 ctrl_inb (DUMMY_READ_AREA6
);
199 unsigned char generic_readb(unsigned long addr
)
201 return *(volatile unsigned char*)addr
;
204 unsigned short generic_readw(unsigned long addr
)
206 return *(volatile unsigned short*)addr
;
209 unsigned int generic_readl(unsigned long addr
)
211 return *(volatile unsigned long*)addr
;
214 void generic_writeb(unsigned char b
, unsigned long addr
)
216 *(volatile unsigned char*)addr
= b
;
219 void generic_writew(unsigned short b
, unsigned long addr
)
221 *(volatile unsigned short*)addr
= b
;
224 void generic_writel(unsigned int b
, unsigned long addr
)
226 *(volatile unsigned long*)addr
= b
;
229 void * generic_ioremap(unsigned long offset
, unsigned long size
)
231 return (void *) P2SEGADDR(offset
);
233 EXPORT_SYMBOL(generic_ioremap
);
235 void generic_iounmap(void *addr
)
238 EXPORT_SYMBOL(generic_iounmap
);
240 unsigned long generic_isa_port2addr(unsigned long offset
)
242 return offset
+ generic_io_base
;