io.h 6.8 KB

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