ux500_wdt.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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/miscdevice.h>
  14. #include <linux/err.h>
  15. #include <linux/uaccess.h>
  16. #include <linux/watchdog.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/platform_data/ux500_wdt.h>
  19. #include <linux/mfd/dbx500-prcmu.h>
  20. #define WATCHDOG_TIMEOUT 600 /* 10 minutes */
  21. #define WATCHDOG_MIN 0
  22. #define WATCHDOG_MAX28 268435 /* 28 bit resolution in ms == 268435.455 s */
  23. #define WATCHDOG_MAX32 4294967 /* 32 bit resolution in ms == 4294967.295 s */
  24. static unsigned int timeout = WATCHDOG_TIMEOUT;
  25. module_param(timeout, uint, 0);
  26. MODULE_PARM_DESC(timeout,
  27. "Watchdog timeout in seconds. default="
  28. __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
  29. static bool nowayout = WATCHDOG_NOWAYOUT;
  30. module_param(nowayout, bool, 0);
  31. MODULE_PARM_DESC(nowayout,
  32. "Watchdog cannot be stopped once started (default="
  33. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  34. static int ux500_wdt_start(struct watchdog_device *wdd)
  35. {
  36. return prcmu_enable_a9wdog(PRCMU_WDOG_ALL);
  37. }
  38. static int ux500_wdt_stop(struct watchdog_device *wdd)
  39. {
  40. return prcmu_disable_a9wdog(PRCMU_WDOG_ALL);
  41. }
  42. static int ux500_wdt_keepalive(struct watchdog_device *wdd)
  43. {
  44. return prcmu_kick_a9wdog(PRCMU_WDOG_ALL);
  45. }
  46. static int ux500_wdt_set_timeout(struct watchdog_device *wdd,
  47. unsigned int timeout)
  48. {
  49. ux500_wdt_stop(wdd);
  50. prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
  51. ux500_wdt_start(wdd);
  52. return 0;
  53. }
  54. static const struct watchdog_info ux500_wdt_info = {
  55. .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
  56. .identity = "Ux500 WDT",
  57. .firmware_version = 1,
  58. };
  59. static const struct watchdog_ops ux500_wdt_ops = {
  60. .owner = THIS_MODULE,
  61. .start = ux500_wdt_start,
  62. .stop = ux500_wdt_stop,
  63. .ping = ux500_wdt_keepalive,
  64. .set_timeout = ux500_wdt_set_timeout,
  65. };
  66. static struct watchdog_device ux500_wdt = {
  67. .info = &ux500_wdt_info,
  68. .ops = &ux500_wdt_ops,
  69. .min_timeout = WATCHDOG_MIN,
  70. .max_timeout = WATCHDOG_MAX32,
  71. };
  72. static int ux500_wdt_probe(struct platform_device *pdev)
  73. {
  74. int ret;
  75. struct ux500_wdt_data *pdata = pdev->dev.platform_data;
  76. if (pdata) {
  77. if (pdata->timeout > 0)
  78. timeout = pdata->timeout;
  79. if (pdata->has_28_bits_resolution)
  80. ux500_wdt.max_timeout = WATCHDOG_MAX28;
  81. }
  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. .owner = THIS_MODULE,
  131. .name = "ux500_wdt",
  132. },
  133. };
  134. module_platform_driver(ux500_wdt_driver);
  135. MODULE_AUTHOR("Jonas Aaberg <jonas.aberg@stericsson.com>");
  136. MODULE_DESCRIPTION("Ux500 Watchdog Driver");
  137. MODULE_LICENSE("GPL");
  138. MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  139. MODULE_ALIAS("platform:ux500_wdt");