wd_timer.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * OMAP2+ MPU WD_TIMER-specific code
  3. *
  4. * Copyright (C) 2012 Texas Instruments, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/io.h>
  13. #include <linux/err.h>
  14. #include <linux/platform_data/omap-wd-timer.h>
  15. #include "omap_hwmod.h"
  16. #include "omap_device.h"
  17. #include "wd_timer.h"
  18. #include "common.h"
  19. #include "prm.h"
  20. #include "soc.h"
  21. /*
  22. * In order to avoid any assumptions from bootloader regarding WDT
  23. * settings, WDT module is reset during init. This enables the watchdog
  24. * timer. Hence it is required to disable the watchdog after the WDT reset
  25. * during init. Otherwise the system would reboot as per the default
  26. * watchdog timer registers settings.
  27. */
  28. #define OMAP_WDT_WPS 0x34
  29. #define OMAP_WDT_SPR 0x48
  30. int omap2_wd_timer_disable(struct omap_hwmod *oh)
  31. {
  32. void __iomem *base;
  33. if (!oh) {
  34. pr_err("%s: Could not look up wdtimer_hwmod\n", __func__);
  35. return -EINVAL;
  36. }
  37. base = omap_hwmod_get_mpu_rt_va(oh);
  38. if (!base) {
  39. pr_err("%s: Could not get the base address for %s\n",
  40. oh->name, __func__);
  41. return -EINVAL;
  42. }
  43. /* sequence required to disable watchdog */
  44. writel_relaxed(0xAAAA, base + OMAP_WDT_SPR);
  45. while (readl_relaxed(base + OMAP_WDT_WPS) & 0x10)
  46. cpu_relax();
  47. writel_relaxed(0x5555, base + OMAP_WDT_SPR);
  48. while (readl_relaxed(base + OMAP_WDT_WPS) & 0x10)
  49. cpu_relax();
  50. return 0;
  51. }
  52. /**
  53. * omap2_wdtimer_reset - reset and disable the WDTIMER IP block
  54. * @oh: struct omap_hwmod *
  55. *
  56. * After the WDTIMER IP blocks are reset on OMAP2/3, we must also take
  57. * care to execute the special watchdog disable sequence. This is
  58. * because the watchdog is re-armed upon OCP softreset. (On OMAP4,
  59. * this behavior was apparently changed and the watchdog is no longer
  60. * re-armed after an OCP soft-reset.) Returns -ETIMEDOUT if the reset
  61. * did not complete, or 0 upon success.
  62. *
  63. * XXX Most of this code should be moved to the omap_hwmod.c layer
  64. * during a normal merge window. omap_hwmod_softreset() should be
  65. * renamed to omap_hwmod_set_ocp_softreset(), and omap_hwmod_softreset()
  66. * should call the hwmod _ocp_softreset() code.
  67. */
  68. int omap2_wd_timer_reset(struct omap_hwmod *oh)
  69. {
  70. int c = 0;
  71. /* Write to the SOFTRESET bit */
  72. omap_hwmod_softreset(oh);
  73. /* Poll on RESETDONE bit */
  74. omap_test_timeout((omap_hwmod_read(oh,
  75. oh->class->sysc->syss_offs)
  76. & SYSS_RESETDONE_MASK),
  77. MAX_MODULE_SOFTRESET_WAIT, c);
  78. if (oh->class->sysc->srst_udelay)
  79. udelay(oh->class->sysc->srst_udelay);
  80. if (c == MAX_MODULE_SOFTRESET_WAIT)
  81. pr_warn("%s: %s: softreset failed (waited %d usec)\n",
  82. __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
  83. else
  84. pr_debug("%s: %s: softreset in %d usec\n", __func__,
  85. oh->name, c);
  86. return (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT :
  87. omap2_wd_timer_disable(oh);
  88. }
  89. static int __init omap_init_wdt(void)
  90. {
  91. int id = -1;
  92. struct platform_device *pdev;
  93. struct omap_hwmod *oh;
  94. char *oh_name = "wd_timer2";
  95. char *dev_name = "omap_wdt";
  96. struct omap_wd_timer_platform_data pdata;
  97. if (!cpu_class_is_omap2() || of_have_populated_dt())
  98. return 0;
  99. oh = omap_hwmod_lookup(oh_name);
  100. if (!oh) {
  101. pr_err("Could not look up wd_timer%d hwmod\n", id);
  102. return -EINVAL;
  103. }
  104. pdata.read_reset_sources = prm_read_reset_sources;
  105. pdev = omap_device_build(dev_name, id, oh, &pdata,
  106. sizeof(struct omap_wd_timer_platform_data));
  107. WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
  108. dev_name, oh->name);
  109. return 0;
  110. }
  111. omap_subsys_initcall(omap_init_wdt);