File: /usr/src/linux/include/asm-cris/io.h
1 #ifndef _ASM_CRIS_IO_H
2 #define _ASM_CRIS_IO_H
3
4 #include <asm/page.h> /* for __va, __pa */
5 #include <asm/svinto.h>
6 #include <linux/config.h>
7
8 /* Console I/O for simulated etrax100. Use #ifdef so erroneous
9 use will be evident. */
10 #ifdef CONFIG_SVINTO_SIM
11 /* Let's use the ucsim interface since it lets us do write(2, ...) */
12 #define SIMCOUT(s,len) \
13 asm ("moveq 4,r1 \n\t" \
14 "moveq 2,r10 \n\t" \
15 "move.d %0,r11 \n\t" \
16 "move.d %1,r12 \n\t" \
17 "push irp \n\t" \
18 "move 0f,irp \n\t" \
19 "jump -6809 \n" \
20 "0: \n\t" \
21 "pop irp" \
22 : : "rm" (s), "rm" (len) : "r1","r10","r11","r12","memory")
23 #define TRACE_ON() __extension__ \
24 ({ int _Foofoo; __asm__ volatile ("bmod [%0],%0" : "=r" (_Foofoo) : "0" \
25 (255)); _Foofoo; })
26
27 #define TRACE_OFF() do { __asm__ volatile ("bmod [%0],%0" :: "r" (254)); } while (0)
28 #define SIM_END() do { __asm__ volatile ("bmod [%0],%0" :: "r" (28)); } while (0)
29 #define CRIS_CYCLES() __extension__ \
30 ({ unsigned long c; asm ("bmod [%1],%0" : "=r" (c) : "r" (27)); c;})
31 #else /* ! defined CONFIG_SVINTO_SIM */
32 /* FIXME: Is there a reliable cycle counter available in some chip? Use
33 that then. */
34 #define CRIS_CYCLES() 0
35 #endif /* ! defined CONFIG_SVINTO_SIM */
36
37 /* Etrax shadow registers - which live in arch/cris/kernel/shadows.c */
38
39 extern unsigned long port_g_data_shadow;
40 extern unsigned char port_pa_dir_shadow;
41 extern unsigned char port_pa_data_shadow;
42 extern unsigned char port_pb_i2c_shadow;
43 extern unsigned char port_pb_config_shadow;
44 extern unsigned char port_pb_dir_shadow;
45 extern unsigned char port_pb_data_shadow;
46 extern unsigned long r_timer_ctrl_shadow;
47
48 extern unsigned long port_cse1_shadow;
49 extern unsigned long port_csp0_shadow;
50 extern unsigned long port_csp4_shadow;
51
52 extern volatile unsigned long *port_cse1_addr;
53 extern volatile unsigned long *port_csp0_addr;
54 extern volatile unsigned long *port_csp4_addr;
55
56 /* macro for setting regs through a shadow -
57 * r = register name (like R_PORT_PA_DATA)
58 * s = shadow name (like port_pa_data_shadow)
59 * b = bit number
60 * v = value (0 or 1)
61 */
62
63 #define REG_SHADOW_SET(r,s,b,v) *r = s = (s & ~(1 << (b))) | ((v) << (b))
64
65 /* The LED's on various Etrax-based products are set differently. */
66
67 #if defined(CONFIG_ETRAX_NO_LEDS) || defined(CONFIG_SVINTO_SIM)
68 #undef CONFIG_ETRAX_PA_LEDS
69 #undef CONFIG_ETRAX_PB_LEDS
70 #undef CONFIG_ETRAX_CSP0_LEDS
71 #define LED_NETWORK_SET_G(x)
72 #define LED_NETWORK_SET_R(x)
73 #define LED_ACTIVE_SET_G(x)
74 #define LED_ACTIVE_SET_R(x)
75 #define LED_DISK_WRITE(x)
76 #define LED_DISK_READ(x)
77 #endif
78
79 #if !defined(CONFIG_ETRAX_CSP0_LEDS)
80 #define LED_BIT_SET(x)
81 #define LED_BIT_CLR(x)
82 #endif
83
84 #define LED_OFF 0x00
85 #define LED_GREEN 0x01
86 #define LED_RED 0x02
87 #define LED_ORANGE (LED_GREEN | LED_RED)
88
89 #if CONFIG_ETRAX_LED1G == CONFIG_ETRAX_LED1R
90 #define LED_NETWORK_SET(x) \
91 do { \
92 LED_NETWORK_SET_G((x) & LED_GREEN); \
93 } while (0)
94 #else
95 #define LED_NETWORK_SET(x) \
96 do { \
97 LED_NETWORK_SET_G((x) & LED_GREEN); \
98 LED_NETWORK_SET_R((x) & LED_RED); \
99 } while (0)
100 #endif
101 #if CONFIG_ETRAX_LED2G == CONFIG_ETRAX_LED2R
102 #define LED_ACTIVE_SET(x) \
103 do { \
104 LED_ACTIVE_SET_G((x) & LED_GREEN); \
105 } while (0)
106 #else
107 #define LED_ACTIVE_SET(x) \
108 do { \
109 LED_ACTIVE_SET_G((x) & LED_GREEN); \
110 LED_ACTIVE_SET_R((x) & LED_RED); \
111 } while (0)
112 #endif
113
114 #ifdef CONFIG_ETRAX_PA_LEDS
115 #define LED_NETWORK_SET_G(x) \
116 REG_SHADOW_SET(R_PORT_PA_DATA, port_pa_data_shadow, CONFIG_ETRAX_LED1G, !(x))
117 #define LED_NETWORK_SET_R(x) \
118 REG_SHADOW_SET(R_PORT_PA_DATA, port_pa_data_shadow, CONFIG_ETRAX_LED1R, !(x))
119 #define LED_ACTIVE_SET_G(x) \
120 REG_SHADOW_SET(R_PORT_PA_DATA, port_pa_data_shadow, CONFIG_ETRAX_LED2G, !(x))
121 #define LED_ACTIVE_SET_R(x) \
122 REG_SHADOW_SET(R_PORT_PA_DATA, port_pa_data_shadow, CONFIG_ETRAX_LED2R, !(x))
123 #define LED_DISK_WRITE(x) \
124 do{\
125 REG_SHADOW_SET(R_PORT_PA_DATA, port_pa_data_shadow, CONFIG_ETRAX_LED3G, !(x));\
126 REG_SHADOW_SET(R_PORT_PA_DATA, port_pa_data_shadow, CONFIG_ETRAX_LED3R, !(x));\
127 }while(0)
128 #define LED_DISK_READ(x) \
129 REG_SHADOW_SET(R_PORT_PA_DATA, port_pa_data_shadow, CONFIG_ETRAX_LED3G, !(x))
130 #endif
131
132 #ifdef CONFIG_ETRAX_PB_LEDS
133 #define LED_NETWORK_SET_G(x) \
134 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, CONFIG_ETRAX_LED1G, !(x))
135 #define LED_NETWORK_SET_R(x) \
136 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, CONFIG_ETRAX_LED1R, !(x))
137 #define LED_ACTIVE_SET_G(x) \
138 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, CONFIG_ETRAX_LED2G, !(x))
139 #define LED_ACTIVE_SET_R(x) \
140 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, CONFIG_ETRAX_LED2R, !(x))
141 #define LED_DISK_WRITE(x) \
142 do{\
143 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, CONFIG_ETRAX_LED3G, !(x));\
144 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, CONFIG_ETRAX_LED3R, !(x));\
145 }while(0)
146 #define LED_DISK_READ(x) \
147 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, CONFIG_ETRAX_LED3G, !(x))
148 #endif
149
150 #ifdef CONFIG_ETRAX_CSP0_LEDS
151 #define CONFIGURABLE_LEDS\
152 ((1 << CONFIG_ETRAX_LED1G ) | (1 << CONFIG_ETRAX_LED1R ) |\
153 (1 << CONFIG_ETRAX_LED2G ) | (1 << CONFIG_ETRAX_LED2R ) |\
154 (1 << CONFIG_ETRAX_LED3G ) | (1 << CONFIG_ETRAX_LED3R ) |\
155 (1 << CONFIG_ETRAX_LED4G ) | (1 << CONFIG_ETRAX_LED4R ) |\
156 (1 << CONFIG_ETRAX_LED5G ) | (1 << CONFIG_ETRAX_LED5R ) |\
157 (1 << CONFIG_ETRAX_LED6G ) | (1 << CONFIG_ETRAX_LED6R ) |\
158 (1 << CONFIG_ETRAX_LED7G ) | (1 << CONFIG_ETRAX_LED7R ) |\
159 (1 << CONFIG_ETRAX_LED8Y ) | (1 << CONFIG_ETRAX_LED9Y ) |\
160 (1 << CONFIG_ETRAX_LED10Y ) |(1 << CONFIG_ETRAX_LED11Y )|\
161 (1 << CONFIG_ETRAX_LED12R ))
162
163 #define LED_NETWORK_SET_G(x) \
164 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, CONFIG_ETRAX_LED1G, !(x))
165 #define LED_NETWORK_SET_R(x) \
166 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, CONFIG_ETRAX_LED1R, !(x))
167 #define LED_ACTIVE_SET_G(x) \
168 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, CONFIG_ETRAX_LED2G, !(x))
169 #define LED_ACTIVE_SET_R(x) \
170 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, CONFIG_ETRAX_LED2R, !(x))
171 #define LED_DISK_WRITE(x) \
172 do{\
173 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, CONFIG_ETRAX_LED3G, !(x));\
174 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, CONFIG_ETRAX_LED3R, !(x));\
175 }while(0)
176 #define LED_DISK_READ(x) \
177 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, CONFIG_ETRAX_LED3G, !(x))
178 #define LED_BIT_SET(x)\
179 do{\
180 if((( 1 << x) & CONFIGURABLE_LEDS) != 0)\
181 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, x, 1);\
182 }while(0)
183 #define LED_BIT_CLR(x)\
184 do{\
185 if((( 1 << x) & CONFIGURABLE_LEDS) != 0)\
186 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, x, 0);\
187 }while(0)
188 #endif
189
190 #
191 #ifdef CONFIG_ETRAX_SOFT_SHUTDOWN
192 #define SOFT_SHUTDOWN() \
193 REG_SHADOW_SET(port_csp0_addr, port_csp0_shadow, CONFIG_ETRAX_SHUTDOWN_BIT, 1)
194 #else
195 #define SOFT_SHUTDOWN()
196 #endif
197
198 /*
199 * Change virtual addresses to physical addresses and vv.
200 */
201
202 static inline unsigned long virt_to_phys(volatile void * address)
203 {
204 return __pa(address);
205 }
206
207 static inline void * phys_to_virt(unsigned long address)
208 {
209 return __va(address);
210 }
211
212 extern void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
213
214 extern inline void * ioremap (unsigned long offset, unsigned long size)
215 {
216 return __ioremap(offset, size, 0);
217 }
218
219 /*
220 * IO bus memory addresses are also 1:1 with the physical address
221 */
222 #define virt_to_bus virt_to_phys
223 #define bus_to_virt phys_to_virt
224
225 /*
226 * readX/writeX() are used to access memory mapped devices. On some
227 * architectures the memory mapped IO stuff needs to be accessed
228 * differently. On the CRIS architecture, we just read/write the
229 * memory location directly.
230 */
231 #define readb(addr) (*(volatile unsigned char *) (addr))
232 #define readw(addr) (*(volatile unsigned short *) (addr))
233 #define readl(addr) (*(volatile unsigned int *) (addr))
234
235 #define writeb(b,addr) ((*(volatile unsigned char *) (addr)) = (b))
236 #define writew(b,addr) ((*(volatile unsigned short *) (addr)) = (b))
237 #define writel(b,addr) ((*(volatile unsigned int *) (addr)) = (b))
238
239 #define memset_io(a,b,c) memset((void *)(a),(b),(c))
240 #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
241 #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
242
243 /*
244 * Again, CRIS does not require mem IO specific function.
245 */
246
247 #define eth_io_copy_and_sum(a,b,c,d) eth_copy_and_sum((a),(void *)(b),(c),(d))
248
249 /* The following is junk needed for the arch-independant code but which
250 * we never use in the CRIS port
251 */
252
253 #define IO_SPACE_LIMIT 0xffff
254 #define inb(x) (0)
255 #define outb(x,y)
256 #define outw(x,y)
257 #define outl(x,y)
258 #define insb(x,y,z)
259 #define insw(x,y,z)
260 #define insl(x,y,z)
261 #define outsb(x,y,z)
262 #define outsw(x,y,z)
263 #define outsl(x,y,z)
264
265 #endif
266