db8500_wdt.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) ST-Ericsson SA 2011-2013
  4. *
  5. * Author: Mathieu Poirier <[email protected]> for ST-Ericsson
  6. * Author: Jonas Aaberg <[email protected]> for ST-Ericsson
  7. */
  8. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/moduleparam.h>
  12. #include <linux/err.h>
  13. #include <linux/uaccess.h>
  14. #include <linux/watchdog.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/mfd/dbx500-prcmu.h>
  17. #define WATCHDOG_TIMEOUT 600 /* 10 minutes */
  18. #define WATCHDOG_MIN 0
  19. #define WATCHDOG_MAX28 268435 /* 28 bit resolution in ms == 268435.455 s */
  20. static unsigned int timeout = WATCHDOG_TIMEOUT;
  21. module_param(timeout, uint, 0);
  22. MODULE_PARM_DESC(timeout,
  23. "Watchdog timeout in seconds. default="
  24. __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
  25. static bool nowayout = WATCHDOG_NOWAYOUT;
  26. module_param(nowayout, bool, 0);
  27. MODULE_PARM_DESC(nowayout,
  28. "Watchdog cannot be stopped once started (default="
  29. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  30. static int db8500_wdt_start(struct watchdog_device *wdd)
  31. {
  32. return prcmu_enable_a9wdog(PRCMU_WDOG_ALL);
  33. }
  34. static int db8500_wdt_stop(struct watchdog_device *wdd)
  35. {
  36. return prcmu_disable_a9wdog(PRCMU_WDOG_ALL);
  37. }
  38. static int db8500_wdt_keepalive(struct watchdog_device *wdd)
  39. {
  40. return prcmu_kick_a9wdog(PRCMU_WDOG_ALL);
  41. }
  42. static int db8500_wdt_set_timeout(struct watchdog_device *wdd,
  43. unsigned int timeout)
  44. {
  45. db8500_wdt_stop(wdd);
  46. prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
  47. db8500_wdt_start(wdd);
  48. return 0;
  49. }
  50. static const struct watchdog_info db8500_wdt_info = {
  51. .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
  52. .identity = "DB8500 WDT",
  53. .firmware_version = 1,
  54. };
  55. static const struct watchdog_ops db8500_wdt_ops = {
  56. .owner = THIS_MODULE,
  57. .start = db8500_wdt_start,
  58. .stop = db8500_wdt_stop,
  59. .ping = db8500_wdt_keepalive,
  60. .set_timeout = db8500_wdt_set_timeout,
  61. };
  62. static struct watchdog_device db8500_wdt = {
  63. .info = &db8500_wdt_info,
  64. .ops = &db8500_wdt_ops,
  65. .min_timeout = WATCHDOG_MIN,
  66. .max_timeout = WATCHDOG_MAX28,
  67. };
  68. static int db8500_wdt_probe(struct platform_device *pdev)
  69. {
  70. struct device *dev = &pdev->dev;
  71. int ret;
  72. timeout = 600; /* Default to 10 minutes */
  73. db8500_wdt.parent = dev;
  74. watchdog_set_nowayout(&db8500_wdt, nowayout);
  75. /* disable auto off on sleep */
  76. prcmu_config_a9wdog(PRCMU_WDOG_CPU1, false);
  77. /* set HW initial value */
  78. prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
  79. ret = devm_watchdog_register_device(dev, &db8500_wdt);
  80. if (ret)
  81. return ret;
  82. dev_info(dev, "initialized\n");
  83. return 0;
  84. }
  85. #ifdef CONFIG_PM
  86. static int db8500_wdt_suspend(struct platform_device *pdev,
  87. pm_message_t state)
  88. {
  89. if (watchdog_active(&db8500_wdt)) {
  90. db8500_wdt_stop(&db8500_wdt);
  91. prcmu_config_a9wdog(PRCMU_WDOG_CPU1, true);
  92. prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
  93. db8500_wdt_start(&db8500_wdt);
  94. }
  95. return 0;
  96. }
  97. static int db8500_wdt_resume(struct platform_device *pdev)
  98. {
  99. if (watchdog_active(&db8500_wdt)) {
  100. db8500_wdt_stop(&db8500_wdt);
  101. prcmu_config_a9wdog(PRCMU_WDOG_CPU1, false);
  102. prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
  103. db8500_wdt_start(&db8500_wdt);
  104. }
  105. return 0;
  106. }
  107. #else
  108. #define db8500_wdt_suspend NULL
  109. #define db8500_wdt_resume NULL
  110. #endif
  111. static struct platform_driver db8500_wdt_driver = {
  112. .probe = db8500_wdt_probe,
  113. .suspend = db8500_wdt_suspend,
  114. .resume = db8500_wdt_resume,
  115. .driver = {
  116. .name = "db8500_wdt",
  117. },
  118. };
  119. module_platform_driver(db8500_wdt_driver);
  120. MODULE_AUTHOR("Jonas Aaberg <[email protected]>");
  121. MODULE_DESCRIPTION("DB8500 Watchdog Driver");
  122. MODULE_LICENSE("GPL");
  123. MODULE_ALIAS("platform:db8500_wdt");