prm2xxx_3xxx.c 9.0 KB

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