prm33xx.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. #define AM33XX_PRM_RSTCTRL_OFFSET 0x0000
  24. #define AM33XX_RST_GLOBAL_WARM_SW_MASK (1 << 0)
  25. /* Read a register in a PRM instance */
  26. static u32 am33xx_prm_read_reg(s16 inst, u16 idx)
  27. {
  28. return readl_relaxed(prm_base + inst + idx);
  29. }
  30. /* Write into a register in a PRM instance */
  31. static void am33xx_prm_write_reg(u32 val, s16 inst, u16 idx)
  32. {
  33. writel_relaxed(val, prm_base + inst + idx);
  34. }
  35. /* Read-modify-write a register in PRM. Caller must lock */
  36. static u32 am33xx_prm_rmw_reg_bits(u32 mask, u32 bits, s16 inst, s16 idx)
  37. {
  38. u32 v;
  39. v = am33xx_prm_read_reg(inst, idx);
  40. v &= ~mask;
  41. v |= bits;
  42. am33xx_prm_write_reg(v, inst, idx);
  43. return v;
  44. }
  45. /**
  46. * am33xx_prm_is_hardreset_asserted - read the HW reset line state of
  47. * submodules contained in the hwmod module
  48. * @shift: register bit shift corresponding to the reset line to check
  49. * @part: PRM partition, ignored for AM33xx
  50. * @inst: CM instance register offset (*_INST macro)
  51. * @rstctrl_offs: RM_RSTCTRL register address offset for this module
  52. *
  53. * Returns 1 if the (sub)module hardreset line is currently asserted,
  54. * 0 if the (sub)module hardreset line is not currently asserted, or
  55. * -EINVAL upon parameter error.
  56. */
  57. static int am33xx_prm_is_hardreset_asserted(u8 shift, u8 part, s16 inst,
  58. u16 rstctrl_offs)
  59. {
  60. u32 v;
  61. v = am33xx_prm_read_reg(inst, rstctrl_offs);
  62. v &= 1 << shift;
  63. v >>= shift;
  64. return v;
  65. }
  66. /**
  67. * am33xx_prm_assert_hardreset - assert the HW reset line of a submodule
  68. * @shift: register bit shift corresponding to the reset line to assert
  69. * @part: CM partition, ignored for AM33xx
  70. * @inst: CM instance register offset (*_INST macro)
  71. * @rstctrl_reg: RM_RSTCTRL register address for this module
  72. *
  73. * Some IPs like dsp, ipu or iva contain processors that require an HW
  74. * reset line to be asserted / deasserted in order to fully enable the
  75. * IP. These modules may have multiple hard-reset lines that reset
  76. * different 'submodules' inside the IP block. This function will
  77. * place the submodule into reset. Returns 0 upon success or -EINVAL
  78. * upon an argument error.
  79. */
  80. static int am33xx_prm_assert_hardreset(u8 shift, u8 part, s16 inst,
  81. u16 rstctrl_offs)
  82. {
  83. u32 mask = 1 << shift;
  84. am33xx_prm_rmw_reg_bits(mask, mask, inst, rstctrl_offs);
  85. return 0;
  86. }
  87. /**
  88. * am33xx_prm_deassert_hardreset - deassert a submodule hardreset line and
  89. * wait
  90. * @shift: register bit shift corresponding to the reset line to deassert
  91. * @st_shift: reset status register bit shift corresponding to the reset line
  92. * @part: PRM partition, not used for AM33xx
  93. * @inst: CM instance register offset (*_INST macro)
  94. * @rstctrl_reg: RM_RSTCTRL register address for this module
  95. * @rstst_reg: RM_RSTST register address for this module
  96. *
  97. * Some IPs like dsp, ipu or iva contain processors that require an HW
  98. * reset line to be asserted / deasserted in order to fully enable the
  99. * IP. These modules may have multiple hard-reset lines that reset
  100. * different 'submodules' inside the IP block. This function will
  101. * take the submodule out of reset and wait until the PRCM indicates
  102. * that the reset has completed before returning. Returns 0 upon success or
  103. * -EINVAL upon an argument error, -EEXIST if the submodule was already out
  104. * of reset, or -EBUSY if the submodule did not exit reset promptly.
  105. */
  106. static int am33xx_prm_deassert_hardreset(u8 shift, u8 st_shift, u8 part,
  107. s16 inst, u16 rstctrl_offs,
  108. u16 rstst_offs)
  109. {
  110. int c;
  111. u32 mask = 1 << st_shift;
  112. /* Check the current status to avoid de-asserting the line twice */
  113. if (am33xx_prm_is_hardreset_asserted(shift, 0, inst, rstctrl_offs) == 0)
  114. return -EEXIST;
  115. /* Clear the reset status by writing 1 to the status bit */
  116. am33xx_prm_rmw_reg_bits(0xffffffff, mask, inst, rstst_offs);
  117. /* de-assert the reset control line */
  118. mask = 1 << shift;
  119. am33xx_prm_rmw_reg_bits(mask, 0, inst, rstctrl_offs);
  120. /* wait the status to be set */
  121. omap_test_timeout(am33xx_prm_is_hardreset_asserted(st_shift, 0, inst,
  122. rstst_offs),
  123. MAX_MODULE_HARDRESET_WAIT, c);
  124. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  125. }
  126. static int am33xx_pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst)
  127. {
  128. am33xx_prm_rmw_reg_bits(OMAP_POWERSTATE_MASK,
  129. (pwrst << OMAP_POWERSTATE_SHIFT),
  130. pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  131. return 0;
  132. }
  133. static int am33xx_pwrdm_read_next_pwrst(struct powerdomain *pwrdm)
  134. {
  135. u32 v;
  136. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstctrl_offs);
  137. v &= OMAP_POWERSTATE_MASK;
  138. v >>= OMAP_POWERSTATE_SHIFT;
  139. return v;
  140. }
  141. static int am33xx_pwrdm_read_pwrst(struct powerdomain *pwrdm)
  142. {
  143. u32 v;
  144. v = am33xx_prm_read_reg(pwrdm->prcm_offs, pwrdm->pwrstst_offs);
  145. v &= OMAP_POWERSTATEST_MASK;
  146. v >>= OMAP_POWERSTATEST_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. static int am33xx_check_vcvp(void)
  258. {
  259. /* No VC/VP on am33xx devices */
  260. return 0;
  261. }
  262. /**
  263. * am33xx_prm_global_warm_sw_reset - reboot the device via warm reset
  264. *
  265. * Immediately reboots the device through warm reset.
  266. */
  267. static void am33xx_prm_global_warm_sw_reset(void)
  268. {
  269. am33xx_prm_rmw_reg_bits(AM33XX_RST_GLOBAL_WARM_SW_MASK,
  270. AM33XX_RST_GLOBAL_WARM_SW_MASK,
  271. AM33XX_PRM_DEVICE_MOD,
  272. AM33XX_PRM_RSTCTRL_OFFSET);
  273. /* OCP barrier */
  274. (void)am33xx_prm_read_reg(AM33XX_PRM_DEVICE_MOD,
  275. AM33XX_PRM_RSTCTRL_OFFSET);
  276. }
  277. struct pwrdm_ops am33xx_pwrdm_operations = {
  278. .pwrdm_set_next_pwrst = am33xx_pwrdm_set_next_pwrst,
  279. .pwrdm_read_next_pwrst = am33xx_pwrdm_read_next_pwrst,
  280. .pwrdm_read_pwrst = am33xx_pwrdm_read_pwrst,
  281. .pwrdm_set_logic_retst = am33xx_pwrdm_set_logic_retst,
  282. .pwrdm_read_logic_pwrst = am33xx_pwrdm_read_logic_pwrst,
  283. .pwrdm_read_logic_retst = am33xx_pwrdm_read_logic_retst,
  284. .pwrdm_clear_all_prev_pwrst = am33xx_pwrdm_clear_all_prev_pwrst,
  285. .pwrdm_set_lowpwrstchange = am33xx_pwrdm_set_lowpwrstchange,
  286. .pwrdm_read_mem_pwrst = am33xx_pwrdm_read_mem_pwrst,
  287. .pwrdm_read_mem_retst = am33xx_pwrdm_read_mem_retst,
  288. .pwrdm_set_mem_onst = am33xx_pwrdm_set_mem_onst,
  289. .pwrdm_set_mem_retst = am33xx_pwrdm_set_mem_retst,
  290. .pwrdm_wait_transition = am33xx_pwrdm_wait_transition,
  291. .pwrdm_has_voltdm = am33xx_check_vcvp,
  292. };
  293. static struct prm_ll_data am33xx_prm_ll_data = {
  294. .assert_hardreset = am33xx_prm_assert_hardreset,
  295. .deassert_hardreset = am33xx_prm_deassert_hardreset,
  296. .is_hardreset_asserted = am33xx_prm_is_hardreset_asserted,
  297. .reset_system = am33xx_prm_global_warm_sw_reset,
  298. };
  299. int __init am33xx_prm_init(const struct omap_prcm_init_data *data)
  300. {
  301. return prm_register(&am33xx_prm_ll_data);
  302. }
  303. static void __exit am33xx_prm_exit(void)
  304. {
  305. prm_unregister(&am33xx_prm_ll_data);
  306. }
  307. __exitcall(am33xx_prm_exit);