prm2xxx_3xxx.c 9.2 KB

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