watchdog: Add support for ux500_wdt watchdog
authorFabio Baltieri <fabio.baltieri@linaro.org>
Tue, 29 Jan 2013 08:57:19 +0000 (09:57 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Wed, 13 Feb 2013 23:22:53 +0000 (00:22 +0100)
This patch adds support for the ux500_wdt watchdog that is found in
ST-Ericsson Ux500 platform.  The driver is based on PRCMU APIs.

Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Lee Jones <lee.jones@linaro.org>
Acked-by: Wim Van Sebroeck <wim@iguana.be>
Signed-off-by: Fabio Baltieri <fabio.baltieri@linaro.org>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/watchdog/Kconfig
drivers/watchdog/Makefile
drivers/watchdog/ux500_wdt.c [new file with mode: 0644]
include/linux/platform_data/ux500_wdt.h [new file with mode: 0644]

index 7f809fd4a57f950c94c3d5d280fe471f60ebeaf4..26e1fdbddf690c88cd20dbf015955d6b13295a0a 100644 (file)
@@ -364,6 +364,18 @@ config IMX2_WDT
          To compile this driver as a module, choose M here: the
          module will be called imx2_wdt.
 
+config UX500_WATCHDOG
+       tristate "ST-Ericsson Ux500 watchdog"
+       depends on MFD_DB8500_PRCMU
+       select WATCHDOG_CORE
+       default y
+       help
+         Say Y here to include Watchdog timer support for the watchdog
+         existing in the prcmu of ST-Ericsson Ux500 series platforms.
+
+         To compile this driver as a module, choose M here: the
+         module will be called ux500_wdt.
+
 # AVR32 Architecture
 
 config AT32AP700X_WDT
index 97bbdb3a464844588fa97e526b89eb284f302145..bec86ee6e9e3a93f4d14494ec090d51b8dc1654c 100644 (file)
@@ -52,6 +52,7 @@ obj-$(CONFIG_STMP3XXX_WATCHDOG) += stmp3xxx_wdt.o
 obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
 obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o
 obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
+obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
 
 # AVR32 Architecture
 obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
diff --git a/drivers/watchdog/ux500_wdt.c b/drivers/watchdog/ux500_wdt.c
new file mode 100644 (file)
index 0000000..a614d84
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2011-2013
+ *
+ * License Terms: GNU General Public License v2
+ *
+ * Author: Mathieu Poirier <mathieu.poirier@linaro.org> for ST-Ericsson
+ * Author: Jonas Aaberg <jonas.aberg@stericsson.com> for ST-Ericsson
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/moduleparam.h>
+#include <linux/miscdevice.h>
+#include <linux/err.h>
+#include <linux/uaccess.h>
+#include <linux/watchdog.h>
+#include <linux/platform_device.h>
+#include <linux/platform_data/ux500_wdt.h>
+
+#include <linux/mfd/dbx500-prcmu.h>
+
+#define WATCHDOG_TIMEOUT 600 /* 10 minutes */
+
+#define WATCHDOG_MIN   0
+#define WATCHDOG_MAX28 268435  /* 28 bit resolution in ms == 268435.455 s */
+#define WATCHDOG_MAX32 4294967 /* 32 bit resolution in ms == 4294967.295 s */
+
+static unsigned int timeout = WATCHDOG_TIMEOUT;
+module_param(timeout, uint, 0);
+MODULE_PARM_DESC(timeout,
+       "Watchdog timeout in seconds. default="
+                               __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
+MODULE_PARM_DESC(nowayout,
+       "Watchdog cannot be stopped once started (default="
+                               __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+static int ux500_wdt_start(struct watchdog_device *wdd)
+{
+       return prcmu_enable_a9wdog(PRCMU_WDOG_ALL);
+}
+
+static int ux500_wdt_stop(struct watchdog_device *wdd)
+{
+       return prcmu_disable_a9wdog(PRCMU_WDOG_ALL);
+}
+
+static int ux500_wdt_keepalive(struct watchdog_device *wdd)
+{
+       return prcmu_kick_a9wdog(PRCMU_WDOG_ALL);
+}
+
+static int ux500_wdt_set_timeout(struct watchdog_device *wdd,
+                                unsigned int timeout)
+{
+       ux500_wdt_stop(wdd);
+       prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
+       ux500_wdt_start(wdd);
+
+       return 0;
+}
+
+static const struct watchdog_info ux500_wdt_info = {
+       .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+       .identity = "Ux500 WDT",
+       .firmware_version = 1,
+};
+
+static const struct watchdog_ops ux500_wdt_ops = {
+       .owner = THIS_MODULE,
+       .start = ux500_wdt_start,
+       .stop  = ux500_wdt_stop,
+       .ping  = ux500_wdt_keepalive,
+       .set_timeout = ux500_wdt_set_timeout,
+};
+
+static struct watchdog_device ux500_wdt = {
+       .info = &ux500_wdt_info,
+       .ops = &ux500_wdt_ops,
+       .min_timeout = WATCHDOG_MIN,
+       .max_timeout = WATCHDOG_MAX32,
+};
+
+static int ux500_wdt_probe(struct platform_device *pdev)
+{
+       int ret;
+       struct ux500_wdt_data *pdata = pdev->dev.platform_data;
+
+       if (pdata) {
+               if (pdata->timeout > 0)
+                       timeout = pdata->timeout;
+               if (pdata->has_28_bits_resolution)
+                       ux500_wdt.max_timeout = WATCHDOG_MAX28;
+       }
+
+       watchdog_set_nowayout(&ux500_wdt, nowayout);
+
+       /* disable auto off on sleep */
+       prcmu_config_a9wdog(PRCMU_WDOG_CPU1, false);
+
+       /* set HW initial value */
+       prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
+
+       ret = watchdog_register_device(&ux500_wdt);
+       if (ret)
+               return ret;
+
+       dev_info(&pdev->dev, "initialized\n");
+
+       return 0;
+}
+
+static int ux500_wdt_remove(struct platform_device *dev)
+{
+       watchdog_unregister_device(&ux500_wdt);
+
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int ux500_wdt_suspend(struct platform_device *pdev,
+                            pm_message_t state)
+{
+       if (watchdog_active(&ux500_wdt)) {
+               ux500_wdt_stop(&ux500_wdt);
+               prcmu_config_a9wdog(PRCMU_WDOG_CPU1, true);
+
+               prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
+               ux500_wdt_start(&ux500_wdt);
+       }
+       return 0;
+}
+
+static int ux500_wdt_resume(struct platform_device *pdev)
+{
+       if (watchdog_active(&ux500_wdt)) {
+               ux500_wdt_stop(&ux500_wdt);
+               prcmu_config_a9wdog(PRCMU_WDOG_CPU1, false);
+
+               prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
+               ux500_wdt_start(&ux500_wdt);
+       }
+       return 0;
+}
+#else
+#define ux500_wdt_suspend NULL
+#define ux500_wdt_resume NULL
+#endif
+
+static struct platform_driver ux500_wdt_driver = {
+       .probe          = ux500_wdt_probe,
+       .remove         = ux500_wdt_remove,
+       .suspend        = ux500_wdt_suspend,
+       .resume         = ux500_wdt_resume,
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = "ux500_wdt",
+       },
+};
+
+module_platform_driver(ux500_wdt_driver);
+
+MODULE_AUTHOR("Jonas Aaberg <jonas.aberg@stericsson.com>");
+MODULE_DESCRIPTION("Ux500 Watchdog Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
+MODULE_ALIAS("platform:ux500_wdt");
diff --git a/include/linux/platform_data/ux500_wdt.h b/include/linux/platform_data/ux500_wdt.h
new file mode 100644 (file)
index 0000000..1689ff4
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) ST Ericsson SA 2011
+ *
+ * License Terms: GNU General Public License v2
+ *
+ * STE Ux500 Watchdog platform data
+ */
+#ifndef __UX500_WDT_H
+#define __UX500_WDT_H
+
+/**
+ * struct ux500_wdt_data
+ */
+struct ux500_wdt_data {
+       unsigned int timeout;
+       bool has_28_bits_resolution;
+};
+
+#endif /* __UX500_WDT_H */