prm2xxx_3xxx.c 6.9 KB

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