ux500_wdt.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2011-2013
  3. *
  4. * License Terms: GNU General Public License v2
  5. *
  6. * Author: Mathieu Poirier <mathieu.poirier@linaro.org> for ST-Ericsson
  7. * Author: Jonas Aaberg <jonas.aberg@stericsson.com> for ST-Ericsson
  8. */
  9. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  10. #include <linux/module.h>
  11. #include <linux/kernel.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/err.h>
  14. #include <linux/uaccess.h>
  15. #include <linux/watchdog.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/platform_data/ux500_wdt.h>
  18. #include <linux/mfd/dbx500-prcmu.h>
  19. #define WATCHDOG_TIMEOUT 600 /* 10 minutes */
  20. #define WATCHDOG_MIN 0
  21. #define WATCHDOG_MAX28 268435 /* 28 bit resolution in ms == 268435.455 s */
  22. #define WATCHDOG_MAX32 4294967 /* 32 bit resolution in ms == 4294967.295 s */
  23. static unsigned int timeout = WATCHDOG_TIMEOUT;
  24. module_param(timeout, uint, 0);
  25. MODULE_PARM_DESC(timeout,
  26. "Watchdog timeout in seconds. default="
  27. __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
  28. static bool nowayout = WATCHDOG_NOWAYOUT;
  29. module_param(nowayout, bool, 0);
  30. MODULE_PARM_DESC(nowayout,
  31. "Watchdog cannot be stopped once started (default="
  32. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  33. static int ux500_wdt_start(struct watchdog_device *wdd)
  34. {
  35. return prcmu_enable_a9wdog(PRCMU_WDOG_ALL);
  36. }
  37. static int ux500_wdt_stop(struct watchdog_device *wdd)
  38. {
  39. return prcmu_disable_a9wdog(PRCMU_WDOG_ALL);
  40. }
  41. static int ux500_wdt_keepalive(struct watchdog_device *wdd)
  42. {
  43. return prcmu_kick_a9wdog(PRCMU_WDOG_ALL);
  44. }
  45. static int ux500_wdt_set_timeout(struct watchdog_device *wdd,
  46. unsigned int timeout)
  47. {
  48. ux500_wdt_stop(wdd);
  49. prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
  50. ux500_wdt_start(wdd);
  51. return 0;
  52. }
  53. static const struct watchdog_info ux500_wdt_info = {
  54. .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
  55. .identity = "Ux500 WDT",
  56. .firmware_version = 1,
  57. };
  58. static const struct watchdog_ops ux500_wdt_ops = {
  59. .owner = THIS_MODULE,
  60. .start = ux500_wdt_start,
  61. .stop = ux500_wdt_stop,
  62. .ping = ux500_wdt_keepalive,
  63. .set_timeout = ux500_wdt_set_timeout,
  64. };
  65. static struct watchdog_device ux500_wdt = {
  66. .info = &ux500_wdt_info,
  67. .ops = &ux500_wdt_ops,
  68. .min_timeout = WATCHDOG_MIN,
  69. .max_timeout = WATCHDOG_MAX32,
  70. };
  71. static int ux500_wdt_probe(struct platform_device *pdev)
  72. {
  73. int ret;
  74. struct ux500_wdt_data *pdata = dev_get_platdata(&pdev->dev);
  75. if (pdata) {
  76. if (pdata->timeout > 0)
  77. timeout = pdata->timeout;
  78. if (pdata->has_28_bits_resolution)
  79. ux500_wdt.max_timeout = WATCHDOG_MAX28;
  80. }
  81. ux500_wdt.parent = &pdev->dev;
  82. watchdog_set_nowayout(&ux500_wdt, nowayout);
  83. /* disable auto off on sleep */
  84. prcmu_config_a9wdog(PRCMU_WDOG_CPU1, false);
  85. /* set HW initial value */
  86. prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
  87. ret = watchdog_register_device(&ux500_wdt);
  88. if (ret)
  89. return ret;
  90. dev_info(&pdev->dev, "initialized\n");
  91. return 0;
  92. }
  93. static int ux500_wdt_remove(struct platform_device *dev)
  94. {
  95. watchdog_unregister_device(&ux500_wdt);
  96. return 0;
  97. }
  98. #ifdef CONFIG_PM
  99. static int ux500_wdt_suspend(struct platform_device *pdev,
  100. pm_message_t state)
  101. {
  102. if (watchdog_active(&ux500_wdt)) {
  103. ux500_wdt_stop(&ux500_wdt);
  104. prcmu_config_a9wdog(PRCMU_WDOG_CPU1, true);
  105. prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
  106. ux500_wdt_start(&ux500_wdt);
  107. }
  108. return 0;
  109. }
  110. static int ux500_wdt_resume(struct platform_device *pdev)
  111. {
  112. if (watchdog_active(&ux500_wdt)) {
  113. ux500_wdt_stop(&ux500_wdt);
  114. prcmu_config_a9wdog(PRCMU_WDOG_CPU1, false);
  115. prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
  116. ux500_wdt_start(&ux500_wdt);
  117. }
  118. return 0;
  119. }
  120. #else
  121. #define ux500_wdt_suspend NULL
  122. #define ux500_wdt_resume NULL
  123. #endif
  124. static struct platform_driver ux500_wdt_driver = {
  125. .probe = ux500_wdt_probe,
  126. .remove = ux500_wdt_remove,
  127. .suspend = ux500_wdt_suspend,
  128. .resume = ux500_wdt_resume,
  129. .driver = {
  130. .name = "ux500_wdt",
  131. },
  132. };
  133. module_platform_driver(ux500_wdt_driver);
  134. MODULE_AUTHOR("Jonas Aaberg <jonas.aberg@stericsson.com>");
  135. MODULE_DESCRIPTION("Ux500 Watchdog Driver");
  136. MODULE_LICENSE("GPL");
  137. MODULE_ALIAS("platform:ux500_wdt");