io.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * IO header file
  3. *
  4. * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
  5. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #ifndef __ASM_M68K_IO_H__
  26. #define __ASM_M68K_IO_H__
  27. #include <asm/byteorder.h>
  28. /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
  29. * two accesses to memory, which may be undesirable for some devices.
  30. */
  31. #define __raw_readb(addr) \
  32. ({ u8 __v = (*(volatile u8 *) (addr)); __v; })
  33. #define __raw_readw(addr) \
  34. ({ u16 __v = (*(volatile u16 *) (addr)); __v; })
  35. #define __raw_readl(addr) \
  36. ({ u32 __v = (*(volatile u32 *) (addr)); __v; })
  37. #define __raw_writeb(addr,b) (void)((*(volatile u8 *) (addr)) = (b))
  38. #define __raw_writew(addr,w) (void)((*(volatile u16 *) (addr)) = (w))
  39. #define __raw_writel(addr,l) (void)((*(volatile u32 *) (addr)) = (l))
  40. #define readb(addr) in_8((volatile u8 *)(addr))
  41. #define writeb(b,addr) out_8((volatile u8 *)(addr), (b))
  42. #if !defined(__BIG_ENDIAN)
  43. #define readw(addr) (*(volatile u16 *) (addr))
  44. #define readl(addr) (*(volatile u32 *) (addr))
  45. #define writew(b,addr) ((*(volatile u16 *) (addr)) = (b))
  46. #define writel(b,addr) ((*(volatile u32 *) (addr)) = (b))
  47. #else
  48. #define readw(addr) in_le16((volatile u16 *)(addr))
  49. #define readl(addr) in_le32((volatile u32 *)(addr))
  50. #define writew(b,addr) out_le16((volatile u16 *)(addr),(b))
  51. #define writel(b,addr) out_le32((volatile u32 *)(addr),(b))
  52. #endif
  53. /*
  54. * The insw/outsw/insl/outsl macros don't do byte-swapping.
  55. * They are only used in practice for transferring buffers which
  56. * are arrays of bytes, and byte-swapping is not appropriate in
  57. * that case. - paulus
  58. */
  59. #define insb(port, buf, ns) _insb((u8 *)((port)+_IO_BASE), (buf), (ns))
  60. #define outsb(port, buf, ns) _outsb((u8 *)((port)+_IO_BASE), (buf), (ns))
  61. #define insw(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  62. #define outsw(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  63. #define insl(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  64. #define outsl(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  65. #define inb(port) in_8((u8 *)((port)+_IO_BASE))
  66. #define outb(val, port) out_8((u8 *)((port)+_IO_BASE), (val))
  67. #if !defined(__BIG_ENDIAN)
  68. #define inw(port) in_be16((u16 *)((port)+_IO_BASE))
  69. #define outw(val, port) out_be16((u16 *)((port)+_IO_BASE), (val))
  70. #define inl(port) in_be32((u32 *)((port)+_IO_BASE))
  71. #define outl(val, port) out_be32((u32 *)((port)+_IO_BASE), (val))
  72. #else
  73. #define inw(port) in_le16((u16 *)((port)+_IO_BASE))
  74. #define outw(val, port) out_le16((u16 *)((port)+_IO_BASE), (val))
  75. #define inl(port) in_le32((u32 *)((port)+_IO_BASE))
  76. #define outl(val, port) out_le32((u32 *)((port)+_IO_BASE), (val))
  77. #endif
  78. extern inline void _insb(volatile u8 * port, void *buf, int ns)
  79. {
  80. u8 *data = (u8 *) buf;
  81. while (ns--)
  82. *data++ = *port;
  83. }
  84. extern inline void _outsb(volatile u8 * port, const void *buf, int ns)
  85. {
  86. u8 *data = (u8 *) buf;
  87. while (ns--)
  88. *port = *data++;
  89. }
  90. extern inline void _insw(volatile u16 * port, void *buf, int ns)
  91. {
  92. u16 *data = (u16 *) buf;
  93. while (ns--)
  94. *data++ = __sw16(*port);
  95. }
  96. extern inline void _outsw(volatile u16 * port, const void *buf, int ns)
  97. {
  98. u16 *data = (u16 *) buf;
  99. while (ns--) {
  100. *port = __sw16(*data);
  101. data++;
  102. }
  103. }
  104. extern inline void _insl(volatile u32 * port, void *buf, int nl)
  105. {
  106. u32 *data = (u32 *) buf;
  107. while (nl--)
  108. *data++ = __sw32(*port);
  109. }
  110. extern inline void _outsl(volatile u32 * port, const void *buf, int nl)
  111. {
  112. u32 *data = (u32 *) buf;
  113. while (nl--) {
  114. *port = __sw32(*data);
  115. data++;
  116. }
  117. }
  118. extern inline void _insw_ns(volatile u16 * port, void *buf, int ns)
  119. {
  120. u16 *data = (u16 *) buf;
  121. while (ns--)
  122. *data++ = *port;
  123. }
  124. extern inline void _outsw_ns(volatile u16 * port, const void *buf, int ns)
  125. {
  126. u16 *data = (u16 *) buf;
  127. while (ns--) {
  128. *port = *data++;
  129. }
  130. }
  131. extern inline void _insl_ns(volatile u32 * port, void *buf, int nl)
  132. {
  133. u32 *data = (u32 *) buf;
  134. while (nl--)
  135. *data++ = *port;
  136. }
  137. extern inline void _outsl_ns(volatile u32 * port, const void *buf, int nl)
  138. {
  139. u32 *data = (u32 *) buf;
  140. while (nl--) {
  141. *port = *data;
  142. data++;
  143. }
  144. }
  145. /*
  146. * The *_ns versions below don't do byte-swapping.
  147. * Neither do the standard versions now, these are just here
  148. * for older code.
  149. */
  150. #define insw_ns(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  151. #define outsw_ns(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  152. #define insl_ns(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  153. #define outsl_ns(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  154. #define IO_SPACE_LIMIT ~0
  155. /*
  156. * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
  157. */
  158. extern inline int in_8(volatile u8 * addr)
  159. {
  160. return (int)*addr;
  161. }
  162. extern inline void out_8(volatile u8 * addr, int val)
  163. {
  164. *addr = (u8) val;
  165. }
  166. extern inline int in_le16(volatile u16 * addr)
  167. {
  168. return __sw16(*addr);
  169. }
  170. extern inline int in_be16(volatile u16 * addr)
  171. {
  172. return (*addr & 0xFFFF);
  173. }
  174. extern inline void out_le16(volatile u16 * addr, int val)
  175. {
  176. *addr = __sw16(val);
  177. }
  178. extern inline void out_be16(volatile u16 * addr, int val)
  179. {
  180. *addr = (u16) val;
  181. }
  182. extern inline unsigned in_le32(volatile u32 * addr)
  183. {
  184. return __sw32(*addr);
  185. }
  186. extern inline unsigned in_be32(volatile u32 * addr)
  187. {
  188. return (*addr);
  189. }
  190. extern inline void out_le32(volatile unsigned *addr, int val)
  191. {
  192. *addr = __sw32(val);
  193. }
  194. extern inline void out_be32(volatile unsigned *addr, int val)
  195. {
  196. *addr = val;
  197. }
  198. static inline void sync(void)
  199. {
  200. /* This sync function is for PowerPC or other architecture instruction
  201. * ColdFire does not have this instruction. Dummy function, added for
  202. * compatibility (CFI driver)
  203. */
  204. }
  205. #endif /* __ASM_M68K_IO_H__ */