prminst44xx.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 "iomap.h"
  18. #include "common.h"
  19. #include "prcm-common.h"
  20. #include "prm44xx.h"
  21. #include "prm54xx.h"
  22. #include "prm7xx.h"
  23. #include "prminst44xx.h"
  24. #include "prm-regbits-44xx.h"
  25. #include "prcm44xx.h"
  26. #include "prcm43xx.h"
  27. #include "prcm_mpu44xx.h"
  28. #include "soc.h"
  29. static void __iomem *_prm_bases[OMAP4_MAX_PRCM_PARTITIONS];
  30. static s32 prm_dev_inst = PRM_INSTANCE_UNKNOWN;
  31. /**
  32. * omap_prm_base_init - Populates the prm partitions
  33. *
  34. * Populates the base addresses of the _prm_bases
  35. * array used for read/write of prm module registers.
  36. */
  37. void omap_prm_base_init(void)
  38. {
  39. _prm_bases[OMAP4430_PRM_PARTITION] = prm_base;
  40. _prm_bases[OMAP4430_PRCM_MPU_PARTITION] = prcm_mpu_base;
  41. }
  42. s32 omap4_prmst_get_prm_dev_inst(void)
  43. {
  44. if (prm_dev_inst != PRM_INSTANCE_UNKNOWN)
  45. return prm_dev_inst;
  46. /* This cannot be done way early at boot.. as things are not setup */
  47. if (cpu_is_omap44xx())
  48. prm_dev_inst = OMAP4430_PRM_DEVICE_INST;
  49. else if (soc_is_omap54xx())
  50. prm_dev_inst = OMAP54XX_PRM_DEVICE_INST;
  51. else if (soc_is_dra7xx())
  52. prm_dev_inst = DRA7XX_PRM_DEVICE_INST;
  53. else if (soc_is_am43xx())
  54. prm_dev_inst = AM43XX_PRM_DEVICE_INST;
  55. return prm_dev_inst;
  56. }
  57. /* Read a register in a PRM instance */
  58. u32 omap4_prminst_read_inst_reg(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]);
  63. return readl_relaxed(_prm_bases[part] + inst + idx);
  64. }
  65. /* Write into a register in a PRM instance */
  66. void omap4_prminst_write_inst_reg(u32 val, u8 part, s16 inst, u16 idx)
  67. {
  68. BUG_ON(part >= OMAP4_MAX_PRCM_PARTITIONS ||
  69. part == OMAP4430_INVALID_PRCM_PARTITION ||
  70. !_prm_bases[part]);
  71. writel_relaxed(val, _prm_bases[part] + inst + idx);
  72. }
  73. /* Read-modify-write a register in PRM. Caller must lock */
  74. u32 omap4_prminst_rmw_inst_reg_bits(u32 mask, u32 bits, u8 part, s16 inst,
  75. u16 idx)
  76. {
  77. u32 v;
  78. v = omap4_prminst_read_inst_reg(part, inst, idx);
  79. v &= ~mask;
  80. v |= bits;
  81. omap4_prminst_write_inst_reg(v, part, inst, idx);
  82. return v;
  83. }
  84. /*
  85. * Address offset (in bytes) between the reset control and the reset
  86. * status registers: 4 bytes on OMAP4
  87. */
  88. #define OMAP4_RST_CTRL_ST_OFFSET 4
  89. /**
  90. * omap4_prminst_is_hardreset_asserted - read the HW reset line state of
  91. * submodules contained in the hwmod module
  92. * @rstctrl_reg: RM_RSTCTRL register address for this module
  93. * @shift: register bit shift corresponding to the reset line to check
  94. *
  95. * Returns 1 if the (sub)module hardreset line is currently asserted,
  96. * 0 if the (sub)module hardreset line is not currently asserted, or
  97. * -EINVAL upon parameter error.
  98. */
  99. int omap4_prminst_is_hardreset_asserted(u8 shift, u8 part, s16 inst,
  100. u16 rstctrl_offs)
  101. {
  102. u32 v;
  103. v = omap4_prminst_read_inst_reg(part, inst, rstctrl_offs);
  104. v &= 1 << shift;
  105. v >>= shift;
  106. return v;
  107. }
  108. /**
  109. * omap4_prminst_assert_hardreset - assert the HW reset line of a submodule
  110. * @rstctrl_reg: RM_RSTCTRL register address for this module
  111. * @shift: register bit shift corresponding to the reset line to assert
  112. *
  113. * Some IPs like dsp, ipu or iva contain processors that require an HW
  114. * reset line to be asserted / deasserted in order to fully enable the
  115. * IP. These modules may have multiple hard-reset lines that reset
  116. * different 'submodules' inside the IP block. This function will
  117. * place the submodule into reset. Returns 0 upon success or -EINVAL
  118. * upon an argument error.
  119. */
  120. int omap4_prminst_assert_hardreset(u8 shift, u8 part, s16 inst,
  121. u16 rstctrl_offs)
  122. {
  123. u32 mask = 1 << shift;
  124. omap4_prminst_rmw_inst_reg_bits(mask, mask, part, inst, rstctrl_offs);
  125. return 0;
  126. }
  127. /**
  128. * omap4_prminst_deassert_hardreset - deassert a submodule hardreset line and
  129. * wait
  130. * @rstctrl_reg: RM_RSTCTRL register address for this module
  131. * @shift: register bit shift corresponding to the reset line to deassert
  132. *
  133. * Some IPs like dsp, ipu or iva contain processors that require an HW
  134. * reset line to be asserted / deasserted in order to fully enable the
  135. * IP. These modules may have multiple hard-reset lines that reset
  136. * different 'submodules' inside the IP block. This function will
  137. * take the submodule out of reset and wait until the PRCM indicates
  138. * that the reset has completed before returning. Returns 0 upon success or
  139. * -EINVAL upon an argument error, -EEXIST if the submodule was already out
  140. * of reset, or -EBUSY if the submodule did not exit reset promptly.
  141. */
  142. int omap4_prminst_deassert_hardreset(u8 shift, u8 part, s16 inst,
  143. u16 rstctrl_offs)
  144. {
  145. int c;
  146. u32 mask = 1 << shift;
  147. u16 rstst_offs = rstctrl_offs + OMAP4_RST_CTRL_ST_OFFSET;
  148. /* Check the current status to avoid de-asserting the line twice */
  149. if (omap4_prminst_is_hardreset_asserted(shift, part, inst,
  150. rstctrl_offs) == 0)
  151. return -EEXIST;
  152. /* Clear the reset status by writing 1 to the status bit */
  153. omap4_prminst_rmw_inst_reg_bits(0xffffffff, mask, part, inst,
  154. rstst_offs);
  155. /* de-assert the reset control line */
  156. omap4_prminst_rmw_inst_reg_bits(mask, 0, part, inst, rstctrl_offs);
  157. /* wait the status to be set */
  158. omap_test_timeout(omap4_prminst_is_hardreset_asserted(shift, part, inst,
  159. rstst_offs),
  160. MAX_MODULE_HARDRESET_WAIT, c);
  161. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  162. }
  163. void omap4_prminst_global_warm_sw_reset(void)
  164. {
  165. u32 v;
  166. s32 inst = omap4_prmst_get_prm_dev_inst();
  167. if (inst == PRM_INSTANCE_UNKNOWN)
  168. return;
  169. v = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION, inst,
  170. OMAP4_PRM_RSTCTRL_OFFSET);
  171. v |= OMAP4430_RST_GLOBAL_WARM_SW_MASK;
  172. omap4_prminst_write_inst_reg(v, OMAP4430_PRM_PARTITION,
  173. inst, OMAP4_PRM_RSTCTRL_OFFSET);
  174. /* OCP barrier */
  175. v = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
  176. inst, OMAP4_PRM_RSTCTRL_OFFSET);
  177. }