prm2xxx_3xxx.c 6.4 KB

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