prm2xxx_3xxx.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OMAP2/3 PRM module functions
  4. *
  5. * Copyright (C) 2010-2011 Texas Instruments, Inc.
  6. * Copyright (C) 2010 Nokia Corporation
  7. * Benoît Cousson
  8. * Paul Walmsley
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/err.h>
  13. #include <linux/io.h>
  14. #include "powerdomain.h"
  15. #include "prm2xxx_3xxx.h"
  16. #include "prm-regbits-24xx.h"
  17. #include "clockdomain.h"
  18. /**
  19. * omap2_prm_is_hardreset_asserted - read the HW reset line state of
  20. * submodules contained in the hwmod module
  21. * @shift: register bit shift corresponding to the reset line to check
  22. * @part: PRM partition, ignored for OMAP2
  23. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  24. * @offset: register offset, ignored for OMAP2
  25. *
  26. * Returns 1 if the (sub)module hardreset line is currently asserted,
  27. * 0 if the (sub)module hardreset line is not currently asserted, or
  28. * -EINVAL if called while running on a non-OMAP2/3 chip.
  29. */
  30. int omap2_prm_is_hardreset_asserted(u8 shift, u8 part, s16 prm_mod, u16 offset)
  31. {
  32. return omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL,
  33. (1 << shift));
  34. }
  35. /**
  36. * omap2_prm_assert_hardreset - assert the HW reset line of a submodule
  37. * @shift: register bit shift corresponding to the reset line to assert
  38. * @part: PRM partition, ignored for OMAP2
  39. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  40. * @offset: register offset, ignored for OMAP2
  41. *
  42. * Some IPs like dsp or iva contain processors that require an HW
  43. * reset line to be asserted / deasserted in order to fully enable the
  44. * IP. These modules may have multiple hard-reset lines that reset
  45. * different 'submodules' inside the IP block. This function will
  46. * place the submodule into reset. Returns 0 upon success or -EINVAL
  47. * upon an argument error.
  48. */
  49. int omap2_prm_assert_hardreset(u8 shift, u8 part, s16 prm_mod, u16 offset)
  50. {
  51. u32 mask;
  52. mask = 1 << shift;
  53. omap2_prm_rmw_mod_reg_bits(mask, mask, prm_mod, OMAP2_RM_RSTCTRL);
  54. return 0;
  55. }
  56. /**
  57. * omap2_prm_deassert_hardreset - deassert a submodule hardreset line and wait
  58. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  59. * @rst_shift: register bit shift corresponding to the reset line to deassert
  60. * @st_shift: register bit shift for the status of the deasserted submodule
  61. * @part: PRM partition, not used for OMAP2
  62. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  63. * @rst_offset: reset register offset, not used for OMAP2
  64. * @st_offset: reset status register offset, not used for OMAP2
  65. *
  66. * Some IPs like dsp or iva contain processors that require an HW
  67. * reset line to be asserted / deasserted in order to fully enable the
  68. * IP. These modules may have multiple hard-reset lines that reset
  69. * different 'submodules' inside the IP block. This function will
  70. * take the submodule out of reset and wait until the PRCM indicates
  71. * that the reset has completed before returning. Returns 0 upon success or
  72. * -EINVAL upon an argument error, -EEXIST if the submodule was already out
  73. * of reset, or -EBUSY if the submodule did not exit reset promptly.
  74. */
  75. int omap2_prm_deassert_hardreset(u8 rst_shift, u8 st_shift, u8 part,
  76. s16 prm_mod, u16 rst_offset, u16 st_offset)
  77. {
  78. u32 rst, st;
  79. int c;
  80. rst = 1 << rst_shift;
  81. st = 1 << st_shift;
  82. /* Check the current status to avoid de-asserting the line twice */
  83. if (omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, rst) == 0)
  84. return -EEXIST;
  85. /* Clear the reset status by writing 1 to the status bit */
  86. omap2_prm_rmw_mod_reg_bits(0xffffffff, st, prm_mod, OMAP2_RM_RSTST);
  87. /* de-assert the reset control line */
  88. omap2_prm_rmw_mod_reg_bits(rst, 0, prm_mod, OMAP2_RM_RSTCTRL);
  89. /* wait the status to be set */
  90. omap_test_timeout(omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTST,
  91. st),
  92. MAX_MODULE_HARDRESET_WAIT, c);
  93. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  94. }
  95. /* Powerdomain low-level functions */
  96. /* Common functions across OMAP2 and OMAP3 */
  97. int omap2_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank,
  98. u8 pwrst)
  99. {
  100. u32 m;
  101. m = omap2_pwrdm_get_mem_bank_onstate_mask(bank);
  102. omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs,
  103. OMAP2_PM_PWSTCTRL);
  104. return 0;
  105. }
  106. int omap2_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank,
  107. u8 pwrst)
  108. {
  109. u32 m;
  110. m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
  111. omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs,
  112. OMAP2_PM_PWSTCTRL);
  113. return 0;
  114. }
  115. int omap2_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
  116. {
  117. u32 m;
  118. m = omap2_pwrdm_get_mem_bank_stst_mask(bank);
  119. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, OMAP2_PM_PWSTST,
  120. m);
  121. }
  122. int omap2_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
  123. {
  124. u32 m;
  125. m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
  126. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  127. OMAP2_PM_PWSTCTRL, m);
  128. }
  129. int omap2_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
  130. {
  131. u32 v;
  132. v = pwrst << __ffs(OMAP_LOGICRETSTATE_MASK);
  133. omap2_prm_rmw_mod_reg_bits(OMAP_LOGICRETSTATE_MASK, v, pwrdm->prcm_offs,
  134. OMAP2_PM_PWSTCTRL);
  135. return 0;
  136. }
  137. int omap2_pwrdm_wait_transition(struct powerdomain *pwrdm)
  138. {
  139. u32 c = 0;
  140. /*
  141. * REVISIT: pwrdm_wait_transition() may be better implemented
  142. * via a callback and a periodic timer check -- how long do we expect
  143. * powerdomain transitions to take?
  144. */
  145. /* XXX Is this udelay() value meaningful? */
  146. while ((omap2_prm_read_mod_reg(pwrdm->prcm_offs, OMAP2_PM_PWSTST) &
  147. OMAP_INTRANSITION_MASK) &&
  148. (c++ < PWRDM_TRANSITION_BAILOUT))
  149. udelay(1);
  150. if (c > PWRDM_TRANSITION_BAILOUT) {
  151. pr_err("powerdomain: %s: waited too long to complete transition\n",
  152. pwrdm->name);
  153. return -EAGAIN;
  154. }
  155. pr_debug("powerdomain: completed transition in %d loops\n", c);
  156. return 0;
  157. }
  158. int omap2_clkdm_add_wkdep(struct clockdomain *clkdm1,
  159. struct clockdomain *clkdm2)
  160. {
  161. omap2_prm_set_mod_reg_bits((1 << clkdm2->dep_bit),
  162. clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP);
  163. return 0;
  164. }
  165. int omap2_clkdm_del_wkdep(struct clockdomain *clkdm1,
  166. struct clockdomain *clkdm2)
  167. {
  168. omap2_prm_clear_mod_reg_bits((1 << clkdm2->dep_bit),
  169. clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP);
  170. return 0;
  171. }
  172. int omap2_clkdm_read_wkdep(struct clockdomain *clkdm1,
  173. struct clockdomain *clkdm2)
  174. {
  175. return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs,
  176. PM_WKDEP, (1 << clkdm2->dep_bit));
  177. }
  178. /* XXX Caller must hold the clkdm's powerdomain lock */
  179. int omap2_clkdm_clear_all_wkdeps(struct clockdomain *clkdm)
  180. {
  181. struct clkdm_dep *cd;
  182. u32 mask = 0;
  183. for (cd = clkdm->wkdep_srcs; cd && cd->clkdm_name; cd++) {
  184. if (!cd->clkdm)
  185. continue; /* only happens if data is erroneous */
  186. /* PRM accesses are slow, so minimize them */
  187. mask |= 1 << cd->clkdm->dep_bit;
  188. cd->wkdep_usecount = 0;
  189. }
  190. omap2_prm_clear_mod_reg_bits(mask, clkdm->pwrdm.ptr->prcm_offs,
  191. PM_WKDEP);
  192. return 0;
  193. }