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