Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | #ifndef _BFIN_IO_H |
| 2 | #define _BFIN_IO_H |
| 3 | |
| 4 | #ifdef __KERNEL__ |
| 5 | |
| 6 | #ifndef __ASSEMBLY__ |
| 7 | #include <linux/types.h> |
| 8 | #endif |
| 9 | #include <linux/compiler.h> |
| 10 | |
| 11 | /* |
| 12 | * These are for ISA/PCI shared memory _only_ and should never be used |
| 13 | * on any other type of memory, including Zorro memory. They are meant to |
| 14 | * access the bus in the bus byte order which is little-endian!. |
| 15 | * |
| 16 | * readX/writeX() are used to access memory mapped devices. On some |
| 17 | * architectures the memory mapped IO stuff needs to be accessed |
| 18 | * differently. On the bfin architecture, we just read/write the |
| 19 | * memory location directly. |
| 20 | */ |
| 21 | #ifndef __ASSEMBLY__ |
| 22 | |
Mike Frysinger | 216e39d | 2007-06-21 11:34:16 +0800 | [diff] [blame] | 23 | static inline unsigned char readb(const volatile void __iomem *addr) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 24 | { |
| 25 | unsigned int val; |
| 26 | int tmp; |
| 27 | |
| 28 | __asm__ __volatile__ ("cli %1;\n\t" |
| 29 | "NOP; NOP; SSYNC;\n\t" |
| 30 | "%0 = b [%2] (z);\n\t" |
| 31 | "sti %1;\n\t" |
| 32 | : "=d"(val), "=d"(tmp): "a"(addr) |
| 33 | ); |
| 34 | |
| 35 | return (unsigned char) val; |
| 36 | } |
| 37 | |
Mike Frysinger | 216e39d | 2007-06-21 11:34:16 +0800 | [diff] [blame] | 38 | static inline unsigned short readw(const volatile void __iomem *addr) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 39 | { |
| 40 | unsigned int val; |
| 41 | int tmp; |
| 42 | |
| 43 | __asm__ __volatile__ ("cli %1;\n\t" |
| 44 | "NOP; NOP; SSYNC;\n\t" |
| 45 | "%0 = w [%2] (z);\n\t" |
| 46 | "sti %1;\n\t" |
| 47 | : "=d"(val), "=d"(tmp): "a"(addr) |
| 48 | ); |
| 49 | |
| 50 | return (unsigned short) val; |
| 51 | } |
| 52 | |
Mike Frysinger | 216e39d | 2007-06-21 11:34:16 +0800 | [diff] [blame] | 53 | static inline unsigned int readl(const volatile void __iomem *addr) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 54 | { |
| 55 | unsigned int val; |
| 56 | int tmp; |
| 57 | |
| 58 | __asm__ __volatile__ ("cli %1;\n\t" |
| 59 | "NOP; NOP; SSYNC;\n\t" |
| 60 | "%0 = [%2];\n\t" |
| 61 | "sti %1;\n\t" |
| 62 | : "=d"(val), "=d"(tmp): "a"(addr) |
| 63 | ); |
| 64 | return val; |
| 65 | } |
| 66 | |
| 67 | #endif /* __ASSEMBLY__ */ |
| 68 | |
| 69 | #define writeb(b,addr) (void)((*(volatile unsigned char *) (addr)) = (b)) |
| 70 | #define writew(b,addr) (void)((*(volatile unsigned short *) (addr)) = (b)) |
| 71 | #define writel(b,addr) (void)((*(volatile unsigned int *) (addr)) = (b)) |
| 72 | |
| 73 | #define __raw_readb readb |
| 74 | #define __raw_readw readw |
| 75 | #define __raw_readl readl |
| 76 | #define __raw_writeb writeb |
| 77 | #define __raw_writew writew |
| 78 | #define __raw_writel writel |
| 79 | #define memset_io(a,b,c) memset((void *)(a),(b),(c)) |
| 80 | #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c)) |
| 81 | #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c)) |
| 82 | |
Mike Frysinger | f75196c | 2009-04-01 12:25:58 +0000 | [diff] [blame] | 83 | /* Convert "I/O port addresses" to actual addresses. i.e. ugly casts. */ |
| 84 | #define __io(port) ((void *)(unsigned long)(port)) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 85 | |
Mike Frysinger | f75196c | 2009-04-01 12:25:58 +0000 | [diff] [blame] | 86 | #define inb(port) readb(__io(port)) |
| 87 | #define inw(port) readw(__io(port)) |
| 88 | #define inl(port) readl(__io(port)) |
| 89 | #define outb(x,port) writeb(x,__io(port)) |
| 90 | #define outw(x,port) writew(x,__io(port)) |
| 91 | #define outl(x,port) writel(x,__io(port)) |
| 92 | |
| 93 | #define inb_p(port) inb(__io(port)) |
| 94 | #define inw_p(port) inw(__io(port)) |
| 95 | #define inl_p(port) inl(__io(port)) |
| 96 | #define outb_p(x,port) outb(x,__io(port)) |
| 97 | #define outw_p(x,port) outw(x,__io(port)) |
| 98 | #define outl_p(x,port) outl(x,__io(port)) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 99 | |
Sonic Zhang | 55e247e | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 100 | #define ioread8_rep(a,d,c) readsb(a,d,c) |
| 101 | #define ioread16_rep(a,d,c) readsw(a,d,c) |
| 102 | #define ioread32_rep(a,d,c) readsl(a,d,c) |
| 103 | #define iowrite8_rep(a,s,c) writesb(a,s,c) |
| 104 | #define iowrite16_rep(a,s,c) writesw(a,s,c) |
| 105 | #define iowrite32_rep(a,s,c) writesl(a,s,c) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 106 | |
| 107 | #define ioread8(X) readb(X) |
| 108 | #define ioread16(X) readw(X) |
| 109 | #define ioread32(X) readl(X) |
| 110 | #define iowrite8(val,X) writeb(val,X) |
| 111 | #define iowrite16(val,X) writew(val,X) |
| 112 | #define iowrite32(val,X) writel(val,X) |
| 113 | |
Mike Frysinger | ecdbfc1 | 2008-11-18 17:48:21 +0800 | [diff] [blame] | 114 | #define mmiowb() wmb() |
| 115 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 116 | #define IO_SPACE_LIMIT 0xffffffff |
| 117 | |
| 118 | /* Values for nocacheflag and cmode */ |
| 119 | #define IOMAP_NOCACHE_SER 1 |
| 120 | |
| 121 | #ifndef __ASSEMBLY__ |
| 122 | |
Bryan Wu | b7b2d344 | 2007-10-09 15:09:49 +0800 | [diff] [blame] | 123 | extern void outsb(unsigned long port, const void *addr, unsigned long count); |
| 124 | extern void outsw(unsigned long port, const void *addr, unsigned long count); |
Michael Hennerich | 5906967 | 2008-05-17 16:38:52 +0800 | [diff] [blame] | 125 | extern void outsw_8(unsigned long port, const void *addr, unsigned long count); |
Bryan Wu | b7b2d344 | 2007-10-09 15:09:49 +0800 | [diff] [blame] | 126 | extern void outsl(unsigned long port, const void *addr, unsigned long count); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 127 | |
Bryan Wu | b7b2d344 | 2007-10-09 15:09:49 +0800 | [diff] [blame] | 128 | extern void insb(unsigned long port, void *addr, unsigned long count); |
| 129 | extern void insw(unsigned long port, void *addr, unsigned long count); |
Michael Hennerich | 5906967 | 2008-05-17 16:38:52 +0800 | [diff] [blame] | 130 | extern void insw_8(unsigned long port, void *addr, unsigned long count); |
Bryan Wu | b7b2d344 | 2007-10-09 15:09:49 +0800 | [diff] [blame] | 131 | extern void insl(unsigned long port, void *addr, unsigned long count); |
Michael Hennerich | 5c91fb9 | 2007-11-17 23:46:58 +0800 | [diff] [blame] | 132 | extern void insl_16(unsigned long port, void *addr, unsigned long count); |
Michael Hennerich | 23ee968 | 2007-05-21 18:09:17 +0800 | [diff] [blame] | 133 | |
Bryan Wu | b7b2d344 | 2007-10-09 15:09:49 +0800 | [diff] [blame] | 134 | extern void dma_outsb(unsigned long port, const void *addr, unsigned short count); |
| 135 | extern void dma_outsw(unsigned long port, const void *addr, unsigned short count); |
| 136 | extern void dma_outsl(unsigned long port, const void *addr, unsigned short count); |
Michael Hennerich | 23ee968 | 2007-05-21 18:09:17 +0800 | [diff] [blame] | 137 | |
Bryan Wu | b7b2d344 | 2007-10-09 15:09:49 +0800 | [diff] [blame] | 138 | extern void dma_insb(unsigned long port, void *addr, unsigned short count); |
| 139 | extern void dma_insw(unsigned long port, void *addr, unsigned short count); |
| 140 | extern void dma_insl(unsigned long port, void *addr, unsigned short count); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 141 | |
Bryan Wu | 121e598 | 2008-10-16 22:31:56 +0800 | [diff] [blame] | 142 | static inline void readsl(const void __iomem *addr, void *buf, int len) |
| 143 | { |
| 144 | insl((unsigned long)addr, buf, len); |
| 145 | } |
| 146 | |
| 147 | static inline void readsw(const void __iomem *addr, void *buf, int len) |
| 148 | { |
| 149 | insw((unsigned long)addr, buf, len); |
| 150 | } |
| 151 | |
| 152 | static inline void readsb(const void __iomem *addr, void *buf, int len) |
| 153 | { |
| 154 | insb((unsigned long)addr, buf, len); |
| 155 | } |
| 156 | |
| 157 | static inline void writesl(const void __iomem *addr, const void *buf, int len) |
| 158 | { |
| 159 | outsl((unsigned long)addr, buf, len); |
| 160 | } |
| 161 | |
| 162 | static inline void writesw(const void __iomem *addr, const void *buf, int len) |
| 163 | { |
| 164 | outsw((unsigned long)addr, buf, len); |
| 165 | } |
| 166 | |
| 167 | static inline void writesb(const void __iomem *addr, const void *buf, int len) |
| 168 | { |
| 169 | outsb((unsigned long)addr, buf, len); |
| 170 | } |
| 171 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 172 | /* |
| 173 | * Map some physical address range into the kernel address space. |
| 174 | */ |
| 175 | static inline void __iomem *__ioremap(unsigned long physaddr, unsigned long size, |
| 176 | int cacheflag) |
| 177 | { |
| 178 | return (void __iomem *)physaddr; |
| 179 | } |
| 180 | |
| 181 | /* |
| 182 | * Unmap a ioremap()ed region again |
| 183 | */ |
| 184 | static inline void iounmap(void *addr) |
| 185 | { |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * __iounmap unmaps nearly everything, so be careful |
| 190 | * it doesn't free currently pointer/page tables anymore but it |
| 191 | * wans't used anyway and might be added later. |
| 192 | */ |
| 193 | static inline void __iounmap(void *addr, unsigned long size) |
| 194 | { |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Set new cache mode for some kernel address space. |
| 199 | * The caller must push data for that range itself, if such data may already |
| 200 | * be in the cache. |
| 201 | */ |
| 202 | static inline void kernel_set_cachemode(void *addr, unsigned long size, |
| 203 | int cmode) |
| 204 | { |
| 205 | } |
| 206 | |
| 207 | static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size) |
| 208 | { |
| 209 | return __ioremap(physaddr, size, IOMAP_NOCACHE_SER); |
| 210 | } |
| 211 | static inline void __iomem *ioremap_nocache(unsigned long physaddr, |
| 212 | unsigned long size) |
| 213 | { |
| 214 | return __ioremap(physaddr, size, IOMAP_NOCACHE_SER); |
| 215 | } |
| 216 | |
| 217 | extern void blkfin_inv_cache_all(void); |
| 218 | |
| 219 | #endif |
| 220 | |
| 221 | #define ioport_map(port, nr) ((void __iomem*)(port)) |
| 222 | #define ioport_unmap(addr) |
| 223 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 224 | /* Pages to physical address... */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 225 | #define page_to_bus(page) ((page - mem_map) << PAGE_SHIFT) |
| 226 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 227 | #define phys_to_virt(vaddr) ((void *) (vaddr)) |
| 228 | #define virt_to_phys(vaddr) ((unsigned long) (vaddr)) |
| 229 | |
| 230 | #define virt_to_bus virt_to_phys |
| 231 | #define bus_to_virt phys_to_virt |
| 232 | |
| 233 | /* |
| 234 | * Convert a physical pointer to a virtual kernel pointer for /dev/mem |
| 235 | * access |
| 236 | */ |
| 237 | #define xlate_dev_mem_ptr(p) __va(p) |
| 238 | |
| 239 | /* |
| 240 | * Convert a virtual cached pointer to an uncached pointer |
| 241 | */ |
| 242 | #define xlate_dev_kmem_ptr(p) p |
| 243 | |
| 244 | #endif /* __KERNEL__ */ |
| 245 | |
| 246 | #endif /* _BFIN_IO_H */ |