]>
Commit | Line | Data |
---|---|---|
8e585f02 TL |
1 | /* |
2 | * IO header file | |
3 | * | |
4 | * Copyright (C) 2004-2007 Freescale Semiconductor, Inc. | |
5 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) | |
6 | * | |
7 | * See file CREDITS for list of people who contributed to this | |
8 | * project. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU General Public License as | |
12 | * published by the Free Software Foundation; either version 2 of | |
13 | * the License, or (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
23 | * MA 02111-1307 USA | |
24 | */ | |
3a197b2f | 25 | |
8cd5cd6d | 26 | #ifndef __ASM_M68K_IO_H__ |
8e585f02 TL |
27 | #define __ASM_M68K_IO_H__ |
28 | ||
29 | #include <asm/byteorder.h> | |
30 | ||
812711ce HS |
31 | /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates |
32 | * two accesses to memory, which may be undesirable for some devices. | |
33 | */ | |
34 | #define __raw_readb(addr) \ | |
35 | ({ u8 __v = (*(volatile u8 *) (addr)); __v; }) | |
36 | #define __raw_readw(addr) \ | |
37 | ({ u16 __v = (*(volatile u16 *) (addr)); __v; }) | |
38 | #define __raw_readl(addr) \ | |
39 | ({ u32 __v = (*(volatile u32 *) (addr)); __v; }) | |
40 | ||
41 | #define __raw_writeb(addr,b) (void)((*(volatile u8 *) (addr)) = (b)) | |
42 | #define __raw_writew(addr,w) (void)((*(volatile u16 *) (addr)) = (w)) | |
43 | #define __raw_writel(addr,l) (void)((*(volatile u32 *) (addr)) = (l)) | |
44 | ||
ab77bc54 TL |
45 | #define readb(addr) in_8((volatile u8 *)(addr)) |
46 | #define writeb(b,addr) out_8((volatile u8 *)(addr), (b)) | |
8e585f02 | 47 | #if !defined(__BIG_ENDIAN) |
ab77bc54 TL |
48 | #define readw(addr) (*(volatile u16 *) (addr)) |
49 | #define readl(addr) (*(volatile u32 *) (addr)) | |
50 | #define writew(b,addr) ((*(volatile u16 *) (addr)) = (b)) | |
51 | #define writel(b,addr) ((*(volatile u32 *) (addr)) = (b)) | |
8e585f02 | 52 | #else |
ab77bc54 TL |
53 | #define readw(addr) in_le16((volatile u16 *)(addr)) |
54 | #define readl(addr) in_le32((volatile u32 *)(addr)) | |
55 | #define writew(b,addr) out_le16((volatile u16 *)(addr),(b)) | |
56 | #define writel(b,addr) out_le32((volatile u32 *)(addr),(b)) | |
8e585f02 TL |
57 | #endif |
58 | ||
59 | /* | |
60 | * The insw/outsw/insl/outsl macros don't do byte-swapping. | |
61 | * They are only used in practice for transferring buffers which | |
62 | * are arrays of bytes, and byte-swapping is not appropriate in | |
63 | * that case. - paulus | |
64 | */ | |
ab77bc54 TL |
65 | #define insb(port, buf, ns) _insb((u8 *)((port)+_IO_BASE), (buf), (ns)) |
66 | #define outsb(port, buf, ns) _outsb((u8 *)((port)+_IO_BASE), (buf), (ns)) | |
67 | #define insw(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns)) | |
68 | #define outsw(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns)) | |
69 | #define insl(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl)) | |
70 | #define outsl(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl)) | |
71 | ||
72 | #define inb(port) in_8((u8 *)((port)+_IO_BASE)) | |
73 | #define outb(val, port) out_8((u8 *)((port)+_IO_BASE), (val)) | |
8e585f02 | 74 | #if !defined(__BIG_ENDIAN) |
ab77bc54 TL |
75 | #define inw(port) in_be16((u16 *)((port)+_IO_BASE)) |
76 | #define outw(val, port) out_be16((u16 *)((port)+_IO_BASE), (val)) | |
77 | #define inl(port) in_be32((u32 *)((port)+_IO_BASE)) | |
78 | #define outl(val, port) out_be32((u32 *)((port)+_IO_BASE), (val)) | |
8e585f02 | 79 | #else |
ab77bc54 TL |
80 | #define inw(port) in_le16((u16 *)((port)+_IO_BASE)) |
81 | #define outw(val, port) out_le16((u16 *)((port)+_IO_BASE), (val)) | |
82 | #define inl(port) in_le32((u32 *)((port)+_IO_BASE)) | |
83 | #define outl(val, port) out_le32((u32 *)((port)+_IO_BASE), (val)) | |
8e585f02 TL |
84 | #endif |
85 | ||
86 | extern inline void _insb(volatile u8 * port, void *buf, int ns) | |
87 | { | |
88 | u8 *data = (u8 *) buf; | |
89 | while (ns--) | |
90 | *data++ = *port; | |
91 | } | |
92 | ||
93 | extern inline void _outsb(volatile u8 * port, const void *buf, int ns) | |
94 | { | |
95 | u8 *data = (u8 *) buf; | |
96 | while (ns--) | |
97 | *port = *data++; | |
98 | } | |
99 | ||
100 | extern inline void _insw(volatile u16 * port, void *buf, int ns) | |
101 | { | |
102 | u16 *data = (u16 *) buf; | |
103 | while (ns--) | |
104 | *data++ = __sw16(*port); | |
105 | } | |
106 | ||
107 | extern inline void _outsw(volatile u16 * port, const void *buf, int ns) | |
108 | { | |
109 | u16 *data = (u16 *) buf; | |
110 | while (ns--) { | |
111 | *port = __sw16(*data); | |
112 | data++; | |
113 | } | |
114 | } | |
115 | ||
116 | extern inline void _insl(volatile u32 * port, void *buf, int nl) | |
117 | { | |
118 | u32 *data = (u32 *) buf; | |
119 | while (nl--) | |
120 | *data++ = __sw32(*port); | |
121 | } | |
122 | ||
123 | extern inline void _outsl(volatile u32 * port, const void *buf, int nl) | |
124 | { | |
125 | u32 *data = (u32 *) buf; | |
126 | while (nl--) { | |
127 | *port = __sw32(*data); | |
128 | data++; | |
129 | } | |
130 | } | |
131 | ||
132 | extern inline void _insw_ns(volatile u16 * port, void *buf, int ns) | |
133 | { | |
134 | u16 *data = (u16 *) buf; | |
135 | while (ns--) | |
136 | *data++ = *port; | |
137 | } | |
138 | ||
139 | extern inline void _outsw_ns(volatile u16 * port, const void *buf, int ns) | |
140 | { | |
141 | u16 *data = (u16 *) buf; | |
142 | while (ns--) { | |
143 | *port = *data++; | |
144 | } | |
145 | } | |
146 | ||
147 | extern inline void _insl_ns(volatile u32 * port, void *buf, int nl) | |
148 | { | |
149 | u32 *data = (u32 *) buf; | |
150 | while (nl--) | |
151 | *data++ = *port; | |
152 | } | |
153 | ||
154 | extern inline void _outsl_ns(volatile u32 * port, const void *buf, int nl) | |
155 | { | |
156 | u32 *data = (u32 *) buf; | |
157 | while (nl--) { | |
158 | *port = *data; | |
159 | data++; | |
160 | } | |
161 | } | |
162 | ||
163 | /* | |
164 | * The *_ns versions below don't do byte-swapping. | |
165 | * Neither do the standard versions now, these are just here | |
166 | * for older code. | |
167 | */ | |
ab77bc54 TL |
168 | #define insw_ns(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns)) |
169 | #define outsw_ns(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns)) | |
170 | #define insl_ns(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl)) | |
171 | #define outsl_ns(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl)) | |
8e585f02 TL |
172 | |
173 | #define IO_SPACE_LIMIT ~0 | |
174 | ||
175 | /* | |
176 | * 8, 16 and 32 bit, big and little endian I/O operations, with barrier. | |
177 | */ | |
178 | extern inline int in_8(volatile u8 * addr) | |
179 | { | |
180 | return (int)*addr; | |
181 | } | |
182 | ||
183 | extern inline void out_8(volatile u8 * addr, int val) | |
184 | { | |
185 | *addr = (u8) val; | |
186 | } | |
187 | ||
188 | extern inline int in_le16(volatile u16 * addr) | |
189 | { | |
190 | return __sw16(*addr); | |
191 | } | |
192 | ||
193 | extern inline int in_be16(volatile u16 * addr) | |
194 | { | |
195 | return (*addr & 0xFFFF); | |
196 | } | |
197 | ||
198 | extern inline void out_le16(volatile u16 * addr, int val) | |
199 | { | |
200 | *addr = __sw16(val); | |
201 | } | |
202 | ||
203 | extern inline void out_be16(volatile u16 * addr, int val) | |
204 | { | |
205 | *addr = (u16) val; | |
206 | } | |
207 | ||
208 | extern inline unsigned in_le32(volatile u32 * addr) | |
209 | { | |
210 | return __sw32(*addr); | |
211 | } | |
212 | ||
213 | extern inline unsigned in_be32(volatile u32 * addr) | |
214 | { | |
215 | return (*addr); | |
216 | } | |
217 | ||
218 | extern inline void out_le32(volatile unsigned *addr, int val) | |
219 | { | |
220 | *addr = __sw32(val); | |
221 | } | |
222 | ||
223 | extern inline void out_be32(volatile unsigned *addr, int val) | |
3a197b2f | 224 | { |
8e585f02 | 225 | *addr = val; |
3a197b2f HW |
226 | } |
227 | ||
6fde84a4 TL |
228 | static inline void sync(void) |
229 | { | |
230 | /* This sync function is for PowerPC or other architecture instruction | |
231 | * ColdFire does not have this instruction. Dummy function, added for | |
232 | * compatibility (CFI driver) | |
233 | */ | |
234 | } | |
8e585f02 | 235 | #endif /* __ASM_M68K_IO_H__ */ |