prminst44xx.c 5.5 KB

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