io.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * IO header file
  3. *
  4. * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
  5. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #ifndef __ASM_M68K_IO_H__
  10. #define __ASM_M68K_IO_H__
  11. #include <asm/byteorder.h>
  12. #ifndef _IO_BASE
  13. #define _IO_BASE 0
  14. #endif
  15. #define __raw_readb(addr) (*(volatile u8 *)(addr))
  16. #define __raw_readw(addr) (*(volatile u16 *)(addr))
  17. #define __raw_readl(addr) (*(volatile u32 *)(addr))
  18. #define __raw_writeb(b,addr) ((*(volatile u8 *) (addr)) = (b))
  19. #define __raw_writew(w,addr) ((*(volatile u16 *) (addr)) = (w))
  20. #define __raw_writel(l,addr) ((*(volatile u32 *) (addr)) = (l))
  21. #define readb(addr) in_8((volatile u8 *)(addr))
  22. #define writeb(b,addr) out_8((volatile u8 *)(addr), (b))
  23. #if !defined(__BIG_ENDIAN)
  24. #define readw(addr) (*(volatile u16 *) (addr))
  25. #define readl(addr) (*(volatile u32 *) (addr))
  26. #define writew(b,addr) ((*(volatile u16 *) (addr)) = (b))
  27. #define writel(b,addr) ((*(volatile u32 *) (addr)) = (b))
  28. #else
  29. #define readw(addr) in_be16((volatile u16 *)(addr))
  30. #define readl(addr) in_be32((volatile u32 *)(addr))
  31. #define writew(b,addr) out_be16((volatile u16 *)(addr),(b))
  32. #define writel(b,addr) out_be32((volatile u32 *)(addr),(b))
  33. #endif
  34. /*
  35. * The insw/outsw/insl/outsl macros don't do byte-swapping.
  36. * They are only used in practice for transferring buffers which
  37. * are arrays of bytes, and byte-swapping is not appropriate in
  38. * that case. - paulus
  39. */
  40. #define insb(port, buf, ns) _insb((u8 *)((port)+_IO_BASE), (buf), (ns))
  41. #define outsb(port, buf, ns) _outsb((u8 *)((port)+_IO_BASE), (buf), (ns))
  42. #define insw(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  43. #define outsw(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  44. #define insl(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  45. #define outsl(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  46. #define inb(port) in_8((u8 *)((port)+_IO_BASE))
  47. #define outb(val, port) out_8((u8 *)((port)+_IO_BASE), (val))
  48. #if !defined(__BIG_ENDIAN)
  49. #define inw(port) in_be16((u16 *)((port)+_IO_BASE))
  50. #define outw(val, port) out_be16((u16 *)((port)+_IO_BASE), (val))
  51. #define inl(port) in_be32((u32 *)((port)+_IO_BASE))
  52. #define outl(val, port) out_be32((u32 *)((port)+_IO_BASE), (val))
  53. #else
  54. #define inw(port) in_le16((u16 *)((port)+_IO_BASE))
  55. #define outw(val, port) out_le16((u16 *)((port)+_IO_BASE), (val))
  56. #define inl(port) in_le32((u32 *)((port)+_IO_BASE))
  57. #define outl(val, port) out_le32((u32 *)((port)+_IO_BASE), (val))
  58. #endif
  59. #define mb() __asm__ __volatile__ ("" : : : "memory")
  60. static inline void _insb(volatile u8 * port, void *buf, int ns)
  61. {
  62. u8 *data = (u8 *) buf;
  63. while (ns--)
  64. *data++ = *port;
  65. }
  66. static inline void _outsb(volatile u8 * port, const void *buf, int ns)
  67. {
  68. u8 *data = (u8 *) buf;
  69. while (ns--)
  70. *port = *data++;
  71. }
  72. static inline void _insw(volatile u16 * port, void *buf, int ns)
  73. {
  74. u16 *data = (u16 *) buf;
  75. while (ns--)
  76. *data++ = __sw16(*port);
  77. }
  78. static inline void _outsw(volatile u16 * port, const void *buf, int ns)
  79. {
  80. u16 *data = (u16 *) buf;
  81. while (ns--) {
  82. *port = __sw16(*data);
  83. data++;
  84. }
  85. }
  86. static inline void _insl(volatile u32 * port, void *buf, int nl)
  87. {
  88. u32 *data = (u32 *) buf;
  89. while (nl--)
  90. *data++ = __sw32(*port);
  91. }
  92. static inline void _outsl(volatile u32 * port, const void *buf, int nl)
  93. {
  94. u32 *data = (u32 *) buf;
  95. while (nl--) {
  96. *port = __sw32(*data);
  97. data++;
  98. }
  99. }
  100. static inline void _insw_ns(volatile u16 * port, void *buf, int ns)
  101. {
  102. u16 *data = (u16 *) buf;
  103. while (ns--)
  104. *data++ = *port;
  105. }
  106. static inline void _outsw_ns(volatile u16 * port, const void *buf, int ns)
  107. {
  108. u16 *data = (u16 *) buf;
  109. while (ns--) {
  110. *port = *data++;
  111. }
  112. }
  113. static inline void _insl_ns(volatile u32 * port, void *buf, int nl)
  114. {
  115. u32 *data = (u32 *) buf;
  116. while (nl--)
  117. *data++ = *port;
  118. }
  119. static inline void _outsl_ns(volatile u32 * port, const void *buf, int nl)
  120. {
  121. u32 *data = (u32 *) buf;
  122. while (nl--) {
  123. *port = *data;
  124. data++;
  125. }
  126. }
  127. /*
  128. * The *_ns versions below don't do byte-swapping.
  129. * Neither do the standard versions now, these are just here
  130. * for older code.
  131. */
  132. #define insw_ns(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  133. #define outsw_ns(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  134. #define insl_ns(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  135. #define outsl_ns(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  136. #define IO_SPACE_LIMIT ~0
  137. /*
  138. * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
  139. */
  140. static inline int in_8(volatile u8 * addr)
  141. {
  142. return (int)*addr;
  143. }
  144. static inline void out_8(volatile u8 * addr, int val)
  145. {
  146. *addr = (u8) val;
  147. }
  148. static inline int in_le16(volatile u16 * addr)
  149. {
  150. return __sw16(*addr);
  151. }
  152. static inline int in_be16(volatile u16 * addr)
  153. {
  154. return (*addr & 0xFFFF);
  155. }
  156. static inline void out_le16(volatile u16 * addr, int val)
  157. {
  158. *addr = __sw16(val);
  159. }
  160. static inline void out_be16(volatile u16 * addr, int val)
  161. {
  162. *addr = (u16) val;
  163. }
  164. static inline unsigned in_le32(volatile u32 * addr)
  165. {
  166. return __sw32(*addr);
  167. }
  168. static inline unsigned in_be32(volatile u32 * addr)
  169. {
  170. return (*addr);
  171. }
  172. static inline void out_le32(volatile unsigned *addr, int val)
  173. {
  174. *addr = __sw32(val);
  175. }
  176. static inline void out_be32(volatile unsigned *addr, int val)
  177. {
  178. *addr = val;
  179. }
  180. /* Clear and set bits in one shot. These macros can be used to clear and
  181. * set multiple bits in a register using a single call. These macros can
  182. * also be used to set a multiple-bit bit pattern using a mask, by
  183. * specifying the mask in the 'clear' parameter and the new bit pattern
  184. * in the 'set' parameter.
  185. */
  186. #define clrbits(type, addr, clear) \
  187. out_##type((addr), in_##type(addr) & ~(clear))
  188. #define setbits(type, addr, set) \
  189. out_##type((addr), in_##type(addr) | (set))
  190. #define clrsetbits(type, addr, clear, set) \
  191. out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
  192. #define clrbits_be32(addr, clear) clrbits(be32, addr, clear)
  193. #define setbits_be32(addr, set) setbits(be32, addr, set)
  194. #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
  195. #define clrbits_le32(addr, clear) clrbits(le32, addr, clear)
  196. #define setbits_le32(addr, set) setbits(le32, addr, set)
  197. #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
  198. #define clrbits_be16(addr, clear) clrbits(be16, addr, clear)
  199. #define setbits_be16(addr, set) setbits(be16, addr, set)
  200. #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set)
  201. #define clrbits_le16(addr, clear) clrbits(le16, addr, clear)
  202. #define setbits_le16(addr, set) setbits(le16, addr, set)
  203. #define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set)
  204. #define clrbits_8(addr, clear) clrbits(8, addr, clear)
  205. #define setbits_8(addr, set) setbits(8, addr, set)
  206. #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
  207. static inline void sync(void)
  208. {
  209. /* This sync function is for PowerPC or other architecture instruction
  210. * ColdFire does not have this instruction. Dummy function, added for
  211. * compatibility (CFI driver)
  212. */
  213. }
  214. /*
  215. * Given a physical address and a length, return a virtual address
  216. * that can be used to access the memory range with the caching
  217. * properties specified by "flags".
  218. */
  219. #define MAP_NOCACHE (0)
  220. #define MAP_WRCOMBINE (0)
  221. #define MAP_WRBACK (0)
  222. #define MAP_WRTHROUGH (0)
  223. static inline void *map_physmem(phys_addr_t paddr, unsigned long len,
  224. unsigned long flags)
  225. {
  226. return (void *)paddr;
  227. }
  228. /*
  229. * Take down a mapping set up by map_physmem().
  230. */
  231. static inline void unmap_physmem(void *vaddr, unsigned long flags)
  232. {
  233. }
  234. static inline phys_addr_t virt_to_phys(void * vaddr)
  235. {
  236. return (phys_addr_t)(vaddr);
  237. }
  238. #endif /* __ASM_M68K_IO_H__ */