stmp3xxx_regs.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Freescale STMP37XX/STMP378X SoC register access interfaces
  3. *
  4. * The SoC registers may be accessed via:
  5. *
  6. * - single 32 bit address, or
  7. * - four 32 bit addresses - general purpose, set, clear and toggle bits
  8. *
  9. * Multiple IP blocks (e.g. SSP, UART) provide identical register sets per
  10. * each module
  11. *
  12. * Embedded Alley Solutions, Inc <source@embeddedalley.com>
  13. *
  14. * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
  15. * Copyright 2008 Embedded Alley Solutions, Inc All Rights Reserved.
  16. */
  17. /*
  18. * The code contained herein is licensed under the GNU General Public
  19. * License. You may obtain a copy of the GNU General Public License
  20. * Version 2 or later at the following locations:
  21. *
  22. * http://www.opensource.org/licenses/gpl-license.html
  23. * http://www.gnu.org/copyleft/gpl.html
  24. */
  25. #ifndef __ASM_PLAT_STMP3XXX_REGS_H
  26. #define __ASM_PLAT_STMP3XXX_REGS_H
  27. #ifndef __ASSEMBLER__
  28. #include <linux/io.h>
  29. #endif
  30. #include "platform.h"
  31. #define REGS_BASE STMP3XXX_REGS_BASE
  32. #define HW_STMP3xxx_SET 0x04
  33. #define HW_STMP3xxx_CLR 0x08
  34. #define HW_STMP3xxx_TOG 0x0c
  35. #ifndef __ASSEMBLER__
  36. #define HW_REGISTER_FUNCS(id, base, offset, regset, rd, wr) \
  37. static const u32 id##_OFFSET = offset; \
  38. static inline u32 id##_RD_NB(const void __iomem *regbase) { \
  39. if (!rd) \
  40. printk(KERN_ERR"%s: cannot READ at %p+%x\n", \
  41. #id, regbase, offset); \
  42. return __raw_readl(regbase + offset); \
  43. } \
  44. static inline void id##_WR_NB(void __iomem *regbase, u32 v) { \
  45. if (!wr) \
  46. printk(KERN_ERR"%s: cannot WRITE at %p+%x\n", \
  47. #id, regbase, offset); \
  48. __raw_writel(v, regbase + offset); \
  49. } \
  50. static inline void id##_SET_NB(void __iomem *regbase, u32 v) { \
  51. if (!wr) \
  52. printk(KERN_ERR"%s: cannot SET at %p+%x\n", \
  53. #id, regbase, offset); \
  54. if (regset) \
  55. __raw_writel(v, regbase + \
  56. offset + HW_STMP3xxx_SET); \
  57. else \
  58. __raw_writel(v | __raw_readl(regbase + offset), \
  59. regbase + offset); \
  60. } \
  61. static inline void id##_CLR_NB(void __iomem *regbase, u32 v) { \
  62. if (!wr) \
  63. printk(KERN_ERR"%s: cannot CLR at %p+%x\n", \
  64. #id, regbase, offset); \
  65. if (regset) \
  66. __raw_writel(v, regbase + \
  67. offset + HW_STMP3xxx_CLR); \
  68. else \
  69. __raw_writel( \
  70. ~v & __raw_readl(regbase + offset), \
  71. regbase + offset); \
  72. } \
  73. static inline void id##_TOG_NB(void __iomem *regbase, u32 v) { \
  74. if (!wr) \
  75. printk(KERN_ERR"%s: cannot TOG at %p+%x\n", \
  76. #id, regbase, offset); \
  77. if (regset) \
  78. __raw_writel(v, regbase + \
  79. offset + HW_STMP3xxx_TOG); \
  80. else \
  81. __raw_writel(v ^ __raw_readl(regbase + offset), \
  82. regbase + offset); \
  83. } \
  84. static inline u32 id##_RD(void) { return id##_RD_NB(base); } \
  85. static inline void id##_WR(u32 v) { id##_WR_NB(base, v); } \
  86. static inline void id##_SET(u32 v) { id##_SET_NB(base, v); } \
  87. static inline void id##_CLR(u32 v) { id##_CLR_NB(base, v); } \
  88. static inline void id##_TOG(u32 v) { id##_TOG_NB(base, v); }
  89. #define HW_REGISTER_FUNCS_INDEXED(id, base, offset, regset, rd, wr, step)\
  90. static inline u32 id##_OFFSET(int i) { \
  91. return offset + i * step; \
  92. } \
  93. static inline u32 id##_RD_NB(const void __iomem *regbase, int i) {\
  94. if (!rd) \
  95. printk(KERN_ERR"%s(%d): can't READ at %p+%x\n", \
  96. #id, i, regbase, offset + i * step); \
  97. return __raw_readl(regbase + offset + i * step); \
  98. } \
  99. static inline void id##_WR_NB(void __iomem *regbase, int i, u32 v) {\
  100. if (!wr) \
  101. printk(KERN_ERR"%s(%d): can't WRITE at %p+%x\n",\
  102. #id, i, regbase, offset + i * step); \
  103. __raw_writel(v, regbase + offset + i * step); \
  104. } \
  105. static inline void id##_SET_NB(void __iomem *regbase, int i, u32 v) {\
  106. if (!wr) \
  107. printk(KERN_ERR"%s(%d): can't SET at %p+%x\n", \
  108. #id, i, regbase, offset + i * step); \
  109. if (regset) \
  110. __raw_writel(v, regbase + offset + \
  111. i * step + HW_STMP3xxx_SET); \
  112. else \
  113. __raw_writel(v | __raw_readl(regbase + \
  114. offset + i * step), \
  115. regbase + offset + i * step); \
  116. } \
  117. static inline void id##_CLR_NB(void __iomem *regbase, int i, u32 v) {\
  118. if (!wr) \
  119. printk(KERN_ERR"%s(%d): cannot CLR at %p+%x\n", \
  120. #id, i, regbase, offset + i * step); \
  121. if (regset) \
  122. __raw_writel(v, regbase + offset + \
  123. i * step + HW_STMP3xxx_CLR); \
  124. else \
  125. __raw_writel(~v & __raw_readl(regbase + \
  126. offset + i * step), \
  127. regbase + offset + i * step); \
  128. } \
  129. static inline void id##_TOG_NB(void __iomem *regbase, int i, u32 v) {\
  130. if (!wr) \
  131. printk(KERN_ERR"%s(%d): cannot TOG at %p+%x\n", \
  132. #id, i, regbase, offset + i * step); \
  133. if (regset) \
  134. __raw_writel(v, regbase + offset + \
  135. i * step + HW_STMP3xxx_TOG); \
  136. else \
  137. __raw_writel(v ^ __raw_readl(regbase + offset \
  138. + i * step), \
  139. regbase + offset + i * step); \
  140. } \
  141. static inline u32 id##_RD(int i) \
  142. { \
  143. return id##_RD_NB(base, i); \
  144. } \
  145. static inline void id##_WR(int i, u32 v) \
  146. { \
  147. id##_WR_NB(base, i, v); \
  148. } \
  149. static inline void id##_SET(int i, u32 v) \
  150. { \
  151. id##_SET_NB(base, i, v); \
  152. } \
  153. static inline void id##_CLR(int i, u32 v) \
  154. { \
  155. id##_CLR_NB(base, i, v); \
  156. } \
  157. static inline void id##_TOG(int i, u32 v) \
  158. { \
  159. id##_TOG_NB(base, i, v); \
  160. }
  161. #define HW_REGISTER_WO(id, base, offset)\
  162. HW_REGISTER_FUNCS(id, base, offset, 1, 0, 1)
  163. #define HW_REGISTER_RO(id, base, offset)\
  164. HW_REGISTER_FUNCS(id, base, offset, 1, 1, 0)
  165. #define HW_REGISTER(id, base, offset) \
  166. HW_REGISTER_FUNCS(id, base, offset, 1, 1, 1)
  167. #define HW_REGISTER_0(id, base, offset) \
  168. HW_REGISTER_FUNCS(id, base, offset, 0, 1, 1)
  169. #define HW_REGISTER_INDEXED(id, base, offset, step) \
  170. HW_REGISTER_FUNCS_INDEXED(id, base, offset, 1, 1, 1, step)
  171. #define HW_REGISTER_RO_INDEXED(id, base, offset, step) \
  172. HW_REGISTER_FUNCS_INDEXED(id, base, offset, 1, 1, 0, step)
  173. #define HW_REGISTER_0_INDEXED(id, base, offset, step) \
  174. HW_REGISTER_FUNCS_INDEXED(id, base, offset, 0, 1, 1, step)
  175. #else /* __ASSEMBLER__ */
  176. #define HW_REGISTER_FUNCS(id, base, offset, regset, rd, wr)
  177. #define HW_REGISTER_FUNCS_INDEXED(id, base, offset, regset, rd, wr, step)
  178. #define HW_REGISTER_WO(id, base, offset)
  179. #define HW_REGISTER_RO(id, base, offset)
  180. #define HW_REGISTER(id, base, offset)
  181. #define HW_REGISTER_0(id, base, offset)
  182. #define HW_REGISTER_INDEXED(id, base, offset, step)
  183. #define HW_REGISTER_RO_INDEXED(id, base, offset, step)
  184. #define HW_REGISTER_0_INDEXED(id, base, offset, step)
  185. #endif /* __ASSEMBLER__ */
  186. #endif /* __ASM_PLAT_STMP3XXX_REGS_H */