prm2xxx_3xxx.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. /**
  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_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
  92. {
  93. omap2_prm_rmw_mod_reg_bits(OMAP_POWERSTATE_MASK,
  94. (pwrst << OMAP_POWERSTATE_SHIFT),
  95. pwrdm->prcm_offs, OMAP2_PM_PWSTCTRL);
  96. return 0;
  97. }
  98. int omap2_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
  99. {
  100. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  101. OMAP2_PM_PWSTCTRL,
  102. OMAP_POWERSTATE_MASK);
  103. }
  104. int omap2_pwrdm_read_pwrst(struct powerdomain *pwrdm)
  105. {
  106. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  107. OMAP2_PM_PWSTST,
  108. OMAP_POWERSTATEST_MASK);
  109. }
  110. int omap2_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank,
  111. u8 pwrst)
  112. {
  113. u32 m;
  114. m = omap2_pwrdm_get_mem_bank_onstate_mask(bank);
  115. omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs,
  116. OMAP2_PM_PWSTCTRL);
  117. return 0;
  118. }
  119. int omap2_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank,
  120. u8 pwrst)
  121. {
  122. u32 m;
  123. m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
  124. omap2_prm_rmw_mod_reg_bits(m, (pwrst << __ffs(m)), pwrdm->prcm_offs,
  125. OMAP2_PM_PWSTCTRL);
  126. return 0;
  127. }
  128. int omap2_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
  129. {
  130. u32 m;
  131. m = omap2_pwrdm_get_mem_bank_stst_mask(bank);
  132. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs, OMAP2_PM_PWSTST,
  133. m);
  134. }
  135. int omap2_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
  136. {
  137. u32 m;
  138. m = omap2_pwrdm_get_mem_bank_retst_mask(bank);
  139. return omap2_prm_read_mod_bits_shift(pwrdm->prcm_offs,
  140. OMAP2_PM_PWSTCTRL, m);
  141. }
  142. int omap2_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
  143. {
  144. u32 v;
  145. v = pwrst << __ffs(OMAP_LOGICRETSTATE_MASK);
  146. omap2_prm_rmw_mod_reg_bits(OMAP_LOGICRETSTATE_MASK, v, pwrdm->prcm_offs,
  147. OMAP2_PM_PWSTCTRL);
  148. return 0;
  149. }
  150. int omap2_pwrdm_wait_transition(struct powerdomain *pwrdm)
  151. {
  152. u32 c = 0;
  153. /*
  154. * REVISIT: pwrdm_wait_transition() may be better implemented
  155. * via a callback and a periodic timer check -- how long do we expect
  156. * powerdomain transitions to take?
  157. */
  158. /* XXX Is this udelay() value meaningful? */
  159. while ((omap2_prm_read_mod_reg(pwrdm->prcm_offs, OMAP2_PM_PWSTST) &
  160. OMAP_INTRANSITION_MASK) &&
  161. (c++ < PWRDM_TRANSITION_BAILOUT))
  162. udelay(1);
  163. if (c > PWRDM_TRANSITION_BAILOUT) {
  164. pr_err("powerdomain: %s: waited too long to complete transition\n",
  165. pwrdm->name);
  166. return -EAGAIN;
  167. }
  168. pr_debug("powerdomain: completed transition in %d loops\n", c);
  169. return 0;
  170. }