omap_hwmod_reset.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "omap_hwmod.h"
  29. #include "common.h"
  30. #define OMAP_RTC_STATUS_REG 0x44
  31. #define OMAP_RTC_KICK0_REG 0x6c
  32. #define OMAP_RTC_KICK1_REG 0x70
  33. #define OMAP_RTC_KICK0_VALUE 0x83E70B13
  34. #define OMAP_RTC_KICK1_VALUE 0x95A4F1E0
  35. #define OMAP_RTC_STATUS_BUSY BIT(0)
  36. #define OMAP_RTC_MAX_READY_TIME 50
  37. /**
  38. * omap_rtc_wait_not_busy - Wait for the RTC BUSY flag
  39. * @oh: struct omap_hwmod *
  40. *
  41. * For updating certain RTC registers, the MPU must wait
  42. * for the BUSY status in OMAP_RTC_STATUS_REG to become zero.
  43. * Once the BUSY status is zero, there is a 15 microseconds access
  44. * period in which the MPU can program.
  45. */
  46. static void omap_rtc_wait_not_busy(struct omap_hwmod *oh)
  47. {
  48. int i;
  49. /* BUSY may stay active for 1/32768 second (~30 usec) */
  50. omap_test_timeout(omap_hwmod_read(oh, OMAP_RTC_STATUS_REG)
  51. & OMAP_RTC_STATUS_BUSY, OMAP_RTC_MAX_READY_TIME, i);
  52. /* now we have ~15 microseconds to read/write various registers */
  53. }
  54. /**
  55. * omap_hwmod_rtc_unlock - Unlock the Kicker mechanism.
  56. * @oh: struct omap_hwmod *
  57. *
  58. * RTC IP have kicker feature. This prevents spurious writes to its registers.
  59. * In order to write into any of the RTC registers, KICK values has te be
  60. * written in respective KICK registers. This is needed for hwmod to write into
  61. * sysconfig register.
  62. */
  63. void omap_hwmod_rtc_unlock(struct omap_hwmod *oh)
  64. {
  65. unsigned long flags;
  66. local_irq_save(flags);
  67. omap_rtc_wait_not_busy(oh);
  68. omap_hwmod_write(OMAP_RTC_KICK0_VALUE, oh, OMAP_RTC_KICK0_REG);
  69. omap_hwmod_write(OMAP_RTC_KICK1_VALUE, oh, OMAP_RTC_KICK1_REG);
  70. local_irq_restore(flags);
  71. }
  72. /**
  73. * omap_hwmod_rtc_lock - Lock the Kicker mechanism.
  74. * @oh: struct omap_hwmod *
  75. *
  76. * RTC IP have kicker feature. This prevents spurious writes to its registers.
  77. * Once the RTC registers are written, KICK mechanism needs to be locked,
  78. * in order to prevent any spurious writes. This function locks back the RTC
  79. * registers once hwmod completes its write into sysconfig register.
  80. */
  81. void omap_hwmod_rtc_lock(struct omap_hwmod *oh)
  82. {
  83. unsigned long flags;
  84. local_irq_save(flags);
  85. omap_rtc_wait_not_busy(oh);
  86. omap_hwmod_write(0x0, oh, OMAP_RTC_KICK0_REG);
  87. omap_hwmod_write(0x0, oh, OMAP_RTC_KICK1_REG);
  88. local_irq_restore(flags);
  89. }