File: /usr/src/linux/arch/sh/kernel/io_hd64461.c

1     /*
2      *	$Id: io_hd64461.c,v 1.1 2000/06/10 21:45:18 yaegashi Exp $
3      *	Copyright (C) 2000 YAEGASHI Takeshi
4      *	Typical I/O routines for HD64461 system.
5      */
6     
7     #include <linux/config.h>
8     #include <asm/io.h>
9     #include <asm/hd64461.h>
10     
11     static __inline__ unsigned long PORT2ADDR(unsigned long port)
12     {
13     	/* 16550A: HD64461 internal */
14     	if (0x3f8<=port && port<=0x3ff)
15     		return CONFIG_HD64461_IOBASE + 0x8000 + ((port-0x3f8)<<1);
16     	if (0x2f8<=port && port<=0x2ff)
17     		return CONFIG_HD64461_IOBASE + 0x7000 + ((port-0x2f8)<<1);
18     
19     #ifdef CONFIG_HD64461_ENABLER
20     	/* NE2000: HD64461 PCMCIA channel 0 (I/O) */
21     	if (0x300<=port && port<=0x31f)
22     		return 0xba000000 + port;
23     
24     	/* ide0: HD64461 PCMCIA channel 1 (memory) */
25     	/* On HP690, CF in slot 1 is configured as a memory card
26     	   device.  See CF+ and CompactFlash Specification for the
27     	   detail of CF's memory mapped addressing. */
28     	if (0x1f0<=port && port<=0x1f7)	return 0xb5000000 + port;
29     	if (port == 0x3f6) return 0xb50001fe;
30     	if (port == 0x3f7) return 0xb50001ff;
31     
32     	/* ide1 */
33     	if (0x170<=port && port<=0x177)	return 0xba000000 + port;
34     	if (port == 0x376) return 0xba000376;
35     	if (port == 0x377) return 0xba000377;
36     #endif
37     
38     	/* ??? */
39     	if (port < 0x10000) return 0xa0000000 + port;
40     
41     	/* HD64461 internal devices (0xb0000000) */
42     	if (port < 0x20000) return CONFIG_HD64461_IOBASE + port - 0x10000;
43     
44     	/* PCMCIA channel 0, I/O (0xba000000) */
45     	if (port < 0x30000) return 0xba000000 + port - 0x20000;
46     
47     	/* PCMCIA channel 1, memory (0xb5000000) */
48     	if (port < 0x40000) return 0xb5000000 + port - 0x30000;
49     
50     	/* Whole physical address space (0xa0000000) */
51     	return 0xa0000000 + (port & 0x1fffffff);
52     }
53     
54     static inline void delay(void)
55     {
56     	ctrl_inw(0xa0000000);
57     }
58     
59     unsigned char hd64461_inb(unsigned long port)
60     {
61     	return *(volatile unsigned char*)PORT2ADDR(port);
62     }
63     
64     unsigned char hd64461_inb_p(unsigned long port)
65     {
66     	unsigned long v = *(volatile unsigned char*)PORT2ADDR(port);
67     	delay();
68     	return v;
69     }
70     
71     unsigned short hd64461_inw(unsigned long port)
72     {
73     	return *(volatile unsigned short*)PORT2ADDR(port);
74     }
75     
76     unsigned int hd64461_inl(unsigned long port)
77     {
78     	return *(volatile unsigned long*)PORT2ADDR(port);
79     }
80     
81     void hd64461_insb(unsigned long port, void *buffer, unsigned long count)
82     {
83     	unsigned char *buf=buffer;
84     	while(count--) *buf++=inb(port);
85     }
86     
87     void hd64461_insw(unsigned long port, void *buffer, unsigned long count)
88     {
89     	unsigned short *buf=buffer;
90     	while(count--) *buf++=inw(port);
91     }
92     
93     void hd64461_insl(unsigned long port, void *buffer, unsigned long count)
94     {
95     	unsigned long *buf=buffer;
96     	while(count--) *buf++=inl(port);
97     }
98     
99     void hd64461_outb(unsigned char b, unsigned long port)
100     {
101     	*(volatile unsigned char*)PORT2ADDR(port) = b;
102     }
103     
104     void hd64461_outb_p(unsigned char b, unsigned long port)
105     {
106     	*(volatile unsigned char*)PORT2ADDR(port) = b;
107     	delay();
108     }
109     
110     void hd64461_outw(unsigned short b, unsigned long port)
111     {
112     	*(volatile unsigned short*)PORT2ADDR(port) = b;
113     }
114     
115     void hd64461_outl(unsigned int b, unsigned long port)
116     {
117             *(volatile unsigned long*)PORT2ADDR(port) = b;
118     }
119     
120     void hd64461_outsb(unsigned long port, const void *buffer, unsigned long count)
121     {
122     	const unsigned char *buf=buffer;
123     	while(count--) outb(*buf++, port);
124     }
125     
126     void hd64461_outsw(unsigned long port, const void *buffer, unsigned long count)
127     {
128     	const unsigned short *buf=buffer;
129     	while(count--) outw(*buf++, port);
130     }
131     
132     void hd64461_outsl(unsigned long port, const void *buffer, unsigned long count)
133     {
134     	const unsigned long *buf=buffer;
135     	while(count--) outl(*buf++, port);
136     }
137