prminst44xx.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OMAP4 PRM instance functions
  4. *
  5. * Copyright (C) 2009 Nokia Corporation
  6. * Copyright (C) 2011 Texas Instruments, Inc.
  7. * Paul Walmsley
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/types.h>
  11. #include <linux/errno.h>
  12. #include <linux/err.h>
  13. #include <linux/io.h>
  14. #include "iomap.h"
  15. #include "common.h"
  16. #include "prcm-common.h"
  17. #include "prm44xx.h"
  18. #include "prm54xx.h"
  19. #include "prm7xx.h"
  20. #include "prminst44xx.h"
  21. #include "prm-regbits-44xx.h"
  22. #include "prcm44xx.h"
  23. #include "prcm43xx.h"
  24. #include "prcm_mpu44xx.h"
  25. #include "soc.h"
  26. static struct omap_domain_base _prm_bases[OMAP4_MAX_PRCM_PARTITIONS];
  27. static s32 prm_dev_inst = PRM_INSTANCE_UNKNOWN;
  28. /**
  29. * omap_prm_base_init - Populates the prm partitions
  30. *
  31. * Populates the base addresses of the _prm_bases
  32. * array used for read/write of prm module registers.
  33. */
  34. void omap_prm_base_init(void)
  35. {
  36. memcpy(&_prm_bases[OMAP4430_PRM_PARTITION], &prm_base,
  37. sizeof(prm_base));
  38. memcpy(&_prm_bases[OMAP4430_PRCM_MPU_PARTITION], &prcm_mpu_base,
  39. sizeof(prcm_mpu_base));
  40. }
  41. s32 omap4_prmst_get_prm_dev_inst(void)
  42. {
  43. return prm_dev_inst;
  44. }
  45. void omap4_prminst_set_prm_dev_inst(s32 dev_inst)
  46. {
  47. prm_dev_inst = dev_inst;
  48. }
  49. /* Read a register in a PRM instance */
  50. u32 omap4_prminst_read_inst_reg(u8 part, s16 inst, u16 idx)
  51. {
  52. BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
  53. part == OMAP4430_INVALID_PRCM_PARTITION ||
  54. !_prm_bases[part].va);
  55. return readl_relaxed(_prm_bases[part].va + inst + idx);
  56. }
  57. /* Write into a register in a PRM instance */
  58. void omap4_prminst_write_inst_reg(u32 val, u8 part, s16 inst, u16 idx)
  59. {
  60. BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
  61. part == OMAP4430_INVALID_PRCM_PARTITION ||
  62. !_prm_bases[part].va);
  63. writel_relaxed(val, _prm_bases[part].va + inst + idx);
  64. }
  65. /* Read-modify-write a register in PRM. Caller must lock */
  66. u32 omap4_prminst_rmw_inst_reg_bits(u32 mask, u32 bits, u8 part, s16 inst,
  67. u16 idx)
  68. {
  69. u32 v;
  70. v = omap4_prminst_read_inst_reg(part, inst, idx);
  71. v &= ~mask;
  72. v |= bits;
  73. omap4_prminst_write_inst_reg(v, part, inst, idx);
  74. return v;
  75. }
  76. /**
  77. * omap4_prminst_is_hardreset_asserted - read the HW reset line state of
  78. * submodules contained in the hwmod module
  79. * @rstctrl_reg: RM_RSTCTRL register address for this module
  80. * @shift: register bit shift corresponding to the reset line to check
  81. *
  82. * Returns 1 if the (sub)module hardreset line is currently asserted,
  83. * 0 if the (sub)module hardreset line is not currently asserted, or
  84. * -EINVAL upon parameter error.
  85. */
  86. int omap4_prminst_is_hardreset_asserted(u8 shift, u8 part, s16 inst,
  87. u16 rstctrl_offs)
  88. {
  89. u32 v;
  90. v = omap4_prminst_read_inst_reg(part, inst, rstctrl_offs);
  91. v &= 1 << shift;
  92. v >>= shift;
  93. return v;
  94. }
  95. /**
  96. * omap4_prminst_assert_hardreset - assert the HW reset line of a submodule
  97. * @rstctrl_reg: RM_RSTCTRL register address for this module
  98. * @shift: register bit shift corresponding to the reset line to assert
  99. *
  100. * Some IPs like dsp, ipu 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 omap4_prminst_assert_hardreset(u8 shift, u8 part, s16 inst,
  108. u16 rstctrl_offs)
  109. {
  110. u32 mask = 1 << shift;
  111. omap4_prminst_rmw_inst_reg_bits(mask, mask, part, inst, rstctrl_offs);
  112. return 0;
  113. }
  114. /**
  115. * omap4_prminst_deassert_hardreset - deassert a submodule hardreset line and
  116. * wait
  117. * @shift: register bit shift corresponding to the reset line to deassert
  118. * @st_shift: status bit offset corresponding to the reset line
  119. * @part: PRM partition
  120. * @inst: PRM instance offset
  121. * @rstctrl_offs: reset register offset
  122. * @rstst_offs: reset status register offset
  123. *
  124. * Some IPs like dsp, ipu or iva contain processors that require an HW
  125. * reset line to be asserted / deasserted in order to fully enable the
  126. * IP. These modules may have multiple hard-reset lines that reset
  127. * different 'submodules' inside the IP block. This function will
  128. * take the submodule out of reset and wait until the PRCM indicates
  129. * that the reset has completed before returning. Returns 0 upon success or
  130. * -EINVAL upon an argument error, -EEXIST if the submodule was already out
  131. * of reset, or -EBUSY if the submodule did not exit reset promptly.
  132. */
  133. int omap4_prminst_deassert_hardreset(u8 shift, u8 st_shift, u8 part, s16 inst,
  134. u16 rstctrl_offs, u16 rstst_offs)
  135. {
  136. int c;
  137. u32 mask = 1 << shift;
  138. u32 st_mask = 1 << st_shift;
  139. /* Check the current status to avoid de-asserting the line twice */
  140. if (omap4_prminst_is_hardreset_asserted(shift, part, inst,
  141. rstctrl_offs) == 0)
  142. return -EEXIST;
  143. /* Clear the reset status by writing 1 to the status bit */
  144. omap4_prminst_rmw_inst_reg_bits(0xffffffff, st_mask, part, inst,
  145. rstst_offs);
  146. /* de-assert the reset control line */
  147. omap4_prminst_rmw_inst_reg_bits(mask, 0, part, inst, rstctrl_offs);
  148. /* wait the status to be set */
  149. omap_test_timeout(omap4_prminst_is_hardreset_asserted(st_shift, part,
  150. inst, rstst_offs),
  151. MAX_MODULE_HARDRESET_WAIT, c);
  152. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  153. }
  154. void omap4_prminst_global_warm_sw_reset(void)
  155. {
  156. u32 v;
  157. s32 inst = omap4_prmst_get_prm_dev_inst();
  158. if (inst == PRM_INSTANCE_UNKNOWN)
  159. return;
  160. v = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION, inst,
  161. OMAP4_PRM_RSTCTRL_OFFSET);
  162. v |= OMAP4430_RST_GLOBAL_WARM_SW_MASK;
  163. omap4_prminst_write_inst_reg(v, OMAP4430_PRM_PARTITION,
  164. inst, OMAP4_PRM_RSTCTRL_OFFSET);
  165. /* OCP barrier */
  166. v = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
  167. inst, OMAP4_PRM_RSTCTRL_OFFSET);
  168. }