io.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 __raw_readb(addr) (*(volatile u8 *)(addr))
  29. #define __raw_readw(addr) (*(volatile u16 *)(addr))
  30. #define __raw_readl(addr) (*(volatile u32 *)(addr))
  31. #define __raw_writeb(b,addr) ((*(volatile u8 *) (addr)) = (b))
  32. #define __raw_writew(w,addr) ((*(volatile u16 *) (addr)) = (w))
  33. #define __raw_writel(l,addr) ((*(volatile u32 *) (addr)) = (l))
  34. #define readb(addr) in_8((volatile u8 *)(addr))
  35. #define writeb(b,addr) out_8((volatile u8 *)(addr), (b))
  36. #if !defined(__BIG_ENDIAN)
  37. #define readw(addr) (*(volatile u16 *) (addr))
  38. #define readl(addr) (*(volatile u32 *) (addr))
  39. #define writew(b,addr) ((*(volatile u16 *) (addr)) = (b))
  40. #define writel(b,addr) ((*(volatile u32 *) (addr)) = (b))
  41. #else
  42. #define readw(addr) in_le16((volatile u16 *)(addr))
  43. #define readl(addr) in_le32((volatile u32 *)(addr))
  44. #define writew(b,addr) out_le16((volatile u16 *)(addr),(b))
  45. #define writel(b,addr) out_le32((volatile u32 *)(addr),(b))
  46. #endif
  47. /*
  48. * The insw/outsw/insl/outsl macros don't do byte-swapping.
  49. * They are only used in practice for transferring buffers which
  50. * are arrays of bytes, and byte-swapping is not appropriate in
  51. * that case. - paulus
  52. */
  53. #define insb(port, buf, ns) _insb((u8 *)((port)+_IO_BASE), (buf), (ns))
  54. #define outsb(port, buf, ns) _outsb((u8 *)((port)+_IO_BASE), (buf), (ns))
  55. #define insw(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  56. #define outsw(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  57. #define insl(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  58. #define outsl(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  59. #define inb(port) in_8((u8 *)((port)+_IO_BASE))
  60. #define outb(val, port) out_8((u8 *)((port)+_IO_BASE), (val))
  61. #if !defined(__BIG_ENDIAN)
  62. #define inw(port) in_be16((u16 *)((port)+_IO_BASE))
  63. #define outw(val, port) out_be16((u16 *)((port)+_IO_BASE), (val))
  64. #define inl(port) in_be32((u32 *)((port)+_IO_BASE))
  65. #define outl(val, port) out_be32((u32 *)((port)+_IO_BASE), (val))
  66. #else
  67. #define inw(port) in_le16((u16 *)((port)+_IO_BASE))
  68. #define outw(val, port) out_le16((u16 *)((port)+_IO_BASE), (val))
  69. #define inl(port) in_le32((u32 *)((port)+_IO_BASE))
  70. #define outl(val, port) out_le32((u32 *)((port)+_IO_BASE), (val))
  71. #endif
  72. extern inline void _insb(volatile u8 * port, void *buf, int ns)
  73. {
  74. u8 *data = (u8 *) buf;
  75. while (ns--)
  76. *data++ = *port;
  77. }
  78. extern inline void _outsb(volatile u8 * port, const void *buf, int ns)
  79. {
  80. u8 *data = (u8 *) buf;
  81. while (ns--)
  82. *port = *data++;
  83. }
  84. extern inline void _insw(volatile u16 * port, void *buf, int ns)
  85. {
  86. u16 *data = (u16 *) buf;
  87. while (ns--)
  88. *data++ = __sw16(*port);
  89. }
  90. extern inline void _outsw(volatile u16 * port, const void *buf, int ns)
  91. {
  92. u16 *data = (u16 *) buf;
  93. while (ns--) {
  94. *port = __sw16(*data);
  95. data++;
  96. }
  97. }
  98. extern inline void _insl(volatile u32 * port, void *buf, int nl)
  99. {
  100. u32 *data = (u32 *) buf;
  101. while (nl--)
  102. *data++ = __sw32(*port);
  103. }
  104. extern inline void _outsl(volatile u32 * port, const void *buf, int nl)
  105. {
  106. u32 *data = (u32 *) buf;
  107. while (nl--) {
  108. *port = __sw32(*data);
  109. data++;
  110. }
  111. }
  112. extern inline void _insw_ns(volatile u16 * port, void *buf, int ns)
  113. {
  114. u16 *data = (u16 *) buf;
  115. while (ns--)
  116. *data++ = *port;
  117. }
  118. extern inline void _outsw_ns(volatile u16 * port, const void *buf, int ns)
  119. {
  120. u16 *data = (u16 *) buf;
  121. while (ns--) {
  122. *port = *data++;
  123. }
  124. }
  125. extern inline void _insl_ns(volatile u32 * port, void *buf, int nl)
  126. {
  127. u32 *data = (u32 *) buf;
  128. while (nl--)
  129. *data++ = *port;
  130. }
  131. extern inline void _outsl_ns(volatile u32 * port, const void *buf, int nl)
  132. {
  133. u32 *data = (u32 *) buf;
  134. while (nl--) {
  135. *port = *data;
  136. data++;
  137. }
  138. }
  139. /*
  140. * The *_ns versions below don't do byte-swapping.
  141. * Neither do the standard versions now, these are just here
  142. * for older code.
  143. */
  144. #define insw_ns(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  145. #define outsw_ns(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  146. #define insl_ns(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  147. #define outsl_ns(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  148. #define IO_SPACE_LIMIT ~0
  149. /*
  150. * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
  151. */
  152. extern inline int in_8(volatile u8 * addr)
  153. {
  154. return (int)*addr;
  155. }
  156. extern inline void out_8(volatile u8 * addr, int val)
  157. {
  158. *addr = (u8) val;
  159. }
  160. extern inline int in_le16(volatile u16 * addr)
  161. {
  162. return __sw16(*addr);
  163. }
  164. extern inline int in_be16(volatile u16 * addr)
  165. {
  166. return (*addr & 0xFFFF);
  167. }
  168. extern inline void out_le16(volatile u16 * addr, int val)
  169. {
  170. *addr = __sw16(val);
  171. }
  172. extern inline void out_be16(volatile u16 * addr, int val)
  173. {
  174. *addr = (u16) val;
  175. }
  176. extern inline unsigned in_le32(volatile u32 * addr)
  177. {
  178. return __sw32(*addr);
  179. }
  180. extern inline unsigned in_be32(volatile u32 * addr)
  181. {
  182. return (*addr);
  183. }
  184. extern inline void out_le32(volatile unsigned *addr, int val)
  185. {
  186. *addr = __sw32(val);
  187. }
  188. extern inline void out_be32(volatile unsigned *addr, int val)
  189. {
  190. *addr = val;
  191. }
  192. static inline void sync(void)
  193. {
  194. /* This sync function is for PowerPC or other architecture instruction
  195. * ColdFire does not have this instruction. Dummy function, added for
  196. * compatibility (CFI driver)
  197. */
  198. }
  199. /*
  200. * Given a physical address and a length, return a virtual address
  201. * that can be used to access the memory range with the caching
  202. * properties specified by "flags".
  203. */
  204. typedef unsigned long phys_addr_t;
  205. #define MAP_NOCACHE (0)
  206. #define MAP_WRCOMBINE (0)
  207. #define MAP_WRBACK (0)
  208. #define MAP_WRTHROUGH (0)
  209. static inline void *map_physmem(phys_addr_t paddr, unsigned long len,
  210. unsigned long flags)
  211. {
  212. return (void *)paddr;
  213. }
  214. /*
  215. * Take down a mapping set up by map_physmem().
  216. */
  217. static inline void unmap_physmem(void *vaddr, unsigned long flags)
  218. {
  219. }
  220. #endif /* __ASM_M68K_IO_H__ */