prm33xx.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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, u8 st_shift, s16 inst,
  100. u16 rstctrl_offs, u16 rstst_offs)
  101. {
  102. int c;
  103. u32 mask = 1 << st_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. mask = 1 << shift;
  111. am33xx_prm_rmw_reg_bits(mask, 0, inst, rstctrl_offs);
  112. /* wait the status to be set */
  113. omap_test_timeout(am33xx_prm_is_hardreset_asserted(st_shift, inst,
  114. rstst_offs),
  115. MAX_MODULE_HARDRESET_WAIT, c);
  116. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  117. }
  118. static int am33xx_pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
  119. {
  120. am33xx_prm_rmw_reg_bits(OMAP_POWERSTATE_MASK,
  121. (pwrst << OMAP_POWERSTATE_SHIFT),
  122. pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  123. return 0;
  124. }
  125. static int am33xx_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
  126. {
  127. u32 v;
  128. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  129. v &= OMAP_POWERSTATE_MASK;
  130. v >>= OMAP_POWERSTATE_SHIFT;
  131. return v;
  132. }
  133. static int am33xx_pwrdm_read_pwrst(struct powerdomain *pwrdm)
  134. {
  135. u32 v;
  136. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
  137. v &= OMAP_POWERSTATEST_MASK;
  138. v >>= OMAP_POWERSTATEST_SHIFT;
  139. return v;
  140. }
  141. static int am33xx_pwrdm_read_prev_pwrst(struct powerdomain *pwrdm)
  142. {
  143. u32 v;
  144. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
  145. v &= AM33XX_LASTPOWERSTATEENTERED_MASK;
  146. v >>= AM33XX_LASTPOWERSTATEENTERED_SHIFT;
  147. return v;
  148. }
  149. static int am33xx_pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm)
  150. {
  151. am33xx_prm_rmw_reg_bits(AM33XX_LOWPOWERSTATECHANGE_MASK,
  152. (1 << AM33XX_LOWPOWERSTATECHANGE_SHIFT),
  153. pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  154. return 0;
  155. }
  156. static int am33xx_pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm)
  157. {
  158. am33xx_prm_rmw_reg_bits(AM33XX_LASTPOWERSTATEENTERED_MASK,
  159. AM33XX_LASTPOWERSTATEENTERED_MASK,
  160. pwrdm->prcm_offs, pwrdm->pwrstst_offs);
  161. return 0;
  162. }
  163. static int am33xx_pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst)
  164. {
  165. u32 m;
  166. m = pwrdm->logicretstate_mask;
  167. if (!m)
  168. return -EINVAL;
  169. am33xx_prm_rmw_reg_bits(m, (pwrst << __ffs(m)),
  170. pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  171. return 0;
  172. }
  173. static int am33xx_pwrdm_read_logic_pwrst(struct powerdomain *pwrdm)
  174. {
  175. u32 v;
  176. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
  177. v &= AM33XX_LOGICSTATEST_MASK;
  178. v >>= AM33XX_LOGICSTATEST_SHIFT;
  179. return v;
  180. }
  181. static int am33xx_pwrdm_read_logic_retst(struct powerdomain *pwrdm)
  182. {
  183. u32 v, m;
  184. m = pwrdm->logicretstate_mask;
  185. if (!m)
  186. return -EINVAL;
  187. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  188. v &= m;
  189. v >>= __ffs(m);
  190. return v;
  191. }
  192. static int am33xx_pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank,
  193. u8 pwrst)
  194. {
  195. u32 m;
  196. m = pwrdm->mem_on_mask[bank];
  197. if (!m)
  198. return -EINVAL;
  199. am33xx_prm_rmw_reg_bits(m, (pwrst << __ffs(m)),
  200. pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  201. return 0;
  202. }
  203. static int am33xx_pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank,
  204. u8 pwrst)
  205. {
  206. u32 m;
  207. m = pwrdm->mem_ret_mask[bank];
  208. if (!m)
  209. return -EINVAL;
  210. am33xx_prm_rmw_reg_bits(m, (pwrst << __ffs(m)),
  211. pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  212. return 0;
  213. }
  214. static int am33xx_pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank)
  215. {
  216. u32 m, v;
  217. m = pwrdm->mem_pwrst_mask[bank];
  218. if (!m)
  219. return -EINVAL;
  220. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
  221. v &= m;
  222. v >>= __ffs(m);
  223. return v;
  224. }
  225. static int am33xx_pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank)
  226. {
  227. u32 m, v;
  228. m = pwrdm->mem_retst_mask[bank];
  229. if (!m)
  230. return -EINVAL;
  231. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  232. v &= m;
  233. v >>= __ffs(m);
  234. return v;
  235. }
  236. static int am33xx_pwrdm_wait_transition(struct powerdomain *pwrdm)
  237. {
  238. u32 c = 0;
  239. /*
  240. * REVISIT: pwrdm_wait_transition() may be better implemented
  241. * via a callback and a periodic timer check -- how long do we expect
  242. * powerdomain transitions to take?
  243. */
  244. /* XXX Is this udelay() value meaningful? */
  245. while ((am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs)
  246. & OMAP_INTRANSITION_MASK) &&
  247. (c++ < PWRDM_TRANSITION_BAILOUT))
  248. udelay(1);
  249. if (c > PWRDM_TRANSITION_BAILOUT) {
  250. pr_err("powerdomain: %s: waited too long to complete transition\n",
  251. pwrdm->name);
  252. return -EAGAIN;
  253. }
  254. pr_debug("powerdomain: completed transition in %d loops\n", c);
  255. return 0;
  256. }
  257. struct pwrdm_ops am33xx_pwrdm_operations = {
  258. .pwrdm_set_next_pwrst = am33xx_pwrdm_set_next_pwrst,
  259. .pwrdm_read_next_pwrst = am33xx_pwrdm_read_next_pwrst,
  260. .pwrdm_read_pwrst = am33xx_pwrdm_read_pwrst,
  261. .pwrdm_read_prev_pwrst = am33xx_pwrdm_read_prev_pwrst,
  262. .pwrdm_set_logic_retst = am33xx_pwrdm_set_logic_retst,
  263. .pwrdm_read_logic_pwrst = am33xx_pwrdm_read_logic_pwrst,
  264. .pwrdm_read_logic_retst = am33xx_pwrdm_read_logic_retst,
  265. .pwrdm_clear_all_prev_pwrst = am33xx_pwrdm_clear_all_prev_pwrst,
  266. .pwrdm_set_lowpwrstchange = am33xx_pwrdm_set_lowpwrstchange,
  267. .pwrdm_read_mem_pwrst = am33xx_pwrdm_read_mem_pwrst,
  268. .pwrdm_read_mem_retst = am33xx_pwrdm_read_mem_retst,
  269. .pwrdm_set_mem_onst = am33xx_pwrdm_set_mem_onst,
  270. .pwrdm_set_mem_retst = am33xx_pwrdm_set_mem_retst,
  271. .pwrdm_wait_transition = am33xx_pwrdm_wait_transition,
  272. };