prminst44xx.c 5.5 KB

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