prminst44xx.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * OMAP4 PRM instance functions
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Copyright (C) 2011 Texas Instruments, Inc.
  6. * Paul Walmsley
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/types.h>
  14. #include <linux/errno.h>
  15. #include <linux/err.h>
  16. #include <linux/io.h>
  17. #include <plat/common.h>
  18. #include "prm44xx.h"
  19. #include "prminst44xx.h"
  20. #include "prm-regbits-44xx.h"
  21. #include "prcm44xx.h"
  22. #include "prcm_mpu44xx.h"
  23. static u32 _prm_bases[OMAP4_MAX_PRCM_PARTITIONS] = {
  24. [OMAP4430_INVALID_PRCM_PARTITION] = 0,
  25. [OMAP4430_PRM_PARTITION] = OMAP4430_PRM_BASE,
  26. [OMAP4430_CM1_PARTITION] = 0,
  27. [OMAP4430_CM2_PARTITION] = 0,
  28. [OMAP4430_SCRM_PARTITION] = 0,
  29. [OMAP4430_PRCM_MPU_PARTITION] = OMAP4430_PRCM_MPU_BASE,
  30. };
  31. /* Read a register in a PRM instance */
  32. u32 omap4_prminst_read_inst_reg(u8 part, s16 inst, u16 idx)
  33. {
  34. BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
  35. part == OMAP4430_INVALID_PRCM_PARTITION ||
  36. !_prm_bases[part]);
  37. return __raw_readl(OMAP2_L4_IO_ADDRESS(_prm_bases[part] + inst +
  38. idx));
  39. }
  40. /* Write into a register in a PRM instance */
  41. void omap4_prminst_write_inst_reg(u32 val, u8 part, s16 inst, u16 idx)
  42. {
  43. BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
  44. part == OMAP4430_INVALID_PRCM_PARTITION ||
  45. !_prm_bases[part]);
  46. __raw_writel(val, OMAP2_L4_IO_ADDRESS(_prm_bases[part] + inst + idx));
  47. }
  48. /* Read-modify-write a register in PRM. Caller must lock */
  49. u32 omap4_prminst_rmw_inst_reg_bits(u32 mask, u32 bits, u8 part, s16 inst,
  50. u16 idx)
  51. {
  52. u32 v;
  53. v = omap4_prminst_read_inst_reg(part, inst, idx);
  54. v &= ~mask;
  55. v |= bits;
  56. omap4_prminst_write_inst_reg(v, part, inst, idx);
  57. return v;
  58. }
  59. /*
  60. * Address offset (in bytes) between the reset control and the reset
  61. * status registers: 4 bytes on OMAP4
  62. */
  63. #define OMAP4_RST_CTRL_ST_OFFSET 4
  64. /**
  65. * omap4_prminst_is_hardreset_asserted - read the HW reset line state of
  66. * submodules contained in the hwmod module
  67. * @rstctrl_reg: RM_RSTCTRL register address for this module
  68. * @shift: register bit shift corresponding to the reset line to check
  69. *
  70. * Returns 1 if the (sub)module hardreset line is currently asserted,
  71. * 0 if the (sub)module hardreset line is not currently asserted, or
  72. * -EINVAL upon parameter error.
  73. */
  74. int omap4_prminst_is_hardreset_asserted(u8 shift, u8 part, s16 inst,
  75. u16 rstctrl_offs)
  76. {
  77. u32 v;
  78. v = omap4_prminst_read_inst_reg(part, inst, rstctrl_offs);
  79. v &= 1 << shift;
  80. v >>= shift;
  81. return v;
  82. }
  83. /**
  84. * omap4_prminst_assert_hardreset - assert the HW reset line of a submodule
  85. * @rstctrl_reg: RM_RSTCTRL register address for this module
  86. * @shift: register bit shift corresponding to the reset line to assert
  87. *
  88. * Some IPs like dsp, ipu or iva contain processors that require an HW
  89. * reset line to be asserted / deasserted in order to fully enable the
  90. * IP. These modules may have multiple hard-reset lines that reset
  91. * different 'submodules' inside the IP block. This function will
  92. * place the submodule into reset. Returns 0 upon success or -EINVAL
  93. * upon an argument error.
  94. */
  95. int omap4_prminst_assert_hardreset(u8 shift, u8 part, s16 inst,
  96. u16 rstctrl_offs)
  97. {
  98. u32 mask = 1 << shift;
  99. omap4_prminst_rmw_inst_reg_bits(mask, mask, part, inst, rstctrl_offs);
  100. return 0;
  101. }
  102. /**
  103. * omap4_prminst_deassert_hardreset - deassert a submodule hardreset line and
  104. * wait
  105. * @rstctrl_reg: RM_RSTCTRL register address for this module
  106. * @shift: register bit shift corresponding to the reset line to deassert
  107. *
  108. * Some IPs like dsp, ipu or iva contain processors that require an HW
  109. * reset line to be asserted / deasserted in order to fully enable the
  110. * IP. These modules may have multiple hard-reset lines that reset
  111. * different 'submodules' inside the IP block. This function will
  112. * take the submodule out of reset and wait until the PRCM indicates
  113. * that the reset has completed before returning. Returns 0 upon success or
  114. * -EINVAL upon an argument error, -EEXIST if the submodule was already out
  115. * of reset, or -EBUSY if the submodule did not exit reset promptly.
  116. */
  117. int omap4_prminst_deassert_hardreset(u8 shift, u8 part, s16 inst,
  118. u16 rstctrl_offs)
  119. {
  120. int c;
  121. u32 mask = 1 << shift;
  122. u16 rstst_offs = rstctrl_offs + OMAP4_RST_CTRL_ST_OFFSET;
  123. /* Check the current status to avoid de-asserting the line twice */
  124. if (omap4_prminst_is_hardreset_asserted(shift, part, inst,
  125. rstctrl_offs) == 0)
  126. return -EEXIST;
  127. /* Clear the reset status by writing 1 to the status bit */
  128. omap4_prminst_rmw_inst_reg_bits(0xffffffff, mask, part, inst,
  129. rstst_offs);
  130. /* de-assert the reset control line */
  131. omap4_prminst_rmw_inst_reg_bits(mask, 0, part, inst, rstctrl_offs);
  132. /* wait the status to be set */
  133. omap_test_timeout(omap4_prminst_is_hardreset_asserted(shift, part, inst,
  134. rstst_offs),
  135. MAX_MODULE_HARDRESET_WAIT, c);
  136. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  137. }
  138. void omap4_prminst_global_warm_sw_reset(void)
  139. {
  140. u32 v;
  141. v = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
  142. OMAP4430_PRM_DEVICE_INST,
  143. OMAP4_PRM_RSTCTRL_OFFSET);
  144. v |= OMAP4430_RST_GLOBAL_WARM_SW_MASK;
  145. omap4_prminst_write_inst_reg(v, OMAP4430_PRM_PARTITION,
  146. OMAP4430_PRM_DEVICE_INST,
  147. OMAP4_PRM_RSTCTRL_OFFSET);
  148. /* OCP barrier */
  149. v = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
  150. OMAP4430_PRM_DEVICE_INST,
  151. OMAP4_PRM_RSTCTRL_OFFSET);
  152. }