wd_timer.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * OMAP2+ MPU WD_TIMER-specific code
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/io.h>
  11. #include <linux/err.h>
  12. #include <plat/omap_hwmod.h>
  13. #include "wd_timer.h"
  14. #include "common.h"
  15. /*
  16. * In order to avoid any assumptions from bootloader regarding WDT
  17. * settings, WDT module is reset during init. This enables the watchdog
  18. * timer. Hence it is required to disable the watchdog after the WDT reset
  19. * during init. Otherwise the system would reboot as per the default
  20. * watchdog timer registers settings.
  21. */
  22. #define OMAP_WDT_WPS 0x34
  23. #define OMAP_WDT_SPR 0x48
  24. /* Maximum microseconds to wait for OMAP module to softreset */
  25. #define MAX_MODULE_SOFTRESET_WAIT 10000
  26. int omap2_wd_timer_disable(struct omap_hwmod *oh)
  27. {
  28. void __iomem *base;
  29. if (!oh) {
  30. pr_err("%s: Could not look up wdtimer_hwmod\n", __func__);
  31. return -EINVAL;
  32. }
  33. base = omap_hwmod_get_mpu_rt_va(oh);
  34. if (!base) {
  35. pr_err("%s: Could not get the base address for %s\n",
  36. oh->name, __func__);
  37. return -EINVAL;
  38. }
  39. /* sequence required to disable watchdog */
  40. __raw_writel(0xAAAA, base + OMAP_WDT_SPR);
  41. while (__raw_readl(base + OMAP_WDT_WPS) & 0x10)
  42. cpu_relax();
  43. __raw_writel(0x5555, base + OMAP_WDT_SPR);
  44. while (__raw_readl(base + OMAP_WDT_WPS) & 0x10)
  45. cpu_relax();
  46. return 0;
  47. }
  48. /**
  49. * omap2_wdtimer_reset - reset and disable the WDTIMER IP block
  50. * @oh: struct omap_hwmod *
  51. *
  52. * After the WDTIMER IP blocks are reset on OMAP2/3, we must also take
  53. * care to execute the special watchdog disable sequence. This is
  54. * because the watchdog is re-armed upon OCP softreset. (On OMAP4,
  55. * this behavior was apparently changed and the watchdog is no longer
  56. * re-armed after an OCP soft-reset.) Returns -ETIMEDOUT if the reset
  57. * did not complete, or 0 upon success.
  58. *
  59. * XXX Most of this code should be moved to the omap_hwmod.c layer
  60. * during a normal merge window. omap_hwmod_softreset() should be
  61. * renamed to omap_hwmod_set_ocp_softreset(), and omap_hwmod_softreset()
  62. * should call the hwmod _ocp_softreset() code.
  63. */
  64. int omap2_wd_timer_reset(struct omap_hwmod *oh)
  65. {
  66. int c = 0;
  67. /* Write to the SOFTRESET bit */
  68. omap_hwmod_softreset(oh);
  69. /* Poll on RESETDONE bit */
  70. omap_test_timeout((omap_hwmod_read(oh,
  71. oh->class->sysc->syss_offs)
  72. & SYSS_RESETDONE_MASK),
  73. MAX_MODULE_SOFTRESET_WAIT, c);
  74. if (oh->class->sysc->srst_udelay)
  75. udelay(oh->class->sysc->srst_udelay);
  76. if (c == MAX_MODULE_SOFTRESET_WAIT)
  77. pr_warning("%s: %s: softreset failed (waited %d usec)\n",
  78. __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
  79. else
  80. pr_debug("%s: %s: softreset in %d usec\n", __func__,
  81. oh->name, c);
  82. return (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT :
  83. omap2_wd_timer_disable(oh);
  84. }