omap_hwmod_reset.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * OMAP IP block custom reset and preprogramming stubs
  3. *
  4. * Copyright (C) 2012 Texas Instruments, Inc.
  5. * Paul Walmsley
  6. *
  7. * A small number of IP blocks need custom reset and preprogramming
  8. * functions. The stubs in this file provide a standard way for the
  9. * hwmod code to call these functions, which are to be located under
  10. * drivers/.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation version 2.
  15. *
  16. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  17. * kind, whether express or implied; without even the implied warranty
  18. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  24. * 02110-1301 USA
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/errno.h>
  28. #include <sound/aess.h>
  29. #include "omap_hwmod.h"
  30. #include "common.h"
  31. #define OMAP_RTC_STATUS_REG 0x44
  32. #define OMAP_RTC_KICK0_REG 0x6c
  33. #define OMAP_RTC_KICK1_REG 0x70
  34. #define OMAP_RTC_KICK0_VALUE 0x83E70B13
  35. #define OMAP_RTC_KICK1_VALUE 0x95A4F1E0
  36. #define OMAP_RTC_STATUS_BUSY BIT(0)
  37. #define OMAP_RTC_MAX_READY_TIME 50
  38. /**
  39. * omap_hwmod_aess_preprogram - enable AESS internal autogating
  40. * @oh: struct omap_hwmod *
  41. *
  42. * The AESS will not IdleAck to the PRCM until its internal autogating
  43. * is enabled. Since internal autogating is disabled by default after
  44. * AESS reset, we must enable autogating after the hwmod code resets
  45. * the AESS. Returns 0.
  46. */
  47. int omap_hwmod_aess_preprogram(struct omap_hwmod *oh)
  48. {
  49. void __iomem *va;
  50. va = omap_hwmod_get_mpu_rt_va(oh);
  51. if (!va)
  52. return -EINVAL;
  53. aess_enable_autogating(va);
  54. return 0;
  55. }
  56. /**
  57. * omap_rtc_wait_not_busy - Wait for the RTC BUSY flag
  58. * @oh: struct omap_hwmod *
  59. *
  60. * For updating certain RTC registers, the MPU must wait
  61. * for the BUSY status in OMAP_RTC_STATUS_REG to become zero.
  62. * Once the BUSY status is zero, there is a 15 microseconds access
  63. * period in which the MPU can program.
  64. */
  65. static void omap_rtc_wait_not_busy(struct omap_hwmod *oh)
  66. {
  67. int i;
  68. /* BUSY may stay active for 1/32768 second (~30 usec) */
  69. omap_test_timeout(omap_hwmod_read(oh, OMAP_RTC_STATUS_REG)
  70. & OMAP_RTC_STATUS_BUSY, OMAP_RTC_MAX_READY_TIME, i);
  71. /* now we have ~15 microseconds to read/write various registers */
  72. }
  73. /**
  74. * omap_hwmod_rtc_unlock - Unlock the Kicker mechanism.
  75. * @oh: struct omap_hwmod *
  76. *
  77. * RTC IP have kicker feature. This prevents spurious writes to its registers.
  78. * In order to write into any of the RTC registers, KICK values has te be
  79. * written in respective KICK registers. This is needed for hwmod to write into
  80. * sysconfig register.
  81. */
  82. void omap_hwmod_rtc_unlock(struct omap_hwmod *oh)
  83. {
  84. local_irq_disable();
  85. omap_rtc_wait_not_busy(oh);
  86. omap_hwmod_write(OMAP_RTC_KICK0_VALUE, oh, OMAP_RTC_KICK0_REG);
  87. omap_hwmod_write(OMAP_RTC_KICK1_VALUE, oh, OMAP_RTC_KICK1_REG);
  88. local_irq_enable();
  89. }
  90. /**
  91. * omap_hwmod_rtc_lock - Lock the Kicker mechanism.
  92. * @oh: struct omap_hwmod *
  93. *
  94. * RTC IP have kicker feature. This prevents spurious writes to its registers.
  95. * Once the RTC registers are written, KICK mechanism needs to be locked,
  96. * in order to prevent any spurious writes. This function locks back the RTC
  97. * registers once hwmod completes its write into sysconfig register.
  98. */
  99. void omap_hwmod_rtc_lock(struct omap_hwmod *oh)
  100. {
  101. local_irq_disable();
  102. omap_rtc_wait_not_busy(oh);
  103. omap_hwmod_write(0x0, oh, OMAP_RTC_KICK0_REG);
  104. omap_hwmod_write(0x0, oh, OMAP_RTC_KICK1_REG);
  105. local_irq_enable();
  106. }