io.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. #define readb(addr) in_8((volatile u8 *)(addr))
  29. #define writeb(b,addr) out_8((volatile u8 *)(addr), (b))
  30. #if !defined(__BIG_ENDIAN)
  31. #define readw(addr) (*(volatile u16 *) (addr))
  32. #define readl(addr) (*(volatile u32 *) (addr))
  33. #define writew(b,addr) ((*(volatile u16 *) (addr)) = (b))
  34. #define writel(b,addr) ((*(volatile u32 *) (addr)) = (b))
  35. #else
  36. #define readw(addr) in_le16((volatile u16 *)(addr))
  37. #define readl(addr) in_le32((volatile u32 *)(addr))
  38. #define writew(b,addr) out_le16((volatile u16 *)(addr),(b))
  39. #define writel(b,addr) out_le32((volatile u32 *)(addr),(b))
  40. #endif
  41. /*
  42. * The insw/outsw/insl/outsl macros don't do byte-swapping.
  43. * They are only used in practice for transferring buffers which
  44. * are arrays of bytes, and byte-swapping is not appropriate in
  45. * that case. - paulus
  46. */
  47. #define insb(port, buf, ns) _insb((u8 *)((port)+_IO_BASE), (buf), (ns))
  48. #define outsb(port, buf, ns) _outsb((u8 *)((port)+_IO_BASE), (buf), (ns))
  49. #define insw(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  50. #define outsw(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  51. #define insl(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  52. #define outsl(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  53. #define inb(port) in_8((u8 *)((port)+_IO_BASE))
  54. #define outb(val, port) out_8((u8 *)((port)+_IO_BASE), (val))
  55. #if !defined(__BIG_ENDIAN)
  56. #define inw(port) in_be16((u16 *)((port)+_IO_BASE))
  57. #define outw(val, port) out_be16((u16 *)((port)+_IO_BASE), (val))
  58. #define inl(port) in_be32((u32 *)((port)+_IO_BASE))
  59. #define outl(val, port) out_be32((u32 *)((port)+_IO_BASE), (val))
  60. #else
  61. #define inw(port) in_le16((u16 *)((port)+_IO_BASE))
  62. #define outw(val, port) out_le16((u16 *)((port)+_IO_BASE), (val))
  63. #define inl(port) in_le32((u32 *)((port)+_IO_BASE))
  64. #define outl(val, port) out_le32((u32 *)((port)+_IO_BASE), (val))
  65. #endif
  66. extern inline void _insb(volatile u8 * port, void *buf, int ns)
  67. {
  68. u8 *data = (u8 *) buf;
  69. while (ns--)
  70. *data++ = *port;
  71. }
  72. extern inline void _outsb(volatile u8 * port, const void *buf, int ns)
  73. {
  74. u8 *data = (u8 *) buf;
  75. while (ns--)
  76. *port = *data++;
  77. }
  78. extern inline void _insw(volatile u16 * port, void *buf, int ns)
  79. {
  80. u16 *data = (u16 *) buf;
  81. while (ns--)
  82. *data++ = __sw16(*port);
  83. }
  84. extern inline void _outsw(volatile u16 * port, const void *buf, int ns)
  85. {
  86. u16 *data = (u16 *) buf;
  87. while (ns--) {
  88. *port = __sw16(*data);
  89. data++;
  90. }
  91. }
  92. extern inline void _insl(volatile u32 * port, void *buf, int nl)
  93. {
  94. u32 *data = (u32 *) buf;
  95. while (nl--)
  96. *data++ = __sw32(*port);
  97. }
  98. extern inline void _outsl(volatile u32 * port, const void *buf, int nl)
  99. {
  100. u32 *data = (u32 *) buf;
  101. while (nl--) {
  102. *port = __sw32(*data);
  103. data++;
  104. }
  105. }
  106. extern inline void _insw_ns(volatile u16 * port, void *buf, int ns)
  107. {
  108. u16 *data = (u16 *) buf;
  109. while (ns--)
  110. *data++ = *port;
  111. }
  112. extern inline void _outsw_ns(volatile u16 * port, const void *buf, int ns)
  113. {
  114. u16 *data = (u16 *) buf;
  115. while (ns--) {
  116. *port = *data++;
  117. }
  118. }
  119. extern inline void _insl_ns(volatile u32 * port, void *buf, int nl)
  120. {
  121. u32 *data = (u32 *) buf;
  122. while (nl--)
  123. *data++ = *port;
  124. }
  125. extern inline void _outsl_ns(volatile u32 * port, const void *buf, int nl)
  126. {
  127. u32 *data = (u32 *) buf;
  128. while (nl--) {
  129. *port = *data;
  130. data++;
  131. }
  132. }
  133. /*
  134. * The *_ns versions below don't do byte-swapping.
  135. * Neither do the standard versions now, these are just here
  136. * for older code.
  137. */
  138. #define insw_ns(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  139. #define outsw_ns(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  140. #define insl_ns(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  141. #define outsl_ns(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  142. #define IO_SPACE_LIMIT ~0
  143. /*
  144. * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
  145. */
  146. extern inline int in_8(volatile u8 * addr)
  147. {
  148. return (int)*addr;
  149. }
  150. extern inline void out_8(volatile u8 * addr, int val)
  151. {
  152. *addr = (u8) val;
  153. }
  154. extern inline int in_le16(volatile u16 * addr)
  155. {
  156. return __sw16(*addr);
  157. }
  158. extern inline int in_be16(volatile u16 * addr)
  159. {
  160. return (*addr & 0xFFFF);
  161. }
  162. extern inline void out_le16(volatile u16 * addr, int val)
  163. {
  164. *addr = __sw16(val);
  165. }
  166. extern inline void out_be16(volatile u16 * addr, int val)
  167. {
  168. *addr = (u16) val;
  169. }
  170. extern inline unsigned in_le32(volatile u32 * addr)
  171. {
  172. return __sw32(*addr);
  173. }
  174. extern inline unsigned in_be32(volatile u32 * addr)
  175. {
  176. return (*addr);
  177. }
  178. extern inline void out_le32(volatile unsigned *addr, int val)
  179. {
  180. *addr = __sw32(val);
  181. }
  182. extern inline void out_be32(volatile unsigned *addr, int val)
  183. {
  184. *addr = val;
  185. }
  186. #endif /* __ASM_M68K_IO_H__ */