TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 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 | */ |
Haiying Wang | 3a197b2 | 2007-02-21 16:52:31 +0100 | [diff] [blame] | 25 | |
TsiChungLiew | 8cd5cd6 | 2007-07-05 22:42:23 -0500 | [diff] [blame] | 26 | #ifndef __ASM_M68K_IO_H__ |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 27 | #define __ASM_M68K_IO_H__ |
| 28 | |
| 29 | #include <asm/byteorder.h> |
| 30 | |
TsiChungLiew | 397b7b8 | 2008-01-14 17:35:44 -0600 | [diff] [blame] | 31 | #define __raw_readb(addr) (*(volatile u8 *)(addr)) |
| 32 | #define __raw_readw(addr) (*(volatile u16 *)(addr)) |
| 33 | #define __raw_readl(addr) (*(volatile u32 *)(addr)) |
Haavard Skinnemoen | 812711c | 2007-12-13 12:56:31 +0100 | [diff] [blame] | 34 | |
TsiChungLiew | 397b7b8 | 2008-01-14 17:35:44 -0600 | [diff] [blame] | 35 | #define __raw_writeb(b,addr) ((*(volatile u8 *) (addr)) = (b)) |
| 36 | #define __raw_writew(w,addr) ((*(volatile u16 *) (addr)) = (w)) |
| 37 | #define __raw_writel(l,addr) ((*(volatile u32 *) (addr)) = (l)) |
Haavard Skinnemoen | 812711c | 2007-12-13 12:56:31 +0100 | [diff] [blame] | 38 | |
TsiChungLiew | ab77bc5 | 2007-08-15 15:39:17 -0500 | [diff] [blame] | 39 | #define readb(addr) in_8((volatile u8 *)(addr)) |
| 40 | #define writeb(b,addr) out_8((volatile u8 *)(addr), (b)) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 41 | #if !defined(__BIG_ENDIAN) |
TsiChungLiew | ab77bc5 | 2007-08-15 15:39:17 -0500 | [diff] [blame] | 42 | #define readw(addr) (*(volatile u16 *) (addr)) |
| 43 | #define readl(addr) (*(volatile u32 *) (addr)) |
| 44 | #define writew(b,addr) ((*(volatile u16 *) (addr)) = (b)) |
| 45 | #define writel(b,addr) ((*(volatile u32 *) (addr)) = (b)) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 46 | #else |
TsiChungLiew | ab77bc5 | 2007-08-15 15:39:17 -0500 | [diff] [blame] | 47 | #define readw(addr) in_le16((volatile u16 *)(addr)) |
| 48 | #define readl(addr) in_le32((volatile u32 *)(addr)) |
| 49 | #define writew(b,addr) out_le16((volatile u16 *)(addr),(b)) |
| 50 | #define writel(b,addr) out_le32((volatile u32 *)(addr),(b)) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 51 | #endif |
| 52 | |
| 53 | /* |
| 54 | * The insw/outsw/insl/outsl macros don't do byte-swapping. |
| 55 | * They are only used in practice for transferring buffers which |
| 56 | * are arrays of bytes, and byte-swapping is not appropriate in |
| 57 | * that case. - paulus |
| 58 | */ |
TsiChungLiew | ab77bc5 | 2007-08-15 15:39:17 -0500 | [diff] [blame] | 59 | #define insb(port, buf, ns) _insb((u8 *)((port)+_IO_BASE), (buf), (ns)) |
| 60 | #define outsb(port, buf, ns) _outsb((u8 *)((port)+_IO_BASE), (buf), (ns)) |
| 61 | #define insw(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns)) |
| 62 | #define outsw(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns)) |
| 63 | #define insl(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl)) |
| 64 | #define outsl(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl)) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 65 | |
TsiChungLiew | ab77bc5 | 2007-08-15 15:39:17 -0500 | [diff] [blame] | 66 | #define inb(port) in_8((u8 *)((port)+_IO_BASE)) |
| 67 | #define outb(val, port) out_8((u8 *)((port)+_IO_BASE), (val)) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 68 | #if !defined(__BIG_ENDIAN) |
TsiChungLiew | ab77bc5 | 2007-08-15 15:39:17 -0500 | [diff] [blame] | 69 | #define inw(port) in_be16((u16 *)((port)+_IO_BASE)) |
| 70 | #define outw(val, port) out_be16((u16 *)((port)+_IO_BASE), (val)) |
| 71 | #define inl(port) in_be32((u32 *)((port)+_IO_BASE)) |
| 72 | #define outl(val, port) out_be32((u32 *)((port)+_IO_BASE), (val)) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 73 | #else |
TsiChungLiew | ab77bc5 | 2007-08-15 15:39:17 -0500 | [diff] [blame] | 74 | #define inw(port) in_le16((u16 *)((port)+_IO_BASE)) |
| 75 | #define outw(val, port) out_le16((u16 *)((port)+_IO_BASE), (val)) |
| 76 | #define inl(port) in_le32((u32 *)((port)+_IO_BASE)) |
| 77 | #define outl(val, port) out_le32((u32 *)((port)+_IO_BASE), (val)) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 78 | #endif |
| 79 | |
| 80 | extern inline void _insb(volatile u8 * port, void *buf, int ns) |
Haiying Wang | 3a197b2 | 2007-02-21 16:52:31 +0100 | [diff] [blame] | 81 | { |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 82 | u8 *data = (u8 *) buf; |
| 83 | while (ns--) |
| 84 | *data++ = *port; |
Haiying Wang | 3a197b2 | 2007-02-21 16:52:31 +0100 | [diff] [blame] | 85 | } |
| 86 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 87 | extern inline void _outsb(volatile u8 * port, const void *buf, int ns) |
| 88 | { |
| 89 | u8 *data = (u8 *) buf; |
| 90 | while (ns--) |
| 91 | *port = *data++; |
| 92 | } |
| 93 | |
| 94 | extern inline void _insw(volatile u16 * port, void *buf, int ns) |
| 95 | { |
| 96 | u16 *data = (u16 *) buf; |
| 97 | while (ns--) |
| 98 | *data++ = __sw16(*port); |
| 99 | } |
| 100 | |
| 101 | extern inline void _outsw(volatile u16 * port, const void *buf, int ns) |
| 102 | { |
| 103 | u16 *data = (u16 *) buf; |
| 104 | while (ns--) { |
| 105 | *port = __sw16(*data); |
| 106 | data++; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | extern inline void _insl(volatile u32 * port, void *buf, int nl) |
| 111 | { |
| 112 | u32 *data = (u32 *) buf; |
| 113 | while (nl--) |
| 114 | *data++ = __sw32(*port); |
| 115 | } |
| 116 | |
| 117 | extern inline void _outsl(volatile u32 * port, const void *buf, int nl) |
| 118 | { |
| 119 | u32 *data = (u32 *) buf; |
| 120 | while (nl--) { |
| 121 | *port = __sw32(*data); |
| 122 | data++; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | extern inline void _insw_ns(volatile u16 * port, void *buf, int ns) |
| 127 | { |
| 128 | u16 *data = (u16 *) buf; |
| 129 | while (ns--) |
| 130 | *data++ = *port; |
| 131 | } |
| 132 | |
| 133 | extern inline void _outsw_ns(volatile u16 * port, const void *buf, int ns) |
| 134 | { |
| 135 | u16 *data = (u16 *) buf; |
| 136 | while (ns--) { |
| 137 | *port = *data++; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | extern inline void _insl_ns(volatile u32 * port, void *buf, int nl) |
| 142 | { |
| 143 | u32 *data = (u32 *) buf; |
| 144 | while (nl--) |
| 145 | *data++ = *port; |
| 146 | } |
| 147 | |
| 148 | extern inline void _outsl_ns(volatile u32 * port, const void *buf, int nl) |
| 149 | { |
| 150 | u32 *data = (u32 *) buf; |
| 151 | while (nl--) { |
| 152 | *port = *data; |
| 153 | data++; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * The *_ns versions below don't do byte-swapping. |
| 159 | * Neither do the standard versions now, these are just here |
| 160 | * for older code. |
| 161 | */ |
TsiChungLiew | ab77bc5 | 2007-08-15 15:39:17 -0500 | [diff] [blame] | 162 | #define insw_ns(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns)) |
| 163 | #define outsw_ns(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns)) |
| 164 | #define insl_ns(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl)) |
| 165 | #define outsl_ns(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl)) |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 166 | |
| 167 | #define IO_SPACE_LIMIT ~0 |
| 168 | |
| 169 | /* |
| 170 | * 8, 16 and 32 bit, big and little endian I/O operations, with barrier. |
| 171 | */ |
| 172 | extern inline int in_8(volatile u8 * addr) |
| 173 | { |
| 174 | return (int)*addr; |
| 175 | } |
| 176 | |
| 177 | extern inline void out_8(volatile u8 * addr, int val) |
| 178 | { |
| 179 | *addr = (u8) val; |
| 180 | } |
| 181 | |
| 182 | extern inline int in_le16(volatile u16 * addr) |
| 183 | { |
| 184 | return __sw16(*addr); |
| 185 | } |
| 186 | |
| 187 | extern inline int in_be16(volatile u16 * addr) |
| 188 | { |
| 189 | return (*addr & 0xFFFF); |
| 190 | } |
| 191 | |
| 192 | extern inline void out_le16(volatile u16 * addr, int val) |
| 193 | { |
| 194 | *addr = __sw16(val); |
| 195 | } |
| 196 | |
| 197 | extern inline void out_be16(volatile u16 * addr, int val) |
| 198 | { |
| 199 | *addr = (u16) val; |
| 200 | } |
| 201 | |
| 202 | extern inline unsigned in_le32(volatile u32 * addr) |
| 203 | { |
| 204 | return __sw32(*addr); |
| 205 | } |
| 206 | |
| 207 | extern inline unsigned in_be32(volatile u32 * addr) |
| 208 | { |
| 209 | return (*addr); |
| 210 | } |
| 211 | |
| 212 | extern inline void out_le32(volatile unsigned *addr, int val) |
| 213 | { |
| 214 | *addr = __sw32(val); |
| 215 | } |
| 216 | |
| 217 | extern inline void out_be32(volatile unsigned *addr, int val) |
| 218 | { |
| 219 | *addr = val; |
| 220 | } |
| 221 | |
TsiChungLiew | 6fde84a | 2007-08-05 03:43:30 -0500 | [diff] [blame] | 222 | static inline void sync(void) |
| 223 | { |
| 224 | /* This sync function is for PowerPC or other architecture instruction |
| 225 | * ColdFire does not have this instruction. Dummy function, added for |
| 226 | * compatibility (CFI driver) |
| 227 | */ |
| 228 | } |
Haavard Skinnemoen | 4d7d693 | 2007-12-13 12:56:33 +0100 | [diff] [blame] | 229 | |
| 230 | /* |
| 231 | * Given a physical address and a length, return a virtual address |
| 232 | * that can be used to access the memory range with the caching |
| 233 | * properties specified by "flags". |
| 234 | */ |
Haavard Skinnemoen | 4d7d693 | 2007-12-13 12:56:33 +0100 | [diff] [blame] | 235 | #define MAP_NOCACHE (0) |
| 236 | #define MAP_WRCOMBINE (0) |
| 237 | #define MAP_WRBACK (0) |
| 238 | #define MAP_WRTHROUGH (0) |
| 239 | |
TsiChungLiew | 397b7b8 | 2008-01-14 17:35:44 -0600 | [diff] [blame] | 240 | static inline void *map_physmem(phys_addr_t paddr, unsigned long len, |
| 241 | unsigned long flags) |
Haavard Skinnemoen | 4d7d693 | 2007-12-13 12:56:33 +0100 | [diff] [blame] | 242 | { |
| 243 | return (void *)paddr; |
| 244 | } |
| 245 | |
| 246 | /* |
| 247 | * Take down a mapping set up by map_physmem(). |
| 248 | */ |
| 249 | static inline void unmap_physmem(void *vaddr, unsigned long flags) |
| 250 | { |
| 251 | |
| 252 | } |
| 253 | |
Kumar Gala | 65e43a1 | 2008-12-13 17:20:27 -0600 | [diff] [blame] | 254 | static inline phys_addr_t virt_to_phys(void * vaddr) |
| 255 | { |
| 256 | return (phys_addr_t)(vaddr); |
| 257 | } |
| 258 | |
TsiChung Liew | 8e585f0 | 2007-06-18 13:50:13 -0500 | [diff] [blame] | 259 | #endif /* __ASM_M68K_IO_H__ */ |