prm2xxx_3xxx.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * OMAP2/3 PRM module functions
  3. *
  4. * Copyright (C) 2010 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. u32 omap2_prm_read_mod_reg(s16 module, u16 idx)
  26. {
  27. return __raw_readl(prm_base + module + idx);
  28. }
  29. void omap2_prm_write_mod_reg(u32 val, s16 module, u16 idx)
  30. {
  31. __raw_writel(val, prm_base + module + idx);
  32. }
  33. /* Read-modify-write a register in a PRM module. Caller must lock */
  34. u32 omap2_prm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx)
  35. {
  36. u32 v;
  37. v = omap2_prm_read_mod_reg(module, idx);
  38. v &= ~mask;
  39. v |= bits;
  40. omap2_prm_write_mod_reg(v, module, idx);
  41. return v;
  42. }
  43. /* Read a PRM register, AND it, and shift the result down to bit 0 */
  44. u32 omap2_prm_read_mod_bits_shift(s16 domain, s16 idx, u32 mask)
  45. {
  46. u32 v;
  47. v = omap2_prm_read_mod_reg(domain, idx);
  48. v &= mask;
  49. v >>= __ffs(mask);
  50. return v;
  51. }
  52. u32 omap2_prm_set_mod_reg_bits(u32 bits, s16 module, s16 idx)
  53. {
  54. return omap2_prm_rmw_mod_reg_bits(bits, bits, module, idx);
  55. }
  56. u32 omap2_prm_clear_mod_reg_bits(u32 bits, s16 module, s16 idx)
  57. {
  58. return omap2_prm_rmw_mod_reg_bits(bits, 0x0, module, idx);
  59. }
  60. /**
  61. * omap2_prm_is_hardreset_asserted - read the HW reset line state of
  62. * submodules contained in the hwmod module
  63. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  64. * @shift: register bit shift corresponding to the reset line to check
  65. *
  66. * Returns 1 if the (sub)module hardreset line is currently asserted,
  67. * 0 if the (sub)module hardreset line is not currently asserted, or
  68. * -EINVAL if called while running on a non-OMAP2/3 chip.
  69. */
  70. int omap2_prm_is_hardreset_asserted(s16 prm_mod, u8 shift)
  71. {
  72. if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
  73. return -EINVAL;
  74. return omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL,
  75. (1 << shift));
  76. }
  77. /**
  78. * omap2_prm_assert_hardreset - assert the HW reset line of a submodule
  79. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  80. * @shift: register bit shift corresponding to the reset line to assert
  81. *
  82. * Some IPs like dsp or iva contain processors that require an HW
  83. * reset line to be asserted / deasserted in order to fully enable the
  84. * IP. These modules may have multiple hard-reset lines that reset
  85. * different 'submodules' inside the IP block. This function will
  86. * place the submodule into reset. Returns 0 upon success or -EINVAL
  87. * upon an argument error.
  88. */
  89. int omap2_prm_assert_hardreset(s16 prm_mod, u8 shift)
  90. {
  91. u32 mask;
  92. if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
  93. return -EINVAL;
  94. mask = 1 << shift;
  95. omap2_prm_rmw_mod_reg_bits(mask, mask, prm_mod, OMAP2_RM_RSTCTRL);
  96. return 0;
  97. }
  98. /**
  99. * omap2_prm_deassert_hardreset - deassert a submodule hardreset line and wait
  100. * @prm_mod: PRM submodule base (e.g. CORE_MOD)
  101. * @rst_shift: register bit shift corresponding to the reset line to deassert
  102. * @st_shift: register bit shift for the status of the deasserted submodule
  103. *
  104. * Some IPs like dsp or iva contain processors that require an HW
  105. * reset line to be asserted / deasserted in order to fully enable the
  106. * IP. These modules may have multiple hard-reset lines that reset
  107. * different 'submodules' inside the IP block. This function will
  108. * take the submodule out of reset and wait until the PRCM indicates
  109. * that the reset has completed before returning. Returns 0 upon success or
  110. * -EINVAL upon an argument error, -EEXIST if the submodule was already out
  111. * of reset, or -EBUSY if the submodule did not exit reset promptly.
  112. */
  113. int omap2_prm_deassert_hardreset(s16 prm_mod, u8 rst_shift, u8 st_shift)
  114. {
  115. u32 rst, st;
  116. int c;
  117. if (!(cpu_is_omap24xx() || cpu_is_omap34xx()))
  118. return -EINVAL;
  119. rst = 1 << rst_shift;
  120. st = 1 << st_shift;
  121. /* Check the current status to avoid de-asserting the line twice */
  122. if (omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTCTRL, rst) == 0)
  123. return -EEXIST;
  124. /* Clear the reset status by writing 1 to the status bit */
  125. omap2_prm_rmw_mod_reg_bits(0xffffffff, st, prm_mod, OMAP2_RM_RSTST);
  126. /* de-assert the reset control line */
  127. omap2_prm_rmw_mod_reg_bits(rst, 0, prm_mod, OMAP2_RM_RSTCTRL);
  128. /* wait the status to be set */
  129. omap_test_timeout(omap2_prm_read_mod_bits_shift(prm_mod, OMAP2_RM_RSTST,
  130. st),
  131. MAX_MODULE_HARDRESET_WAIT, c);
  132. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  133. }
  134. /* PRM VP */
  135. /*
  136. * struct omap3_vp - OMAP3 VP register access description.
  137. * @tranxdone_status: VP_TRANXDONE_ST bitmask in PRM_IRQSTATUS_MPU reg
  138. */
  139. struct omap3_vp {
  140. u32 tranxdone_status;
  141. };
  142. static struct omap3_vp omap3_vp[] = {
  143. [OMAP3_VP_VDD_MPU_ID] = {
  144. .tranxdone_status = OMAP3430_VP1_TRANXDONE_ST_MASK,
  145. },
  146. [OMAP3_VP_VDD_CORE_ID] = {
  147. .tranxdone_status = OMAP3430_VP2_TRANXDONE_ST_MASK,
  148. },
  149. };
  150. #define MAX_VP_ID ARRAY_SIZE(omap3_vp);
  151. u32 omap3_prm_vp_check_txdone(u8 vp_id)
  152. {
  153. struct omap3_vp *vp = &omap3_vp[vp_id];
  154. u32 irqstatus;
  155. irqstatus = omap2_prm_read_mod_reg(OCP_MOD,
  156. OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  157. return irqstatus & vp->tranxdone_status;
  158. }
  159. void omap3_prm_vp_clear_txdone(u8 vp_id)
  160. {
  161. struct omap3_vp *vp = &omap3_vp[vp_id];
  162. omap2_prm_write_mod_reg(vp->tranxdone_status,
  163. OCP_MOD, OMAP3_PRM_IRQSTATUS_MPU_OFFSET);
  164. }
  165. u32 omap3_prm_vcvp_read(u8 offset)
  166. {
  167. return omap2_prm_read_mod_reg(OMAP3430_GR_MOD, offset);
  168. }
  169. void omap3_prm_vcvp_write(u32 val, u8 offset)
  170. {
  171. omap2_prm_write_mod_reg(val, OMAP3430_GR_MOD, offset);
  172. }
  173. u32 omap3_prm_vcvp_rmw(u32 mask, u32 bits, u8 offset)
  174. {
  175. return omap2_prm_rmw_mod_reg_bits(mask, bits, OMAP3430_GR_MOD, offset);
  176. }