cminst44xx.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * OMAP4 CM instance functions
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Paul Walmsley
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This is needed since CM instances can be in the PRM, PRCM_MPU, CM1,
  12. * or CM2 hardware modules. For example, the EMU_CM CM instance is in
  13. * the PRM hardware module. What a mess...
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/types.h>
  17. #include <linux/errno.h>
  18. #include <linux/err.h>
  19. #include <linux/io.h>
  20. #include <plat/common.h>
  21. #include "cm.h"
  22. #include "cm1_44xx.h"
  23. #include "cm2_44xx.h"
  24. #include "cm44xx.h"
  25. #include "cminst44xx.h"
  26. #include "cm-regbits-34xx.h"
  27. #include "cm-regbits-44xx.h"
  28. #include "prcm44xx.h"
  29. #include "prm44xx.h"
  30. #include "prcm_mpu44xx.h"
  31. static u32 _cm_bases[OMAP4_MAX_PRCM_PARTITIONS] = {
  32. [OMAP4430_INVALID_PRCM_PARTITION] = 0,
  33. [OMAP4430_PRM_PARTITION] = OMAP4430_PRM_BASE,
  34. [OMAP4430_CM1_PARTITION] = OMAP4430_CM1_BASE,
  35. [OMAP4430_CM2_PARTITION] = OMAP4430_CM2_BASE,
  36. [OMAP4430_SCRM_PARTITION] = 0,
  37. [OMAP4430_PRCM_MPU_PARTITION] = OMAP4430_PRCM_MPU_BASE,
  38. };
  39. /* Read a register in a CM instance */
  40. u32 omap4_cminst_read_inst_reg(u8 part, s16 inst, u16 idx)
  41. {
  42. BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
  43. part == OMAP4430_INVALID_PRCM_PARTITION ||
  44. !_cm_bases[part]);
  45. return __raw_readl(OMAP2_L4_IO_ADDRESS(_cm_bases[part] + inst + idx));
  46. }
  47. /* Write into a register in a CM instance */
  48. void omap4_cminst_write_inst_reg(u32 val, u8 part, s16 inst, u16 idx)
  49. {
  50. BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
  51. part == OMAP4430_INVALID_PRCM_PARTITION ||
  52. !_cm_bases[part]);
  53. __raw_writel(val, OMAP2_L4_IO_ADDRESS(_cm_bases[part] + inst + idx));
  54. }
  55. /* Read-modify-write a register in CM1. Caller must lock */
  56. u32 omap4_cminst_rmw_inst_reg_bits(u32 mask, u32 bits, u8 part, s16 inst,
  57. s16 idx)
  58. {
  59. u32 v;
  60. v = omap4_cminst_read_inst_reg(part, inst, idx);
  61. v &= ~mask;
  62. v |= bits;
  63. omap4_cminst_write_inst_reg(v, part, inst, idx);
  64. return v;
  65. }
  66. u32 omap4_cminst_set_inst_reg_bits(u32 bits, u8 part, s16 inst, s16 idx)
  67. {
  68. return omap4_cminst_rmw_inst_reg_bits(bits, bits, part, inst, idx);
  69. }
  70. u32 omap4_cminst_clear_inst_reg_bits(u32 bits, u8 part, s16 inst, s16 idx)
  71. {
  72. return omap4_cminst_rmw_inst_reg_bits(bits, 0x0, part, inst, idx);
  73. }
  74. u32 omap4_cminst_read_inst_reg_bits(u8 part, u16 inst, s16 idx, u32 mask)
  75. {
  76. u32 v;
  77. v = omap4_cminst_read_inst_reg(part, inst, idx);
  78. v &= mask;
  79. v >>= __ffs(mask);
  80. return v;
  81. }
  82. /*
  83. *
  84. */
  85. /**
  86. * _clktrctrl_write - write @c to a CM_CLKSTCTRL.CLKTRCTRL register bitfield
  87. * @c: CLKTRCTRL register bitfield (LSB = bit 0, i.e., unshifted)
  88. * @part: PRCM partition ID that the CM_CLKSTCTRL register exists in
  89. * @inst: CM instance register offset (*_INST macro)
  90. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  91. *
  92. * @c must be the unshifted value for CLKTRCTRL - i.e., this function
  93. * will handle the shift itself.
  94. */
  95. static void _clktrctrl_write(u8 c, u8 part, s16 inst, u16 cdoffs)
  96. {
  97. u32 v;
  98. v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  99. v &= ~OMAP4430_CLKTRCTRL_MASK;
  100. v |= c << OMAP4430_CLKTRCTRL_SHIFT;
  101. omap4_cminst_write_inst_reg(v, part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  102. }
  103. /**
  104. * omap4_cminst_is_clkdm_in_hwsup - is a clockdomain in hwsup idle mode?
  105. * @part: PRCM partition ID that the CM_CLKSTCTRL register exists in
  106. * @inst: CM instance register offset (*_INST macro)
  107. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  108. *
  109. * Returns true if the clockdomain referred to by (@part, @inst, @cdoffs)
  110. * is in hardware-supervised idle mode, or 0 otherwise.
  111. */
  112. bool omap4_cminst_is_clkdm_in_hwsup(u8 part, s16 inst, u16 cdoffs)
  113. {
  114. u32 v;
  115. v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  116. v &= OMAP4430_CLKTRCTRL_MASK;
  117. v >>= OMAP4430_CLKTRCTRL_SHIFT;
  118. return (v == OMAP34XX_CLKSTCTRL_ENABLE_AUTO) ? true : false;
  119. }
  120. /**
  121. * omap4_cminst_clkdm_enable_hwsup - put a clockdomain in hwsup-idle mode
  122. * @part: PRCM partition ID that the clockdomain registers exist in
  123. * @inst: CM instance register offset (*_INST macro)
  124. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  125. *
  126. * Put a clockdomain referred to by (@part, @inst, @cdoffs) into
  127. * hardware-supervised idle mode. No return value.
  128. */
  129. void omap4_cminst_clkdm_enable_hwsup(u8 part, s16 inst, u16 cdoffs)
  130. {
  131. _clktrctrl_write(OMAP34XX_CLKSTCTRL_ENABLE_AUTO, part, inst, cdoffs);
  132. }
  133. /**
  134. * omap4_cminst_clkdm_disable_hwsup - put a clockdomain in swsup-idle mode
  135. * @part: PRCM partition ID that the clockdomain registers exist in
  136. * @inst: CM instance register offset (*_INST macro)
  137. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  138. *
  139. * Put a clockdomain referred to by (@part, @inst, @cdoffs) into
  140. * software-supervised idle mode, i.e., controlled manually by the
  141. * Linux OMAP clockdomain code. No return value.
  142. */
  143. void omap4_cminst_clkdm_disable_hwsup(u8 part, s16 inst, u16 cdoffs)
  144. {
  145. _clktrctrl_write(OMAP34XX_CLKSTCTRL_DISABLE_AUTO, part, inst, cdoffs);
  146. }
  147. /**
  148. * omap4_cminst_clkdm_force_sleep - try to put a clockdomain into idle
  149. * @part: PRCM partition ID that the clockdomain registers exist in
  150. * @inst: CM instance register offset (*_INST macro)
  151. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  152. *
  153. * Put a clockdomain referred to by (@part, @inst, @cdoffs) into idle
  154. * No return value.
  155. */
  156. void omap4_cminst_clkdm_force_sleep(u8 part, s16 inst, u16 cdoffs)
  157. {
  158. _clktrctrl_write(OMAP34XX_CLKSTCTRL_FORCE_SLEEP, part, inst, cdoffs);
  159. }
  160. /**
  161. * omap4_cminst_clkdm_force_sleep - try to take a clockdomain out of idle
  162. * @part: PRCM partition ID that the clockdomain registers exist in
  163. * @inst: CM instance register offset (*_INST macro)
  164. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  165. *
  166. * Take a clockdomain referred to by (@part, @inst, @cdoffs) out of idle,
  167. * waking it up. No return value.
  168. */
  169. void omap4_cminst_clkdm_force_wakeup(u8 part, s16 inst, u16 cdoffs)
  170. {
  171. _clktrctrl_write(OMAP34XX_CLKSTCTRL_FORCE_WAKEUP, part, inst, cdoffs);
  172. }
  173. /*
  174. *
  175. */
  176. /**
  177. * omap4_cm_wait_module_ready - wait for a module to be in 'func' state
  178. * @clkctrl_reg: CLKCTRL module address
  179. *
  180. * Wait for the module IDLEST to be functional. If the idle state is in any
  181. * the non functional state (trans, idle or disabled), module and thus the
  182. * sysconfig cannot be accessed and will probably lead to an "imprecise
  183. * external abort"
  184. *
  185. * Module idle state:
  186. * 0x0 func: Module is fully functional, including OCP
  187. * 0x1 trans: Module is performing transition: wakeup, or sleep, or sleep
  188. * abortion
  189. * 0x2 idle: Module is in Idle mode (only OCP part). It is functional if
  190. * using separate functional clock
  191. * 0x3 disabled: Module is disabled and cannot be accessed
  192. *
  193. */
  194. int omap4_cm_wait_module_ready(void __iomem *clkctrl_reg)
  195. {
  196. int i = 0;
  197. if (!clkctrl_reg)
  198. return 0;
  199. omap_test_timeout((
  200. ((__raw_readl(clkctrl_reg) & OMAP4430_IDLEST_MASK) == 0) ||
  201. (((__raw_readl(clkctrl_reg) & OMAP4430_IDLEST_MASK) >>
  202. OMAP4430_IDLEST_SHIFT) == 0x2)),
  203. MAX_MODULE_READY_TIME, i);
  204. return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
  205. }