initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / asm-arm / arch-shark / io.h
blob61abd02e561056c8d3547ce86b52e70c9b1bd1a4
1 /*
2 * linux/include/asm-arm/arch-shark/io.h
4 * by Alexander Schulz
6 * derived from:
7 * linux/include/asm-arm/arch-ebsa110/io.h
8 * Copyright (C) 1997,1998 Russell King
9 */
11 #ifndef __ASM_ARM_ARCH_IO_H
12 #define __ASM_ARM_ARCH_IO_H
14 #define IO_SPACE_LIMIT 0xffffffff
17 * We use two different types of addressing - PC style addresses, and ARM
18 * addresses. PC style accesses the PC hardware with the normal PC IO
19 * addresses, eg 0x3f8 for serial#1. ARM addresses are 0x80000000+
20 * and are translated to the start of IO.
22 #define __PORT_PCIO(x) (!((x) & 0x80000000))
25 * Dynamic IO functions - let the compiler
26 * optimize the expressions
28 #define DECLARE_DYN_OUT(fnsuffix,instr) \
29 static inline void __out##fnsuffix (unsigned int value, unsigned int port) \
30 { \
31 unsigned long temp; \
32 __asm__ __volatile__( \
33 "tst %2, #0x80000000\n\t" \
34 "mov %0, %4\n\t" \
35 "addeq %0, %0, %3\n\t" \
36 "str" instr " %1, [%0, %2] @ out" #fnsuffix \
37 : "=&r" (temp) \
38 : "r" (value), "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE) \
39 : "cc"); \
42 #define DECLARE_DYN_IN(sz,fnsuffix,instr) \
43 static inline unsigned sz __in##fnsuffix (unsigned int port) \
44 { \
45 unsigned long temp, value; \
46 __asm__ __volatile__( \
47 "tst %2, #0x80000000\n\t" \
48 "mov %0, %4\n\t" \
49 "addeq %0, %0, %3\n\t" \
50 "ldr" instr " %1, [%0, %2] @ in" #fnsuffix \
51 : "=&r" (temp), "=r" (value) \
52 : "r" (port), "Ir" (PCIO_BASE - IO_BASE), "Ir" (IO_BASE) \
53 : "cc"); \
54 return (unsigned sz)value; \
57 static inline unsigned int __ioaddr (unsigned int port) \
58 { \
59 if (__PORT_PCIO(port)) \
60 return (unsigned int)(PCIO_BASE + (port)); \
61 else \
62 return (unsigned int)(IO_BASE + (port)); \
65 #define DECLARE_IO(sz,fnsuffix,instr) \
66 DECLARE_DYN_OUT(fnsuffix,instr) \
67 DECLARE_DYN_IN(sz,fnsuffix,instr)
69 DECLARE_IO(char,b,"b")
70 DECLARE_IO(short,w,"h")
71 DECLARE_IO(long,l,"")
73 #undef DECLARE_IO
74 #undef DECLARE_DYN_OUT
75 #undef DECLARE_DYN_IN
78 * Constant address IO functions
80 * These have to be macros for the 'J' constraint to work -
81 * +/-4096 immediate operand.
83 #define __outbc(value,port) \
84 ({ \
85 if (__PORT_PCIO((port))) \
86 __asm__ __volatile__( \
87 "strb %0, [%1, %2] @ outbc" \
88 : : "r" (value), "r" (PCIO_BASE), "Jr" (port)); \
89 else \
90 __asm__ __volatile__( \
91 "strb %0, [%1, %2] @ outbc" \
92 : : "r" (value), "r" (IO_BASE), "r" (port)); \
95 #define __inbc(port) \
96 ({ \
97 unsigned char result; \
98 if (__PORT_PCIO((port))) \
99 __asm__ __volatile__( \
100 "ldrb %0, [%1, %2] @ inbc" \
101 : "=r" (result) : "r" (PCIO_BASE), "Jr" (port)); \
102 else \
103 __asm__ __volatile__( \
104 "ldrb %0, [%1, %2] @ inbc" \
105 : "=r" (result) : "r" (IO_BASE), "r" (port)); \
106 result; \
109 #define __outwc(value,port) \
110 ({ \
111 unsigned long v = value; \
112 if (__PORT_PCIO((port))) \
113 __asm__ __volatile__( \
114 "strh %0, [%1, %2] @ outwc" \
115 : : "r" (v|v<<16), "r" (PCIO_BASE), "Jr" (port)); \
116 else \
117 __asm__ __volatile__( \
118 "strh %0, [%1, %2] @ outwc" \
119 : : "r" (v|v<<16), "r" (IO_BASE), "r" (port)); \
122 #define __inwc(port) \
123 ({ \
124 unsigned short result; \
125 if (__PORT_PCIO((port))) \
126 __asm__ __volatile__( \
127 "ldrh %0, [%1, %2] @ inwc" \
128 : "=r" (result) : "r" (PCIO_BASE), "Jr" (port)); \
129 else \
130 __asm__ __volatile__( \
131 "ldrh %0, [%1, %2] @ inwc" \
132 : "=r" (result) : "r" (IO_BASE), "r" (port)); \
133 result & 0xffff; \
136 #define __outlc(value,port) \
137 ({ \
138 unsigned long v = value; \
139 if (__PORT_PCIO((port))) \
140 __asm__ __volatile__( \
141 "str %0, [%1, %2] @ outlc" \
142 : : "r" (v), "r" (PCIO_BASE), "Jr" (port)); \
143 else \
144 __asm__ __volatile__( \
145 "str %0, [%1, %2] @ outlc" \
146 : : "r" (v), "r" (IO_BASE), "r" (port)); \
149 #define __inlc(port) \
150 ({ \
151 unsigned long result; \
152 if (__PORT_PCIO((port))) \
153 __asm__ __volatile__( \
154 "ldr %0, [%1, %2] @ inlc" \
155 : "=r" (result) : "r" (PCIO_BASE), "Jr" (port)); \
156 else \
157 __asm__ __volatile__( \
158 "ldr %0, [%1, %2] @ inlc" \
159 : "=r" (result) : "r" (IO_BASE), "r" (port)); \
160 result; \
163 #define __ioaddrc(port) \
164 ({ \
165 unsigned long addr; \
166 if (__PORT_PCIO((port))) \
167 addr = PCIO_BASE + (port); \
168 else \
169 addr = IO_BASE + (port); \
170 addr; \
173 #define __mem_pci(addr) addr
175 #define inb(p) (__builtin_constant_p((p)) ? __inbc(p) : __inb(p))
176 #define inw(p) (__builtin_constant_p((p)) ? __inwc(p) : __inw(p))
177 #define inl(p) (__builtin_constant_p((p)) ? __inlc(p) : __inl(p))
178 #define outb(v,p) (__builtin_constant_p((p)) ? __outbc(v,p) : __outb(v,p))
179 #define outw(v,p) (__builtin_constant_p((p)) ? __outwc(v,p) : __outw(v,p))
180 #define outl(v,p) (__builtin_constant_p((p)) ? __outlc(v,p) : __outl(v,p))
183 * Translated address IO functions
185 * IO address has already been translated to a virtual address
187 #define outb_t(v,p) \
188 (*(volatile unsigned char *)(p) = (v))
190 #define inb_t(p) \
191 (*(volatile unsigned char *)(p))
193 #define outl_t(v,p) \
194 (*(volatile unsigned long *)(p) = (v))
196 #define inl_t(p) \
197 (*(volatile unsigned long *)(p))
199 #endif