prm2xxx_3xxx.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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 <plat/cpu.h>
  19. #include <plat/prcm.h>
  20. #include "vp.h"
  21. #include "prm2xxx_3xxx.h"
  22. #include "cm2xxx_3xxx.h"
  23. #include "prm-regbits-24xx.h"
  24. #include "prm-regbits-34xx.h"
  25. static const struct omap_prcm_irq omap3_prcm_irqs[] = {
  26. OMAP_PRCM_IRQ("wkup", 0, 0),
  27. OMAP_PRCM_IRQ("io", 9, 1),
  28. };
  29. static struct omap_prcm_irq_setup omap3_prcm_irq_setup = {
  30. .ack = OMAP3_PRM_IRQSTATUS_MPU_OFFSET,
  31. .mask = OMAP3_PRM_IRQENABLE_MPU_OFFSET,
  32. .nr_regs = 1,
  33. .irqs = omap3_prcm_irqs,
  34. .nr_irqs = ARRAY_SIZE(omap3_prcm_irqs),
  35. .irq = INT_34XX_PRCM_MPU_IRQ,
  36. .read_pending_irqs = &omap3xxx_prm_read_pending_irqs,
  37. .ocp_barrier = &omap3xxx_prm_ocp_barrier,
  38. .save_and_clear_irqen = &omap3xxx_prm_save_and_clear_irqen,
  39. .restore_irqen = &omap3xxx_prm_restore_irqen,
  40. };
  41. u32 omap2_prm_read_mod_reg(s16 module, u16 idx)
  42. {
  43. return __raw_readl(prm_base + module + idx);
  44. }
  45. void omap2_prm_write_mod_reg(u32 val, s16 module, u16 idx)
  46. {
  47. __raw_writel(val, prm_base + module + idx);
  48. }
  49. /* Read-modify-write a register in a PRM module. Caller must lock */
  50. u32 omap2_prm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx)
  51. {
  52. u32 v;
  53. v = omap2_prm_read_mod_reg(module, idx);
  54. v &= ~mask;
  55. v |= bits;
  56. omap2_prm_write_mod_reg(v, module, idx);
  57. return v;
  58. }
  59. /* Read a PRM register, AND it, and shift the result down to bit 0 */
  60. u32 omap2_prm_read_mod_bits_shift(s16 domain, s16 idx, u32 mask)
  61. {
  62. u32 v;
  63. v = omap2_prm_read_mod_reg(domain, idx);
  64. v &= mask;
  65. v >>= __ffs(mask);
  66. return v;
  67. }
  68. u32 omap2_prm_set_mod_reg_bits(u32 bits, s16 module, s16 idx)
  69. {
  70. return omap2_prm_rmw_mod_reg_bits(bits, bits, module, idx);
  71. }
  72. u32 omap2_prm_clear_mod_reg_bits(u32 bits, s16 module, s16 idx)
  73. {
  74. return omap2_prm_rmw_mod_reg_bits(bits, 0x0, module, idx);
  75. }
  76. /**
  77. * omap2_prm_is_hardreset_asserted - read the HW reset line state of
  78. * submodules contained in the hwmod module
  79. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  80. * @shift: register bit shift corresponding to the reset line to check
  81. *
  82. * Returns 1 if the (sub)module hardreset line is currently asserted,
  83. * 0 if the (sub)module hardreset line is not currently asserted, or
  84. * -EINVAL if called while running on a non-OMAP2/3 chip.
  85. */
  86. int omap2_prm_is_hardreset_asserted(s16 prm_mod, u8 shift)
  87. {
  88. if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
  89. return -EINVAL;
  90. return omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL,
  91. (1 << shift));
  92. }
  93. /**
  94. * omap2_prm_assert_hardreset - assert the HW reset line of a submodule
  95. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  96. * @shift: register bit shift corresponding to the reset line to assert
  97. *
  98. * Some IPs like dsp or iva contain processors that require an HW
  99. * reset line to be asserted / deasserted in order to fully enable the
  100. * IP. These modules may have multiple hard-reset lines that reset
  101. * different 'submodules' inside the IP block. This function will
  102. * place the submodule into reset. Returns 0 upon success or -EINVAL
  103. * upon an argument error.
  104. */
  105. int omap2_prm_assert_hardreset(s16 prm_mod, u8 shift)
  106. {
  107. u32 mask;
  108. if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
  109. return -EINVAL;
  110. mask = 1 << shift;
  111. omap2_prm_rmw_mod_reg_bits(mask, mask, prm_mod, OMAP2_RM_RSTCTRL);
  112. return 0;
  113. }
  114. /**
  115. * omap2_prm_deassert_hardreset - deassert a submodule hardreset line and wait
  116. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  117. * @rst_shift: register bit shift corresponding to the reset line to deassert
  118. * @st_shift: register bit shift for the status of the deasserted submodule
  119. *
  120. * Some IPs like dsp or iva contain processors that require an HW
  121. * reset line to be asserted / deasserted in order to fully enable the
  122. * IP. These modules may have multiple hard-reset lines that reset
  123. * different 'submodules' inside the IP block. This function will
  124. * take the submodule out of reset and wait until the PRCM indicates
  125. * that the reset has completed before returning. Returns 0 upon success or
  126. * -EINVAL upon an argument error, -EEXIST if the submodule was already out
  127. * of reset, or -EBUSY if the submodule did not exit reset promptly.
  128. */
  129. int omap2_prm_deassert_hardreset(s16 prm_mod, u8 rst_shift, u8 st_shift)
  130. {
  131. u32 rst, st;
  132. int c;
  133. if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
  134. return -EINVAL;
  135. rst = 1 << rst_shift;
  136. st = 1 << st_shift;
  137. /* Check the current status to avoid de-asserting the line twice */
  138. if (omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, rst) == 0)
  139. return -EEXIST;
  140. /* Clear the reset status by writing 1 to the status bit */
  141. omap2_prm_rmw_mod_reg_bits(0xffffffff, st, prm_mod, OMAP2_RM_RSTST);
  142. /* de-assert the reset control line */
  143. omap2_prm_rmw_mod_reg_bits(rst, 0, prm_mod, OMAP2_RM_RSTCTRL);
  144. /* wait the status to be set */
  145. omap_test_timeout(omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTST,
  146. st),
  147. MAX_MODULE_HARDRESET_WAIT, c);
  148. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  149. }
  150. /* PRM VP */
  151. /*
  152. * struct omap3_vp - OMAP3 VP register access description.
  153. * @tranxdone_status: VP_TRANXDONE_ST bitmask in PRM_IRQSTATUS_MPU reg
  154. */
  155. struct omap3_vp {
  156. u32 tranxdone_status;
  157. };
  158. static struct omap3_vp omap3_vp[] = {
  159. [OMAP3_VP_VDD_MPU_ID] = {
  160. .tranxdone_status = OMAP3430_VP1_TRANXDONE_ST_MASK,
  161. },
  162. [OMAP3_VP_VDD_CORE_ID] = {
  163. .tranxdone_status = OMAP3430_VP2_TRANXDONE_ST_MASK,
  164. },
  165. };
  166. #define MAX_VP_ID ARRAY_SIZE(omap3_vp);
  167. u32 omap3_prm_vp_check_txdone(u8 vp_id)
  168. {
  169. struct omap3_vp *vp = &omap3_vp[vp_id];
  170. u32 irqstatus;
  171. irqstatus = omap2_prm_read_mod_reg(OCP_MOD,
  172. OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  173. return irqstatus & vp->tranxdone_status;
  174. }
  175. void omap3_prm_vp_clear_txdone(u8 vp_id)
  176. {
  177. struct omap3_vp *vp = &omap3_vp[vp_id];
  178. omap2_prm_write_mod_reg(vp->tranxdone_status,
  179. OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  180. }
  181. u32 omap3_prm_vcvp_read(u8 offset)
  182. {
  183. return omap2_prm_read_mod_reg(OMAP3430_GR_MOD, offset);
  184. }
  185. void omap3_prm_vcvp_write(u32 val, u8 offset)
  186. {
  187. omap2_prm_write_mod_reg(val, OMAP3430_GR_MOD, offset);
  188. }
  189. u32 omap3_prm_vcvp_rmw(u32 mask, u32 bits, u8 offset)
  190. {
  191. return omap2_prm_rmw_mod_reg_bits(mask, bits, OMAP3430_GR_MOD, offset);
  192. }
  193. /**
  194. * omap3xxx_prm_read_pending_irqs - read pending PRM MPU IRQs into @events
  195. * @events: ptr to a u32, preallocated by caller
  196. *
  197. * Read PRM_IRQSTATUS_MPU bits, AND'ed with the currently-enabled PRM
  198. * MPU IRQs, and store the result into the u32 pointed to by @events.
  199. * No return value.
  200. */
  201. void omap3xxx_prm_read_pending_irqs(unsigned long *events)
  202. {
  203. u32 mask, st;
  204. /* XXX Can the mask read be avoided (e.g., can it come from RAM?) */
  205. mask = omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
  206. st = omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  207. events[0] = mask & st;
  208. }
  209. /**
  210. * omap3xxx_prm_ocp_barrier - force buffered MPU writes to the PRM to complete
  211. *
  212. * Force any buffered writes to the PRM IP block to complete. Needed
  213. * by the PRM IRQ handler, which reads and writes directly to the IP
  214. * block, to avoid race conditions after acknowledging or clearing IRQ
  215. * bits. No return value.
  216. */
  217. void omap3xxx_prm_ocp_barrier(void)
  218. {
  219. omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_REVISION_OFFSET);
  220. }
  221. /**
  222. * omap3xxx_prm_save_and_clear_irqen - save/clear PRM_IRQENABLE_MPU reg
  223. * @saved_mask: ptr to a u32 array to save IRQENABLE bits
  224. *
  225. * Save the PRM_IRQENABLE_MPU register to @saved_mask. @saved_mask
  226. * must be allocated by the caller. Intended to be used in the PRM
  227. * interrupt handler suspend callback. The OCP barrier is needed to
  228. * ensure the write to disable PRM interrupts reaches the PRM before
  229. * returning; otherwise, spurious interrupts might occur. No return
  230. * value.
  231. */
  232. void omap3xxx_prm_save_and_clear_irqen(u32 *saved_mask)
  233. {
  234. saved_mask[0] = omap2_prm_read_mod_reg(OCP_MOD,
  235. OMAP3_PRM_IRQENABLE_MPU_OFFSET);
  236. omap2_prm_write_mod_reg(0, OCP_MOD, OMAP3_PRM_IRQENABLE_MPU_OFFSET);
  237. /* OCP barrier */
  238. omap2_prm_read_mod_reg(OCP_MOD, OMAP3_PRM_REVISION_OFFSET);
  239. }
  240. /**
  241. * omap3xxx_prm_restore_irqen - set PRM_IRQENABLE_MPU register from args
  242. * @saved_mask: ptr to a u32 array of IRQENABLE bits saved previously
  243. *
  244. * Restore the PRM_IRQENABLE_MPU register from @saved_mask. Intended
  245. * to be used in the PRM interrupt handler resume callback to restore
  246. * values saved by omap3xxx_prm_save_and_clear_irqen(). No OCP
  247. * barrier should be needed here; any pending PRM interrupts will fire
  248. * once the writes reach the PRM. No return value.
  249. */
  250. void omap3xxx_prm_restore_irqen(u32 *saved_mask)
  251. {
  252. omap2_prm_write_mod_reg(saved_mask[0], OCP_MOD,
  253. OMAP3_PRM_IRQENABLE_MPU_OFFSET);
  254. }
  255. static int __init omap3xxx_prcm_init(void)
  256. {
  257. if (cpu_is_omap34xx())
  258. return omap_prcm_register_chain_handler(&omap3_prcm_irq_setup);
  259. return 0;
  260. }
  261. subsys_initcall(omap3xxx_prcm_init);