cminst44xx.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. /*
  67. *
  68. */
  69. /**
  70. * _clktrctrl_write - write @c to a CM_CLKSTCTRL.CLKTRCTRL register bitfield
  71. * @c: CLKTRCTRL register bitfield (LSB = bit 0, i.e., unshifted)
  72. * @part: PRCM partition ID that the CM_CLKSTCTRL register exists in
  73. * @inst: CM instance register offset (*_INST macro)
  74. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  75. *
  76. * @c must be the unshifted value for CLKTRCTRL - i.e., this function
  77. * will handle the shift itself.
  78. */
  79. static void _clktrctrl_write(u8 c, u8 part, s16 inst, u16 cdoffs)
  80. {
  81. u32 v;
  82. v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  83. v &= ~OMAP4430_CLKTRCTRL_MASK;
  84. v |= c << OMAP4430_CLKTRCTRL_SHIFT;
  85. omap4_cminst_write_inst_reg(v, part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  86. }
  87. /**
  88. * omap4_cminst_is_clkdm_in_hwsup - is a clockdomain in hwsup idle mode?
  89. * @part: PRCM partition ID that the CM_CLKSTCTRL register exists in
  90. * @inst: CM instance register offset (*_INST macro)
  91. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  92. *
  93. * Returns true if the clockdomain referred to by (@part, @inst, @cdoffs)
  94. * is in hardware-supervised idle mode, or 0 otherwise.
  95. */
  96. bool omap4_cminst_is_clkdm_in_hwsup(u8 part, s16 inst, u16 cdoffs)
  97. {
  98. u32 v;
  99. v = omap4_cminst_read_inst_reg(part, inst, cdoffs + OMAP4_CM_CLKSTCTRL);
  100. v &= OMAP4430_CLKTRCTRL_MASK;
  101. v >>= OMAP4430_CLKTRCTRL_SHIFT;
  102. return (v == OMAP34XX_CLKSTCTRL_ENABLE_AUTO) ? true : false;
  103. }
  104. /**
  105. * omap4_cminst_clkdm_enable_hwsup - put a clockdomain in hwsup-idle mode
  106. * @part: PRCM partition ID that the clockdomain registers exist in
  107. * @inst: CM instance register offset (*_INST macro)
  108. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  109. *
  110. * Put a clockdomain referred to by (@part, @inst, @cdoffs) into
  111. * hardware-supervised idle mode. No return value.
  112. */
  113. void omap4_cminst_clkdm_enable_hwsup(u8 part, s16 inst, u16 cdoffs)
  114. {
  115. _clktrctrl_write(OMAP34XX_CLKSTCTRL_ENABLE_AUTO, part, inst, cdoffs);
  116. }
  117. /**
  118. * omap4_cminst_clkdm_disable_hwsup - put a clockdomain in swsup-idle mode
  119. * @part: PRCM partition ID that the clockdomain registers exist in
  120. * @inst: CM instance register offset (*_INST macro)
  121. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  122. *
  123. * Put a clockdomain referred to by (@part, @inst, @cdoffs) into
  124. * software-supervised idle mode, i.e., controlled manually by the
  125. * Linux OMAP clockdomain code. No return value.
  126. */
  127. void omap4_cminst_clkdm_disable_hwsup(u8 part, s16 inst, u16 cdoffs)
  128. {
  129. _clktrctrl_write(OMAP34XX_CLKSTCTRL_DISABLE_AUTO, part, inst, cdoffs);
  130. }
  131. /**
  132. * omap4_cminst_clkdm_force_sleep - try to put a clockdomain into idle
  133. * @part: PRCM partition ID that the clockdomain registers exist in
  134. * @inst: CM instance register offset (*_INST macro)
  135. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  136. *
  137. * Put a clockdomain referred to by (@part, @inst, @cdoffs) into idle
  138. * No return value.
  139. */
  140. void omap4_cminst_clkdm_force_sleep(u8 part, s16 inst, u16 cdoffs)
  141. {
  142. _clktrctrl_write(OMAP34XX_CLKSTCTRL_FORCE_SLEEP, part, inst, cdoffs);
  143. }
  144. /**
  145. * omap4_cminst_clkdm_force_sleep - try to take a clockdomain out of idle
  146. * @part: PRCM partition ID that the clockdomain registers exist in
  147. * @inst: CM instance register offset (*_INST macro)
  148. * @cdoffs: Clockdomain register offset (*_CDOFFS macro)
  149. *
  150. * Take a clockdomain referred to by (@part, @inst, @cdoffs) out of idle,
  151. * waking it up. No return value.
  152. */
  153. void omap4_cminst_clkdm_force_wakeup(u8 part, s16 inst, u16 cdoffs)
  154. {
  155. _clktrctrl_write(OMAP34XX_CLKSTCTRL_FORCE_WAKEUP, part, inst, cdoffs);
  156. }
  157. /*
  158. *
  159. */
  160. /**
  161. * omap4_cm_wait_module_ready - wait for a module to be in 'func' state
  162. * @clkctrl_reg: CLKCTRL module address
  163. *
  164. * Wait for the module IDLEST to be functional. If the idle state is in any
  165. * the non functional state (trans, idle or disabled), module and thus the
  166. * sysconfig cannot be accessed and will probably lead to an "imprecise
  167. * external abort"
  168. *
  169. * Module idle state:
  170. * 0x0 func: Module is fully functional, including OCP
  171. * 0x1 trans: Module is performing transition: wakeup, or sleep, or sleep
  172. * abortion
  173. * 0x2 idle: Module is in Idle mode (only OCP part). It is functional if
  174. * using separate functional clock
  175. * 0x3 disabled: Module is disabled and cannot be accessed
  176. *
  177. */
  178. int omap4_cm_wait_module_ready(void __iomem *clkctrl_reg)
  179. {
  180. int i = 0;
  181. if (!clkctrl_reg)
  182. return 0;
  183. omap_test_timeout((
  184. ((__raw_readl(clkctrl_reg) & OMAP4430_IDLEST_MASK) == 0) ||
  185. (((__raw_readl(clkctrl_reg) & OMAP4430_IDLEST_MASK) >>
  186. OMAP4430_IDLEST_SHIFT) == 0x2)),
  187. MAX_MODULE_READY_TIME, i);
  188. return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
  189. }