prm44xx.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * OMAP4 PRM module functions
  3. *
  4. * Copyright (C) 2010 Texas Instruments, Inc.
  5. * Copyright (C) 2010 Nokia Corporation
  6. * Benoît Cousson
  7. * Paul Walmsley
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/delay.h>
  15. #include <linux/errno.h>
  16. #include <linux/err.h>
  17. #include <plat/common.h>
  18. #include <plat/cpu.h>
  19. #include <plat/prcm.h>
  20. #include "prm.h"
  21. #include "prm-regbits-44xx.h"
  22. /*
  23. * Address offset (in bytes) between the reset control and the reset
  24. * status registers: 4 bytes on OMAP4
  25. */
  26. #define OMAP4_RST_CTRL_ST_OFFSET 4
  27. /**
  28. * omap4_prm_is_hardreset_asserted - read the HW reset line state of
  29. * submodules contained in the hwmod module
  30. * @rstctrl_reg: RM_RSTCTRL register address for this module
  31. * @shift: register bit shift corresponding to the reset line to check
  32. *
  33. * Returns 1 if the (sub)module hardreset line is currently asserted,
  34. * 0 if the (sub)module hardreset line is not currently asserted, or
  35. * -EINVAL upon parameter error.
  36. */
  37. int omap4_prm_is_hardreset_asserted(void __iomem *rstctrl_reg, u8 shift)
  38. {
  39. if (!cpu_is_omap44xx() || !rstctrl_reg)
  40. return -EINVAL;
  41. return omap4_prm_read_bits_shift(rstctrl_reg, (1 << shift));
  42. }
  43. /**
  44. * omap4_prm_assert_hardreset - assert the HW reset line of a submodule
  45. * @rstctrl_reg: RM_RSTCTRL register address for this module
  46. * @shift: register bit shift corresponding to the reset line to assert
  47. *
  48. * Some IPs like dsp, ipu or iva contain processors that require an HW
  49. * reset line to be asserted / deasserted in order to fully enable the
  50. * IP. These modules may have multiple hard-reset lines that reset
  51. * different 'submodules' inside the IP block. This function will
  52. * place the submodule into reset. Returns 0 upon success or -EINVAL
  53. * upon an argument error.
  54. */
  55. int omap4_prm_assert_hardreset(void __iomem *rstctrl_reg, u8 shift)
  56. {
  57. u32 mask;
  58. if (!cpu_is_omap44xx() || !rstctrl_reg)
  59. return -EINVAL;
  60. mask = 1 << shift;
  61. omap4_prm_rmw_reg_bits(mask, mask, rstctrl_reg);
  62. return 0;
  63. }
  64. /**
  65. * omap4_prm_deassert_hardreset - deassert a submodule hardreset line and wait
  66. * @rstctrl_reg: RM_RSTCTRL register address for this module
  67. * @shift: register bit shift corresponding to the reset line to deassert
  68. *
  69. * Some IPs like dsp, ipu or iva contain processors that require an HW
  70. * reset line to be asserted / deasserted in order to fully enable the
  71. * IP. These modules may have multiple hard-reset lines that reset
  72. * different 'submodules' inside the IP block. This function will
  73. * take the submodule out of reset and wait until the PRCM indicates
  74. * that the reset has completed before returning. Returns 0 upon success or
  75. * -EINVAL upon an argument error, -EEXIST if the submodule was already out
  76. * of reset, or -EBUSY if the submodule did not exit reset promptly.
  77. */
  78. int omap4_prm_deassert_hardreset(void __iomem *rstctrl_reg, u8 shift)
  79. {
  80. u32 mask;
  81. void __iomem *rstst_reg;
  82. int c;
  83. if (!cpu_is_omap44xx() || !rstctrl_reg)
  84. return -EINVAL;
  85. rstst_reg = rstctrl_reg + OMAP4_RST_CTRL_ST_OFFSET;
  86. mask = 1 << shift;
  87. /* Check the current status to avoid de-asserting the line twice */
  88. if (omap4_prm_read_bits_shift(rstctrl_reg, mask) == 0)
  89. return -EEXIST;
  90. /* Clear the reset status by writing 1 to the status bit */
  91. omap4_prm_rmw_reg_bits(0xffffffff, mask, rstst_reg);
  92. /* de-assert the reset control line */
  93. omap4_prm_rmw_reg_bits(mask, 0, rstctrl_reg);
  94. /* wait the status to be set */
  95. omap_test_timeout(omap4_prm_read_bits_shift(rstst_reg, mask),
  96. MAX_MODULE_HARDRESET_WAIT, c);
  97. return (c == MAX_MODULE_HARDRESET_WAIT) ? -EBUSY : 0;
  98. }