prm44xx.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * OMAP4 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/delay.h>
  15. #include <linux/errno.h>
  16. #include <linux/err.h>
  17. #include <linux/io.h>
  18. #include <plat/common.h>
  19. #include <plat/cpu.h>
  20. #include <plat/prcm.h>
  21. #include "prm44xx.h"
  22. #include "prm-regbits-44xx.h"
  23. /*
  24. * Address offset (in bytes) between the reset control and the reset
  25. * status registers: 4 bytes on OMAP4
  26. */
  27. #define OMAP4_RST_CTRL_ST_OFFSET 4
  28. /* PRM low-level functions */
  29. /* Read a register in a CM/PRM instance in the PRM module */
  30. u32 omap4_prm_read_inst_reg(s16 inst, u16 reg)
  31. {
  32. return __raw_readl(OMAP44XX_PRM_REGADDR(inst, reg));
  33. }
  34. /* Write into a register in a CM/PRM instance in the PRM module */
  35. void omap4_prm_write_inst_reg(u32 val, s16 inst, u16 reg)
  36. {
  37. __raw_writel(val, OMAP44XX_PRM_REGADDR(inst, reg));
  38. }
  39. /* Read-modify-write a register in a PRM module. Caller must lock */
  40. u32 omap4_prm_rmw_inst_reg_bits(u32 mask, u32 bits, s16 inst, s16 reg)
  41. {
  42. u32 v;
  43. v = omap4_prm_read_inst_reg(inst, reg);
  44. v &= ~mask;
  45. v |= bits;
  46. omap4_prm_write_inst_reg(v, inst, reg);
  47. return v;
  48. }
  49. /* Read a PRM register, AND it, and shift the result down to bit 0 */
  50. /* XXX deprecated */
  51. u32 omap4_prm_read_bits_shift(void __iomem *reg, u32 mask)
  52. {
  53. u32 v;
  54. v = __raw_readl(reg);
  55. v &= mask;
  56. v >>= __ffs(mask);
  57. return v;
  58. }
  59. /* Read-modify-write a register in a PRM module. Caller must lock */
  60. /* XXX deprecated */
  61. u32 omap4_prm_rmw_reg_bits(u32 mask, u32 bits, void __iomem *reg)
  62. {
  63. u32 v;
  64. v = __raw_readl(reg);
  65. v &= ~mask;
  66. v |= bits;
  67. __raw_writel(v, reg);
  68. return v;
  69. }
  70. u32 omap4_prm_set_inst_reg_bits(u32 bits, s16 inst, s16 reg)
  71. {
  72. return omap4_prm_rmw_inst_reg_bits(bits, bits, inst, reg);
  73. }
  74. u32 omap4_prm_clear_inst_reg_bits(u32 bits, s16 inst, s16 reg)
  75. {
  76. return omap4_prm_rmw_inst_reg_bits(bits, 0x0, inst, reg);
  77. }
  78. /**
  79. * omap4_prm_is_hardreset_asserted - read the HW reset line state of
  80. * submodules contained in the hwmod module
  81. * @rstctrl_reg: RM_RSTCTRL register address for this module
  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 upon parameter error.
  87. */
  88. int omap4_prm_is_hardreset_asserted(void __iomem *rstctrl_reg, u8 shift)
  89. {
  90. if (!cpu_is_omap44xx() || !rstctrl_reg)
  91. return -EINVAL;
  92. return omap4_prm_read_bits_shift(rstctrl_reg, (1 << shift));
  93. }
  94. /**
  95. * omap4_prm_assert_hardreset - assert the HW reset line of a submodule
  96. * @rstctrl_reg: RM_RSTCTRL register address for this module
  97. * @shift: register bit shift corresponding to the reset line to assert
  98. *
  99. * Some IPs like dsp, ipu 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 omap4_prm_assert_hardreset(void __iomem *rstctrl_reg, u8 shift)
  107. {
  108. u32 mask;
  109. if (!cpu_is_omap44xx() || !rstctrl_reg)
  110. return -EINVAL;
  111. mask = 1 << shift;
  112. omap4_prm_rmw_reg_bits(mask, mask, rstctrl_reg);
  113. return 0;
  114. }
  115. /**
  116. * omap4_prm_deassert_hardreset - deassert a submodule hardreset line and wait
  117. * @rstctrl_reg: RM_RSTCTRL register address for this module
  118. * @shift: register bit shift corresponding to the reset line to deassert
  119. *
  120. * Some IPs like dsp, ipu 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 omap4_prm_deassert_hardreset(void __iomem *rstctrl_reg, u8 shift)
  130. {
  131. u32 mask;
  132. void __iomem *rstst_reg;
  133. int c;
  134. if (!cpu_is_omap44xx() || !rstctrl_reg)
  135. return -EINVAL;
  136. rstst_reg = rstctrl_reg + OMAP4_RST_CTRL_ST_OFFSET;
  137. mask = 1 << shift;
  138. /* Check the current status to avoid de-asserting the line twice */
  139. if (omap4_prm_read_bits_shift(rstctrl_reg, mask) == 0)
  140. return -EEXIST;
  141. /* Clear the reset status by writing 1 to the status bit */
  142. omap4_prm_rmw_reg_bits(0xffffffff, mask, rstst_reg);
  143. /* de-assert the reset control line */
  144. omap4_prm_rmw_reg_bits(mask, 0, rstctrl_reg);
  145. /* wait the status to be set */
  146. omap_test_timeout(omap4_prm_read_bits_shift(rstst_reg, mask),
  147. MAX_MODULE_HARDRESET_WAIT, c);
  148. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  149. }
  150. void omap4_prm_global_warm_sw_reset(void)
  151. {
  152. u32 v;
  153. v = omap4_prm_read_inst_reg(OMAP4430_PRM_DEVICE_INST,
  154. OMAP4_RM_RSTCTRL);
  155. v |= OMAP4430_RST_GLOBAL_WARM_SW_MASK;
  156. omap4_prm_write_inst_reg(v, OMAP4430_PRM_DEVICE_INST,
  157. OMAP4_RM_RSTCTRL);
  158. /* OCP barrier */
  159. v = omap4_prm_read_inst_reg(OMAP4430_PRM_DEVICE_INST,
  160. OMAP4_RM_RSTCTRL);
  161. }