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