ep93xx_wdt.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Watchdog driver for Cirrus Logic EP93xx family of devices.
  3. *
  4. * Copyright (c) 2004 Ray Lehtiniemi
  5. * Copyright (c) 2006 Tower Technologies
  6. * Based on ep93xx driver, bits from alim7101_wdt.c
  7. *
  8. * Authors: Ray Lehtiniemi <rayl@mail.com>,
  9. * Alessandro Zummo <a.zummo@towertech.it>
  10. *
  11. * Copyright (c) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
  12. * Convert to a platform device and use the watchdog framework API
  13. *
  14. * This file is licensed under the terms of the GNU General Public
  15. * License version 2. This program is licensed "as is" without any
  16. * warranty of any kind, whether express or implied.
  17. *
  18. * This watchdog fires after 250msec, which is a too short interval
  19. * for us to rely on the user space daemon alone. So we ping the
  20. * wdt each ~200msec and eventually stop doing it if the user space
  21. * daemon dies.
  22. */
  23. #include <linux/platform_device.h>
  24. #include <linux/module.h>
  25. #include <linux/watchdog.h>
  26. #include <linux/io.h>
  27. /* default timeout (secs) */
  28. #define WDT_TIMEOUT 30
  29. static bool nowayout = WATCHDOG_NOWAYOUT;
  30. module_param(nowayout, bool, 0);
  31. MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
  32. static unsigned int timeout;
  33. module_param(timeout, uint, 0);
  34. MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds.");
  35. #define EP93XX_WATCHDOG 0x00
  36. #define EP93XX_WDSTATUS 0x04
  37. struct ep93xx_wdt_priv {
  38. void __iomem *mmio;
  39. struct watchdog_device wdd;
  40. };
  41. static int ep93xx_wdt_start(struct watchdog_device *wdd)
  42. {
  43. struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
  44. writel(0xaaaa, priv->mmio + EP93XX_WATCHDOG);
  45. return 0;
  46. }
  47. static int ep93xx_wdt_stop(struct watchdog_device *wdd)
  48. {
  49. struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
  50. writel(0xaa55, priv->mmio + EP93XX_WATCHDOG);
  51. return 0;
  52. }
  53. static int ep93xx_wdt_ping(struct watchdog_device *wdd)
  54. {
  55. struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
  56. writel(0x5555, priv->mmio + EP93XX_WATCHDOG);
  57. return 0;
  58. }
  59. static const struct watchdog_info ep93xx_wdt_ident = {
  60. .options = WDIOF_CARDRESET |
  61. WDIOF_SETTIMEOUT |
  62. WDIOF_MAGICCLOSE |
  63. WDIOF_KEEPALIVEPING,
  64. .identity = "EP93xx Watchdog",
  65. };
  66. static const struct watchdog_ops ep93xx_wdt_ops = {
  67. .owner = THIS_MODULE,
  68. .start = ep93xx_wdt_start,
  69. .stop = ep93xx_wdt_stop,
  70. .ping = ep93xx_wdt_ping,
  71. };
  72. static int ep93xx_wdt_probe(struct platform_device *pdev)
  73. {
  74. struct device *dev = &pdev->dev;
  75. struct ep93xx_wdt_priv *priv;
  76. struct watchdog_device *wdd;
  77. unsigned long val;
  78. int ret;
  79. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  80. if (!priv)
  81. return -ENOMEM;
  82. priv->mmio = devm_platform_ioremap_resource(pdev, 0);
  83. if (IS_ERR(priv->mmio))
  84. return PTR_ERR(priv->mmio);
  85. val = readl(priv->mmio + EP93XX_WATCHDOG);
  86. wdd = &priv->wdd;
  87. wdd->bootstatus = (val & 0x01) ? WDIOF_CARDRESET : 0;
  88. wdd->info = &ep93xx_wdt_ident;
  89. wdd->ops = &ep93xx_wdt_ops;
  90. wdd->min_timeout = 1;
  91. wdd->max_hw_heartbeat_ms = 200;
  92. wdd->parent = dev;
  93. watchdog_set_nowayout(wdd, nowayout);
  94. wdd->timeout = WDT_TIMEOUT;
  95. watchdog_init_timeout(wdd, timeout, dev);
  96. watchdog_set_drvdata(wdd, priv);
  97. ret = devm_watchdog_register_device(dev, wdd);
  98. if (ret)
  99. return ret;
  100. dev_info(dev, "EP93XX watchdog driver %s\n",
  101. (val & 0x08) ? " (nCS1 disable detected)" : "");
  102. return 0;
  103. }
  104. static struct platform_driver ep93xx_wdt_driver = {
  105. .driver = {
  106. .name = "ep93xx-wdt",
  107. },
  108. .probe = ep93xx_wdt_probe,
  109. };
  110. module_platform_driver(ep93xx_wdt_driver);
  111. MODULE_AUTHOR("Ray Lehtiniemi <rayl@mail.com>");
  112. MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
  113. MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
  114. MODULE_DESCRIPTION("EP93xx Watchdog");
  115. MODULE_LICENSE("GPL");