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 "common.h"
  18. #include "powerdomain.h"
  19. #include "prm2xxx_3xxx.h"
  20. #include "prm-regbits-24xx.h"
  21. #include "clockdomain.h"
  22. /**
  23. * omap2_prm_is_hardreset_asserted - read the HW reset line state of
  24. * submodules contained in the hwmod module
  25. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  26. * @shift: register bit shift corresponding to the reset line to check
  27. *
  28. * Returns 1 if the (sub)module hardreset line is currently asserted,
  29. * 0 if the (sub)module hardreset line is not currently asserted, or
  30. * -EINVAL if called while running on a non-OMAP2/3 chip.
  31. */
  32. int omap2_prm_is_hardreset_asserted(s16 prm_mod, u8 shift)
  33. {
  34. return omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL,
  35. (1 << shift));
  36. }
  37. /**
  38. * omap2_prm_assert_hardreset - assert the HW reset line of a submodule
  39. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  40. * @shift: register bit shift corresponding to the reset line to assert
  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(s16 prm_mod, u8 shift)
  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. *
  62. * Some IPs like dsp or iva contain processors that require an HW
  63. * reset line to be asserted / deasserted in order to fully enable the
  64. * IP. These modules may have multiple hard-reset lines that reset
  65. * different 'submodules' inside the IP block. This function will
  66. * take the submodule out of reset and wait until the PRCM indicates
  67. * that the reset has completed before returning. Returns 0 upon success or
  68. * -EINVAL upon an argument error, -EEXIST if the submodule was already out
  69. * of reset, or -EBUSY if the submodule did not exit reset promptly.
  70. */
  71. int omap2_prm_deassert_hardreset(s16 prm_mod, u8 rst_shift, u8 st_shift)
  72. {
  73. u32 rst, st;
  74. int c;
  75. rst = 1 << rst_shift;
  76. st = 1 << st_shift;
  77. /* Check the current status to avoid de-asserting the line twice */
  78. if (omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, rst) == 0)
  79. return -EEXIST;
  80. /* Clear the reset status by writing 1 to the status bit */
  81. omap2_prm_rmw_mod_reg_bits(0xffffffff, st, prm_mod, OMAP2_RM_RSTST);
  82. /* de-assert the reset control line */
  83. omap2_prm_rmw_mod_reg_bits(rst, 0, prm_mod, OMAP2_RM_RSTCTRL);
  84. /* wait the status to be set */
  85. omap_test_timeout(omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTST,
  86. st),
  87. MAX_MODULE_HARDRESET_WAIT, c);
  88. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  89. }
  90. /* Powerdomain low-level functions */
  91. /* Common functions across OMAP2 and OMAP3 */
  92. int omap2_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank,
  93. u8 pwrst)
  94. {
  95. u32 m;
  96. m = omap2_pwrdm_get_mem_bank_onstate_mask(bank);
  97. omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs,
  98. OMAP2_PM_PWSTCTRL);
  99. return 0;
  100. }
  101. int omap2_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank,
  102. u8 pwrst)
  103. {
  104. u32 m;
  105. m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
  106. omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs,
  107. OMAP2_PM_PWSTCTRL);
  108. return 0;
  109. }
  110. int omap2_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
  111. {
  112. u32 m;
  113. m = omap2_pwrdm_get_mem_bank_stst_mask(bank);
  114. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, OMAP2_PM_PWSTST,
  115. m);
  116. }
  117. int omap2_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
  118. {
  119. u32 m;
  120. m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
  121. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  122. OMAP2_PM_PWSTCTRL, m);
  123. }
  124. int omap2_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
  125. {
  126. u32 v;
  127. v = pwrst << __ffs(OMAP_LOGICRETSTATE_MASK);
  128. omap2_prm_rmw_mod_reg_bits(OMAP_LOGICRETSTATE_MASK, v, pwrdm->prcm_offs,
  129. OMAP2_PM_PWSTCTRL);
  130. return 0;
  131. }
  132. int omap2_pwrdm_wait_transition(struct powerdomain *pwrdm)
  133. {
  134. u32 c = 0;
  135. /*
  136. * REVISIT: pwrdm_wait_transition() may be better implemented
  137. * via a callback and a periodic timer check -- how long do we expect
  138. * powerdomain transitions to take?
  139. */
  140. /* XXX Is this udelay() value meaningful? */
  141. while ((omap2_prm_read_mod_reg(pwrdm->prcm_offs, OMAP2_PM_PWSTST) &
  142. OMAP_INTRANSITION_MASK) &&
  143. (c++ < PWRDM_TRANSITION_BAILOUT))
  144. udelay(1);
  145. if (c > PWRDM_TRANSITION_BAILOUT) {
  146. pr_err("powerdomain: %s: waited too long to complete transition\n",
  147. pwrdm->name);
  148. return -EAGAIN;
  149. }
  150. pr_debug("powerdomain: completed transition in %d loops\n", c);
  151. return 0;
  152. }
  153. int omap2_clkdm_add_wkdep(struct clockdomain *clkdm1,
  154. struct clockdomain *clkdm2)
  155. {
  156. omap2_prm_set_mod_reg_bits((1 << clkdm2->dep_bit),
  157. clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP);
  158. return 0;
  159. }
  160. int omap2_clkdm_del_wkdep(struct clockdomain *clkdm1,
  161. struct clockdomain *clkdm2)
  162. {
  163. omap2_prm_clear_mod_reg_bits((1 << clkdm2->dep_bit),
  164. clkdm1->pwrdm.ptr->prcm_offs, PM_WKDEP);
  165. return 0;
  166. }
  167. int omap2_clkdm_read_wkdep(struct clockdomain *clkdm1,
  168. struct clockdomain *clkdm2)
  169. {
  170. return omap2_prm_read_mod_bits_shift(clkdm1->pwrdm.ptr->prcm_offs,
  171. PM_WKDEP, (1 << clkdm2->dep_bit));
  172. }
  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. atomic_set(&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. }