ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-h8300 / io.h
1 #ifndef _H8300_IO_H
2 #define _H8300_IO_H
3
4 #ifdef __KERNEL__
5
6 #include <linux/config.h>
7 #include <asm/virtconvert.h>
8
9 #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
10 #include <asm/regs306x.h>
11 #elif defined(CONFIG_H8S2678)
12 #include <asm/regs267x.h>
13 #else
14 #error UNKNOWN CPU TYPE
15 #endif
16
17
18 /*
19  * These are for ISA/PCI shared memory _only_ and should never be used
20  * on any other type of memory, including Zorro memory. They are meant to
21  * access the bus in the bus byte order which is little-endian!.
22  *
23  * readX/writeX() are used to access memory mapped devices. On some
24  * architectures the memory mapped IO stuff needs to be accessed
25  * differently. On the m68k architecture, we just read/write the
26  * memory location directly.
27  */
28 /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
29  * two accesses to memory, which may be undesireable for some devices.
30  */
31
32 /*
33  * swap functions are sometimes needed to interface little-endian hardware
34  */
35
36 /*
37  * CHANGES
38  * 
39  * 020325   Added some #define's for the COBRA5272 board
40  *          (hede)
41  */
42
43 static inline unsigned short _swapw(volatile unsigned short v)
44 {
45     return ((v << 8) | (v >> 8));
46 }
47
48 static inline unsigned int _swapl(volatile unsigned long v)
49 {
50     return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
51 }
52
53 #define readb(addr) \
54     ({ unsigned char __v = (*(volatile unsigned char *) ((addr) & 0x00ffffff)); __v; })
55 #define readw(addr) \
56     ({ unsigned short __v = (*(volatile unsigned short *) ((addr) & 0x00ffffff)); __v; })
57 #define readl(addr) \
58     ({ unsigned int __v = (*(volatile unsigned int *) ((addr) & 0x00ffffff)); __v; })
59
60 #define writeb(b,addr) (void)((*(volatile unsigned char *) ((addr) & 0x00ffffff)) = (b))
61 #define writew(b,addr) (void)((*(volatile unsigned short *) ((addr) & 0x00ffffff)) = (b))
62 #define writel(b,addr) (void)((*(volatile unsigned int *) ((addr) & 0x00ffffff)) = (b))
63 #define readb_relaxed(addr) readb(addr)
64 #define readw_relaxed(addr) readw(addr)
65 #define readl_relaxed(addr) readl(addr)
66
67 #define __raw_readb readb
68 #define __raw_readw readw
69 #define __raw_readl readl
70 #define __raw_writeb writeb
71 #define __raw_writew writew
72 #define __raw_writel writel
73
74 static inline int h8300_buswidth(unsigned int addr)
75 {
76         return (*(volatile unsigned char *)ABWCR & (1 << ((addr >> 21) & 7))) == 0;
77 }
78
79 static inline void io_outsb(unsigned int addr, void *buf, int len)
80 {
81         volatile unsigned char  *ap_b = (volatile unsigned char *) addr;
82         volatile unsigned short *ap_w = (volatile unsigned short *) addr;
83         unsigned char *bp = (unsigned char *) buf;
84
85         if(h8300_buswidth(addr) && (addr & 1)) {
86                 while (len--)
87                         *ap_w = *bp++;
88         } else {
89                 while (len--)
90                         *ap_b = *bp++;
91         }
92 }
93
94 static inline void io_outsw(unsigned int addr, void *buf, int len)
95 {
96         volatile unsigned short *ap = (volatile unsigned short *) addr;
97         unsigned short *bp = (unsigned short *) buf;
98         while (len--)
99                 *ap = *bp++;
100 }
101
102 static inline void io_outsl(unsigned int addr, void *buf, int len)
103 {
104         volatile unsigned int *ap = (volatile unsigned int *) addr;
105         unsigned int *bp = (unsigned int *) buf;
106         while (len--)
107                 *ap = *bp++;
108 }
109
110 static inline void io_insb(unsigned int addr, void *buf, int len)
111 {
112         volatile unsigned char  *ap;
113         unsigned char *bp = (unsigned char *) buf;
114
115         if(h8300_buswidth(addr))
116                 ap = (volatile unsigned char *)(addr ^ 1);
117         else
118                 ap = (volatile unsigned char *)addr;
119         while (len--)
120                 *bp++ = *ap;
121 }
122
123 static inline void io_insw(unsigned int addr, void *buf, int len)
124 {
125         volatile unsigned short *ap = (volatile unsigned short *) addr;
126         unsigned short *bp = (unsigned short *) buf;
127         while (len--)
128                 *bp++ = *ap;
129 }
130
131 static inline void io_insl(unsigned int addr, void *buf, int len)
132 {
133         volatile unsigned int *ap = (volatile unsigned int *) addr;
134         unsigned int *bp = (unsigned int *) buf;
135         while (len--)
136                 *bp++ = *ap;
137 }
138
139 /*
140  *      make the short names macros so specific devices
141  *      can override them as required
142  */
143
144 #define memset_io(a,b,c)        memset((void *)(a),(b),(c))
145 #define memcpy_fromio(a,b,c)    memcpy((a),(void *)(b),(c))
146 #define memcpy_toio(a,b,c)      memcpy((void *)(a),(b),(c))
147
148 #define inb(addr)    ((h8300_buswidth(addr))?readb((addr) ^ 1) & 0xff:readb(addr))
149 #define inw(addr)    _swapw(readw(addr))
150 #define inl(addr)    _swapl(readl(addr))
151 #define outb(x,addr) ((void)((h8300_buswidth(addr) && ((addr) & 1))?writew(x,addr):writeb(x,addr)))
152 #define outw(x,addr) ((void) writew(_swapw(x),addr))
153 #define outl(x,addr) ((void) writel(_swapl(x),addr))
154
155 #define inb_p(addr)    inb(addr)
156 #define inw_p(addr)    inw(addr)
157 #define inl_p(addr)    inl(addr)
158 #define outb_p(x,addr) outb(x,addr)
159 #define outw_p(x,addr) outw(x,addr)
160 #define outl_p(x,addr) outl(x,addr)
161
162 #define outsb(a,b,l) io_outsb(a,b,l)
163 #define outsw(a,b,l) io_outsw(a,b,l)
164 #define outsl(a,b,l) io_outsl(a,b,l)
165
166 #define insb(a,b,l) io_insb(a,b,l)
167 #define insw(a,b,l) io_insw(a,b,l)
168 #define insl(a,b,l) io_insl(a,b,l)
169
170 #define IO_SPACE_LIMIT 0xffffff
171
172
173 /* Values for nocacheflag and cmode */
174 #define IOMAP_FULL_CACHING              0
175 #define IOMAP_NOCACHE_SER               1
176 #define IOMAP_NOCACHE_NONSER            2
177 #define IOMAP_WRITETHROUGH              3
178
179 extern void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
180 extern void __iounmap(void *addr, unsigned long size);
181
182 static inline void *ioremap(unsigned long physaddr, unsigned long size)
183 {
184         return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
185 }
186 static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
187 {
188         return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
189 }
190 static inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size)
191 {
192         return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
193 }
194 static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
195 {
196         return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
197 }
198
199 extern void iounmap(void *addr);
200
201 /* Nothing to do */
202
203 #define dma_cache_inv(_start,_size)             do { } while (0)
204 #define dma_cache_wback(_start,_size)           do { } while (0)
205 #define dma_cache_wback_inv(_start,_size)       do { } while (0)
206
207 /* H8/300 internal I/O functions */
208 static __inline__ unsigned char ctrl_inb(unsigned long addr)
209 {
210         return *(volatile unsigned char*)addr;
211 }
212
213 static __inline__ unsigned short ctrl_inw(unsigned long addr)
214 {
215         return *(volatile unsigned short*)addr;
216 }
217
218 static __inline__ unsigned int ctrl_inl(unsigned long addr)
219 {
220         return *(volatile unsigned long*)addr;
221 }
222
223 static __inline__ void ctrl_outb(unsigned char b, unsigned long addr)
224 {
225         *(volatile unsigned char*)addr = b;
226 }
227
228 static __inline__ void ctrl_outw(unsigned short b, unsigned long addr)
229 {
230         *(volatile unsigned short*)addr = b;
231 }
232
233 static __inline__ void ctrl_outl(unsigned int b, unsigned long addr)
234 {
235         *(volatile unsigned long*)addr = b;
236 }
237
238 /* Pages to physical address... */
239 #define page_to_phys(page)      ((page - mem_map) << PAGE_SHIFT)
240 #define page_to_bus(page)       ((page - mem_map) << PAGE_SHIFT)
241
242 /*
243  * Macros used for converting between virtual and physical mappings.
244  */
245 #define mm_ptov(vaddr)          ((void *) (vaddr))
246 #define mm_vtop(vaddr)          ((unsigned long) (vaddr))
247 #define phys_to_virt(vaddr)     ((void *) (vaddr))
248 #define virt_to_phys(vaddr)     ((unsigned long) (vaddr))
249
250 #define virt_to_bus virt_to_phys
251 #define bus_to_virt phys_to_virt
252
253 #endif /* __KERNEL__ */
254
255 #endif /* _H8300_IO_H */