Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - io.h IO routines |
| 3 | * |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 4 | * Copyright 2004-2009 Analog Devices Inc. |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 5 | * |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 6 | * Licensed under the GPL-2 or later. |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _BLACKFIN_IO_H |
| 10 | #define _BLACKFIN_IO_H |
| 11 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 12 | #ifdef __KERNEL__ |
| 13 | |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 14 | #include <asm/blackfin.h> |
| 15 | |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 16 | #define __iomem |
| 17 | |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 18 | static inline void sync(void) |
| 19 | { |
| 20 | SSYNC(); |
| 21 | } |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 22 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 23 | /* |
Haavard Skinnemoen | f985551 | 2007-12-13 12:56:33 +0100 | [diff] [blame] | 24 | * Given a physical address and a length, return a virtual address |
| 25 | * that can be used to access the memory range with the caching |
| 26 | * properties specified by "flags". |
| 27 | */ |
Haavard Skinnemoen | f985551 | 2007-12-13 12:56:33 +0100 | [diff] [blame] | 28 | #define MAP_NOCACHE (0) |
| 29 | #define MAP_WRCOMBINE (0) |
| 30 | #define MAP_WRBACK (0) |
| 31 | #define MAP_WRTHROUGH (0) |
| 32 | |
| 33 | static inline void * |
| 34 | map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags) |
| 35 | { |
| 36 | return (void *)paddr; |
| 37 | } |
| 38 | |
| 39 | /* |
| 40 | * Take down a mapping set up by map_physmem(). |
| 41 | */ |
| 42 | static inline void unmap_physmem(void *vaddr, unsigned long flags) |
| 43 | { |
| 44 | |
| 45 | } |
| 46 | |
Kumar Gala | 9364a67 | 2008-12-13 17:20:27 -0600 | [diff] [blame] | 47 | static inline phys_addr_t virt_to_phys(void * vaddr) |
| 48 | { |
| 49 | return (phys_addr_t)(vaddr); |
| 50 | } |
| 51 | |
Haavard Skinnemoen | f985551 | 2007-12-13 12:56:33 +0100 | [diff] [blame] | 52 | /* |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 53 | * These are for ISA/PCI shared memory _only_ and should never be used |
| 54 | * on any other type of memory, including Zorro memory. They are meant to |
| 55 | * access the bus in the bus byte order which is little-endian!. |
| 56 | * |
| 57 | * readX/writeX() are used to access memory mapped devices. On some |
| 58 | * architectures the memory mapped IO stuff needs to be accessed |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 59 | * differently. On the bfin architecture, we just read/write the |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 60 | * memory location directly. |
| 61 | */ |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 62 | #ifndef __ASSEMBLY__ |
| 63 | |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 64 | static inline unsigned char readb(const volatile void __iomem *addr) |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 65 | { |
| 66 | unsigned int val; |
| 67 | int tmp; |
| 68 | |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 69 | __asm__ __volatile__ ( |
| 70 | "cli %1;" |
| 71 | "NOP; NOP; SSYNC;" |
| 72 | "%0 = b [%2] (z);" |
| 73 | "sti %1;" |
| 74 | : "=d"(val), "=d"(tmp) |
| 75 | : "a"(addr) |
| 76 | ); |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 77 | |
| 78 | return (unsigned char) val; |
| 79 | } |
| 80 | |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 81 | static inline unsigned short readw(const volatile void __iomem *addr) |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 82 | { |
| 83 | unsigned int val; |
| 84 | int tmp; |
| 85 | |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 86 | __asm__ __volatile__ ( |
| 87 | "cli %1;" |
| 88 | "NOP; NOP; SSYNC;" |
| 89 | "%0 = w [%2] (z);" |
| 90 | "sti %1;" |
| 91 | : "=d"(val), "=d"(tmp) |
| 92 | : "a"(addr) |
| 93 | ); |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 94 | |
| 95 | return (unsigned short) val; |
| 96 | } |
| 97 | |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 98 | static inline unsigned int readl(const volatile void __iomem *addr) |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 99 | { |
| 100 | unsigned int val; |
| 101 | int tmp; |
| 102 | |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 103 | __asm__ __volatile__ ( |
| 104 | "cli %1;" |
| 105 | "NOP; NOP; SSYNC;" |
| 106 | "%0 = [%2];" |
| 107 | "sti %1;" |
| 108 | : "=d"(val), "=d"(tmp) |
| 109 | : "a"(addr) |
| 110 | ); |
| 111 | |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 112 | return val; |
| 113 | } |
| 114 | |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 115 | #endif /* __ASSEMBLY__ */ |
| 116 | |
| 117 | #define writeb(b, addr) (void)((*(volatile unsigned char *) (addr)) = (b)) |
| 118 | #define writew(b, addr) (void)((*(volatile unsigned short *) (addr)) = (b)) |
| 119 | #define writel(b, addr) (void)((*(volatile unsigned int *) (addr)) = (b)) |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 120 | |
| 121 | #define __raw_readb readb |
| 122 | #define __raw_readw readw |
| 123 | #define __raw_readl readl |
Mike Frysinger | e9e1aa9 | 2008-02-04 19:26:54 -0500 | [diff] [blame] | 124 | #define __raw_writeb writeb |
| 125 | #define __raw_writew writew |
| 126 | #define __raw_writel writel |
Mike Frysinger | 66c4cf4 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 127 | #define memset_io(a, b, c) memset((void *)(a), (b), (c)) |
| 128 | #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c)) |
| 129 | #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c)) |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 130 | |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 131 | /* Convert "I/O port addresses" to actual addresses. i.e. ugly casts. */ |
| 132 | #define __io(port) ((void *)(unsigned long)(port)) |
| 133 | |
| 134 | #define inb(port) readb(__io(port)) |
| 135 | #define inw(port) readw(__io(port)) |
| 136 | #define inl(port) readl(__io(port)) |
Mike Frysinger | d57463a | 2011-11-25 15:57:42 -0500 | [diff] [blame] | 137 | #define in_le32(port) inl(port) |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 138 | #define outb(x, port) writeb(x, __io(port)) |
| 139 | #define outw(x, port) writew(x, __io(port)) |
| 140 | #define outl(x, port) writel(x, __io(port)) |
Mike Frysinger | d57463a | 2011-11-25 15:57:42 -0500 | [diff] [blame] | 141 | #define out_le32(x, port) outl(x, port) |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 142 | |
| 143 | #define inb_p(port) inb(__io(port)) |
| 144 | #define inw_p(port) inw(__io(port)) |
| 145 | #define inl_p(port) inl(__io(port)) |
| 146 | #define outb_p(x, port) outb(x, __io(port)) |
| 147 | #define outw_p(x, port) outw(x, __io(port)) |
| 148 | #define outl_p(x, port) outl(x, __io(port)) |
| 149 | |
| 150 | #define ioread8_rep(a, d, c) readsb(a, d, c) |
| 151 | #define ioread16_rep(a, d, c) readsw(a, d, c) |
| 152 | #define ioread32_rep(a, d, c) readsl(a, d, c) |
| 153 | #define iowrite8_rep(a, s, c) writesb(a, s, c) |
| 154 | #define iowrite16_rep(a, s, c) writesw(a, s, c) |
| 155 | #define iowrite32_rep(a, s, c) writesl(a, s, c) |
| 156 | |
| 157 | #define ioread8(x) readb(x) |
| 158 | #define ioread16(x) readw(x) |
| 159 | #define ioread32(x) readl(x) |
| 160 | #define iowrite8(val, x) writeb(val, x) |
| 161 | #define iowrite16(val, x) writew(val, x) |
| 162 | #define iowrite32(val, x) writel(val, x) |
| 163 | |
| 164 | #define mmiowb() wmb() |
| 165 | |
| 166 | #ifndef __ASSEMBLY__ |
| 167 | |
| 168 | extern void outsb(unsigned long port, const void *addr, unsigned long count); |
| 169 | extern void outsw(unsigned long port, const void *addr, unsigned long count); |
| 170 | extern void outsw_8(unsigned long port, const void *addr, unsigned long count); |
| 171 | extern void outsl(unsigned long port, const void *addr, unsigned long count); |
| 172 | |
| 173 | extern void insb(unsigned long port, void *addr, unsigned long count); |
| 174 | extern void insw(unsigned long port, void *addr, unsigned long count); |
| 175 | extern void insw_8(unsigned long port, void *addr, unsigned long count); |
| 176 | extern void insl(unsigned long port, void *addr, unsigned long count); |
| 177 | extern void insl_16(unsigned long port, void *addr, unsigned long count); |
| 178 | |
| 179 | static inline void readsl(const void __iomem *addr, void *buf, int len) |
| 180 | { |
| 181 | insl((unsigned long)addr, buf, len); |
| 182 | } |
| 183 | |
| 184 | static inline void readsw(const void __iomem *addr, void *buf, int len) |
| 185 | { |
| 186 | insw((unsigned long)addr, buf, len); |
| 187 | } |
| 188 | |
| 189 | static inline void readsb(const void __iomem *addr, void *buf, int len) |
| 190 | { |
| 191 | insb((unsigned long)addr, buf, len); |
| 192 | } |
| 193 | |
| 194 | static inline void writesl(const void __iomem *addr, const void *buf, int len) |
| 195 | { |
| 196 | outsl((unsigned long)addr, buf, len); |
| 197 | } |
| 198 | |
| 199 | static inline void writesw(const void __iomem *addr, const void *buf, int len) |
| 200 | { |
| 201 | outsw((unsigned long)addr, buf, len); |
| 202 | } |
| 203 | |
| 204 | static inline void writesb(const void __iomem *addr, const void *buf, int len) |
| 205 | { |
| 206 | outsb((unsigned long)addr, buf, len); |
| 207 | } |
| 208 | |
Mike Frysinger | 99c4264 | 2009-11-30 13:34:07 -0500 | [diff] [blame] | 209 | #if defined(CONFIG_STAMP_CF) || defined(CONFIG_BFIN_IDE) |
| 210 | /* This hack for CF/IDE needs to be addressed at some point */ |
| 211 | extern void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words); |
| 212 | extern void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words); |
| 213 | extern unsigned char cf_inb(volatile unsigned char *addr); |
| 214 | extern void cf_outb(unsigned char val, volatile unsigned char *addr); |
| 215 | #undef inb |
| 216 | #undef outb |
| 217 | #undef insw |
| 218 | #undef outsw |
| 219 | #define inb(addr) cf_inb((void *)(addr)) |
| 220 | #define outb(x, addr) cf_outb((unsigned char)(x), (void *)(addr)) |
| 221 | #define insw(port, addr, cnt) cf_insw((void *)(addr), (void *)(port), cnt) |
| 222 | #define outsw(port, addr, cnt) cf_outsw((void *)(port), (void *)(addr), cnt) |
| 223 | #endif |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 224 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 225 | #endif |
Mike Frysinger | e59bac5 | 2009-11-30 13:51:24 -0500 | [diff] [blame] | 226 | |
| 227 | #endif /* __KERNEL__ */ |
| 228 | |
Wolfgang Denk | 97caf67 | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 229 | #endif |