io.h 7.0 KB

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