prm33xx.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * AM33XX PRM functions
  3. *
  4. * Copyright (C) 2011-2012 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation version 2.
  9. *
  10. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  11. * kind, whether express or implied; without even the implied warranty
  12. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/types.h>
  17. #include <linux/errno.h>
  18. #include <linux/err.h>
  19. #include <linux/io.h>
  20. #include "common.h"
  21. #include "powerdomain.h"
  22. #include "prm33xx.h"
  23. #include "prm-regbits-33xx.h"
  24. /* Read a register in a PRM instance */
  25. u32 am33xx_prm_read_reg(s16 inst, u16 idx)
  26. {
  27. return __raw_readl(prm_base + inst + idx);
  28. }
  29. /* Write into a register in a PRM instance */
  30. void am33xx_prm_write_reg(u32 val, s16 inst, u16 idx)
  31. {
  32. __raw_writel(val, prm_base + inst + idx);
  33. }
  34. /* Read-modify-write a register in PRM. Caller must lock */
  35. u32 am33xx_prm_rmw_reg_bits(u32 mask, u32 bits, s16 inst, s16 idx)
  36. {
  37. u32 v;
  38. v = am33xx_prm_read_reg(inst, idx);
  39. v &= ~mask;
  40. v |= bits;
  41. am33xx_prm_write_reg(v, inst, idx);
  42. return v;
  43. }
  44. /**
  45. * am33xx_prm_is_hardreset_asserted - read the HW reset line state of
  46. * submodules contained in the hwmod module
  47. * @shift: register bit shift corresponding to the reset line to check
  48. * @inst: CM instance register offset (*_INST macro)
  49. * @rstctrl_offs: RM_RSTCTRL register address offset for this module
  50. *
  51. * Returns 1 if the (sub)module hardreset line is currently asserted,
  52. * 0 if the (sub)module hardreset line is not currently asserted, or
  53. * -EINVAL upon parameter error.
  54. */
  55. int am33xx_prm_is_hardreset_asserted(u8 shift, s16 inst, u16 rstctrl_offs)
  56. {
  57. u32 v;
  58. v = am33xx_prm_read_reg(inst, rstctrl_offs);
  59. v &= 1 << shift;
  60. v >>= shift;
  61. return v;
  62. }
  63. /**
  64. * am33xx_prm_assert_hardreset - assert the HW reset line of a submodule
  65. * @shift: register bit shift corresponding to the reset line to assert
  66. * @inst: CM instance register offset (*_INST macro)
  67. * @rstctrl_reg: RM_RSTCTRL register address for this module
  68. *
  69. * Some IPs like dsp, ipu 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. * place the submodule into reset. Returns 0 upon success or -EINVAL
  74. * upon an argument error.
  75. */
  76. int am33xx_prm_assert_hardreset(u8 shift, s16 inst, u16 rstctrl_offs)
  77. {
  78. u32 mask = 1 << shift;
  79. am33xx_prm_rmw_reg_bits(mask, mask, inst, rstctrl_offs);
  80. return 0;
  81. }
  82. /**
  83. * am33xx_prm_deassert_hardreset - deassert a submodule hardreset line and
  84. * wait
  85. * @shift: register bit shift corresponding to the reset line to deassert
  86. * @inst: CM instance register offset (*_INST macro)
  87. * @rstctrl_reg: RM_RSTCTRL register address for this module
  88. * @rstst_reg: RM_RSTST register address for this module
  89. *
  90. * Some IPs like dsp, ipu or iva contain processors that require an HW
  91. * reset line to be asserted / deasserted in order to fully enable the
  92. * IP. These modules may have multiple hard-reset lines that reset
  93. * different 'submodules' inside the IP block. This function will
  94. * take the submodule out of reset and wait until the PRCM indicates
  95. * that the reset has completed before returning. Returns 0 upon success or
  96. * -EINVAL upon an argument error, -EEXIST if the submodule was already out
  97. * of reset, or -EBUSY if the submodule did not exit reset promptly.
  98. */
  99. int am33xx_prm_deassert_hardreset(u8 shift, s16 inst,
  100. u16 rstctrl_offs, u16 rstst_offs)
  101. {
  102. int c;
  103. u32 mask = 1 << shift;
  104. /* Check the current status to avoid de-asserting the line twice */
  105. if (am33xx_prm_is_hardreset_asserted(shift, inst, rstctrl_offs) == 0)
  106. return -EEXIST;
  107. /* Clear the reset status by writing 1 to the status bit */
  108. am33xx_prm_rmw_reg_bits(0xffffffff, mask, inst, rstst_offs);
  109. /* de-assert the reset control line */
  110. am33xx_prm_rmw_reg_bits(mask, 0, inst, rstctrl_offs);
  111. /* wait the status to be set */
  112. omap_test_timeout(am33xx_prm_is_hardreset_asserted(shift, inst,
  113. rstst_offs),
  114. MAX_MODULE_HARDRESET_WAIT, c);
  115. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  116. }
  117. static int am33xx_pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
  118. {
  119. am33xx_prm_rmw_reg_bits(OMAP_POWERSTATE_MASK,
  120. (pwrst << OMAP_POWERSTATE_SHIFT),
  121. pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  122. return 0;
  123. }
  124. static int am33xx_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
  125. {
  126. u32 v;
  127. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  128. v &= OMAP_POWERSTATE_MASK;
  129. v >>= OMAP_POWERSTATE_SHIFT;
  130. return v;
  131. }
  132. static int am33xx_pwrdm_read_pwrst(struct powerdomain *pwrdm)
  133. {
  134. u32 v;
  135. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
  136. v &= OMAP_POWERSTATEST_MASK;
  137. v >>= OMAP_POWERSTATEST_SHIFT;
  138. return v;
  139. }
  140. static int am33xx_pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
  141. {
  142. u32 v;
  143. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
  144. v &= AM33XX_LASTPOWERSTATEENTERED_MASK;
  145. v >>= AM33XX_LASTPOWERSTATEENTERED_SHIFT;
  146. return v;
  147. }
  148. static int am33xx_pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm)
  149. {
  150. am33xx_prm_rmw_reg_bits(AM33XX_LOWPOWERSTATECHANGE_MASK,
  151. (1 << AM33XX_LOWPOWERSTATECHANGE_SHIFT),
  152. pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  153. return 0;
  154. }
  155. static int am33xx_pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
  156. {
  157. am33xx_prm_rmw_reg_bits(AM33XX_LASTPOWERSTATEENTERED_MASK,
  158. AM33XX_LASTPOWERSTATEENTERED_MASK,
  159. pwrdm->prcm_offs, pwrdm->pwrstst_offs);
  160. return 0;
  161. }
  162. static int am33xx_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
  163. {
  164. u32 m;
  165. m = pwrdm->logicretstate_mask;
  166. if (!m)
  167. return -EINVAL;
  168. am33xx_prm_rmw_reg_bits(m, (pwrst << __ffs(m)),
  169. pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  170. return 0;
  171. }
  172. static int am33xx_pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
  173. {
  174. u32 v;
  175. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
  176. v &= AM33XX_LOGICSTATEST_MASK;
  177. v >>= AM33XX_LOGICSTATEST_SHIFT;
  178. return v;
  179. }
  180. static int am33xx_pwrdm_read_logic_retst(struct powerdomain *pwrdm)
  181. {
  182. u32 v, m;
  183. m = pwrdm->logicretstate_mask;
  184. if (!m)
  185. return -EINVAL;
  186. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  187. v &= m;
  188. v >>= __ffs(m);
  189. return v;
  190. }
  191. static int am33xx_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank,
  192. u8 pwrst)
  193. {
  194. u32 m;
  195. m = pwrdm->mem_on_mask[bank];
  196. if (!m)
  197. return -EINVAL;
  198. am33xx_prm_rmw_reg_bits(m, (pwrst << __ffs(m)),
  199. pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  200. return 0;
  201. }
  202. static int am33xx_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank,
  203. u8 pwrst)
  204. {
  205. u32 m;
  206. m = pwrdm->mem_ret_mask[bank];
  207. if (!m)
  208. return -EINVAL;
  209. am33xx_prm_rmw_reg_bits(m, (pwrst << __ffs(m)),
  210. pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  211. return 0;
  212. }
  213. static int am33xx_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
  214. {
  215. u32 m, v;
  216. m = pwrdm->mem_pwrst_mask[bank];
  217. if (!m)
  218. return -EINVAL;
  219. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
  220. v &= m;
  221. v >>= __ffs(m);
  222. return v;
  223. }
  224. static int am33xx_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
  225. {
  226. u32 m, v;
  227. m = pwrdm->mem_retst_mask[bank];
  228. if (!m)
  229. return -EINVAL;
  230. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  231. v &= m;
  232. v >>= __ffs(m);
  233. return v;
  234. }
  235. static int am33xx_pwrdm_wait_transition(struct powerdomain *pwrdm)
  236. {
  237. u32 c = 0;
  238. /*
  239. * REVISIT: pwrdm_wait_transition() may be better implemented
  240. * via a callback and a periodic timer check -- how long do we expect
  241. * powerdomain transitions to take?
  242. */
  243. /* XXX Is this udelay() value meaningful? */
  244. while ((am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs)
  245. & OMAP_INTRANSITION_MASK) &&
  246. (c++ < PWRDM_TRANSITION_BAILOUT))
  247. udelay(1);
  248. if (c > PWRDM_TRANSITION_BAILOUT) {
  249. pr_err("powerdomain: %s: waited too long to complete transition\n",
  250. pwrdm->name);
  251. return -EAGAIN;
  252. }
  253. pr_debug("powerdomain: completed transition in %d loops\n", c);
  254. return 0;
  255. }
  256. struct pwrdm_ops am33xx_pwrdm_operations = {
  257. .pwrdm_set_next_pwrst = am33xx_pwrdm_set_next_pwrst,
  258. .pwrdm_read_next_pwrst = am33xx_pwrdm_read_next_pwrst,
  259. .pwrdm_read_pwrst = am33xx_pwrdm_read_pwrst,
  260. .pwrdm_read_prev_pwrst = am33xx_pwrdm_read_prev_pwrst,
  261. .pwrdm_set_logic_retst = am33xx_pwrdm_set_logic_retst,
  262. .pwrdm_read_logic_pwrst = am33xx_pwrdm_read_logic_pwrst,
  263. .pwrdm_read_logic_retst = am33xx_pwrdm_read_logic_retst,
  264. .pwrdm_clear_all_prev_pwrst = am33xx_pwrdm_clear_all_prev_pwrst,
  265. .pwrdm_set_lowpwrstchange = am33xx_pwrdm_set_lowpwrstchange,
  266. .pwrdm_read_mem_pwrst = am33xx_pwrdm_read_mem_pwrst,
  267. .pwrdm_read_mem_retst = am33xx_pwrdm_read_mem_retst,
  268. .pwrdm_set_mem_onst = am33xx_pwrdm_set_mem_onst,
  269. .pwrdm_set_mem_retst = am33xx_pwrdm_set_mem_retst,
  270. .pwrdm_wait_transition = am33xx_pwrdm_wait_transition,
  271. };