prm33xx.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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 "powerdomain.h"
  21. #include "prm33xx.h"
  22. #include "prm-regbits-33xx.h"
  23. /* Read a register in a PRM instance */
  24. u32 am33xx_prm_read_reg(s16 inst, u16 idx)
  25. {
  26. return readl_relaxed(prm_base + inst + idx);
  27. }
  28. /* Write into a register in a PRM instance */
  29. void am33xx_prm_write_reg(u32 val, s16 inst, u16 idx)
  30. {
  31. writel_relaxed(val, prm_base + inst + idx);
  32. }
  33. /* Read-modify-write a register in PRM. Caller must lock */
  34. u32 am33xx_prm_rmw_reg_bits(u32 mask, u32 bits, s16 inst, s16 idx)
  35. {
  36. u32 v;
  37. v = am33xx_prm_read_reg(inst, idx);
  38. v &= ~mask;
  39. v |= bits;
  40. am33xx_prm_write_reg(v, inst, idx);
  41. return v;
  42. }
  43. /**
  44. * am33xx_prm_is_hardreset_asserted - read the HW reset line state of
  45. * submodules contained in the hwmod module
  46. * @shift: register bit shift corresponding to the reset line to check
  47. * @inst: CM instance register offset (*_INST macro)
  48. * @rstctrl_offs: RM_RSTCTRL register address offset for this module
  49. *
  50. * Returns 1 if the (sub)module hardreset line is currently asserted,
  51. * 0 if the (sub)module hardreset line is not currently asserted, or
  52. * -EINVAL upon parameter error.
  53. */
  54. int am33xx_prm_is_hardreset_asserted(u8 shift, s16 inst, u16 rstctrl_offs)
  55. {
  56. u32 v;
  57. v = am33xx_prm_read_reg(inst, rstctrl_offs);
  58. v &= 1 << shift;
  59. v >>= shift;
  60. return v;
  61. }
  62. /**
  63. * am33xx_prm_assert_hardreset - assert the HW reset line of a submodule
  64. * @shift: register bit shift corresponding to the reset line to assert
  65. * @inst: CM instance register offset (*_INST macro)
  66. * @rstctrl_reg: RM_RSTCTRL register address for this module
  67. *
  68. * Some IPs like dsp, ipu or iva contain processors that require an HW
  69. * reset line to be asserted / deasserted in order to fully enable the
  70. * IP. These modules may have multiple hard-reset lines that reset
  71. * different 'submodules' inside the IP block. This function will
  72. * place the submodule into reset. Returns 0 upon success or -EINVAL
  73. * upon an argument error.
  74. */
  75. int am33xx_prm_assert_hardreset(u8 shift, s16 inst, u16 rstctrl_offs)
  76. {
  77. u32 mask = 1 << shift;
  78. am33xx_prm_rmw_reg_bits(mask, mask, inst, rstctrl_offs);
  79. return 0;
  80. }
  81. /**
  82. * am33xx_prm_deassert_hardreset - deassert a submodule hardreset line and
  83. * wait
  84. * @shift: register bit shift corresponding to the reset line to deassert
  85. * @inst: CM instance register offset (*_INST macro)
  86. * @rstctrl_reg: RM_RSTCTRL register address for this module
  87. * @rstst_reg: RM_RSTST register address for this module
  88. *
  89. * Some IPs like dsp, ipu or iva contain processors that require an HW
  90. * reset line to be asserted / deasserted in order to fully enable the
  91. * IP. These modules may have multiple hard-reset lines that reset
  92. * different 'submodules' inside the IP block. This function will
  93. * take the submodule out of reset and wait until the PRCM indicates
  94. * that the reset has completed before returning. Returns 0 upon success or
  95. * -EINVAL upon an argument error, -EEXIST if the submodule was already out
  96. * of reset, or -EBUSY if the submodule did not exit reset promptly.
  97. */
  98. int am33xx_prm_deassert_hardreset(u8 shift, u8 st_shift, s16 inst,
  99. u16 rstctrl_offs, u16 rstst_offs)
  100. {
  101. int c;
  102. u32 mask = 1 << st_shift;
  103. /* Check the current status to avoid de-asserting the line twice */
  104. if (am33xx_prm_is_hardreset_asserted(shift, inst, rstctrl_offs) == 0)
  105. return -EEXIST;
  106. /* Clear the reset status by writing 1 to the status bit */
  107. am33xx_prm_rmw_reg_bits(0xffffffff, mask, inst, rstst_offs);
  108. /* de-assert the reset control line */
  109. mask = 1 << shift;
  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(st_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. static int am33xx_check_vcvp(void)
  257. {
  258. /* No VC/VP on am33xx devices */
  259. return 0;
  260. }
  261. struct pwrdm_ops am33xx_pwrdm_operations = {
  262. .pwrdm_set_next_pwrst = am33xx_pwrdm_set_next_pwrst,
  263. .pwrdm_read_next_pwrst = am33xx_pwrdm_read_next_pwrst,
  264. .pwrdm_read_pwrst = am33xx_pwrdm_read_pwrst,
  265. .pwrdm_read_prev_pwrst = am33xx_pwrdm_read_prev_pwrst,
  266. .pwrdm_set_logic_retst = am33xx_pwrdm_set_logic_retst,
  267. .pwrdm_read_logic_pwrst = am33xx_pwrdm_read_logic_pwrst,
  268. .pwrdm_read_logic_retst = am33xx_pwrdm_read_logic_retst,
  269. .pwrdm_clear_all_prev_pwrst = am33xx_pwrdm_clear_all_prev_pwrst,
  270. .pwrdm_set_lowpwrstchange = am33xx_pwrdm_set_lowpwrstchange,
  271. .pwrdm_read_mem_pwrst = am33xx_pwrdm_read_mem_pwrst,
  272. .pwrdm_read_mem_retst = am33xx_pwrdm_read_mem_retst,
  273. .pwrdm_set_mem_onst = am33xx_pwrdm_set_mem_onst,
  274. .pwrdm_set_mem_retst = am33xx_pwrdm_set_mem_retst,
  275. .pwrdm_wait_transition = am33xx_pwrdm_wait_transition,
  276. .pwrdm_has_voltdm = am33xx_check_vcvp,
  277. };