0001
0002
0003
0004
0005
0006
0007
0008
0009 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0010
0011 #include <linux/module.h>
0012 #include <linux/kernel.h>
0013 #include <linux/moduleparam.h>
0014 #include <linux/err.h>
0015 #include <linux/uaccess.h>
0016 #include <linux/watchdog.h>
0017 #include <linux/platform_device.h>
0018
0019 #include <linux/mfd/dbx500-prcmu.h>
0020
0021 #define WATCHDOG_TIMEOUT 600
0022
0023 #define WATCHDOG_MIN 0
0024 #define WATCHDOG_MAX28 268435
0025
0026 static unsigned int timeout = WATCHDOG_TIMEOUT;
0027 module_param(timeout, uint, 0);
0028 MODULE_PARM_DESC(timeout,
0029 "Watchdog timeout in seconds. default="
0030 __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
0031
0032 static bool nowayout = WATCHDOG_NOWAYOUT;
0033 module_param(nowayout, bool, 0);
0034 MODULE_PARM_DESC(nowayout,
0035 "Watchdog cannot be stopped once started (default="
0036 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
0037
0038 static int db8500_wdt_start(struct watchdog_device *wdd)
0039 {
0040 return prcmu_enable_a9wdog(PRCMU_WDOG_ALL);
0041 }
0042
0043 static int db8500_wdt_stop(struct watchdog_device *wdd)
0044 {
0045 return prcmu_disable_a9wdog(PRCMU_WDOG_ALL);
0046 }
0047
0048 static int db8500_wdt_keepalive(struct watchdog_device *wdd)
0049 {
0050 return prcmu_kick_a9wdog(PRCMU_WDOG_ALL);
0051 }
0052
0053 static int db8500_wdt_set_timeout(struct watchdog_device *wdd,
0054 unsigned int timeout)
0055 {
0056 db8500_wdt_stop(wdd);
0057 prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
0058 db8500_wdt_start(wdd);
0059
0060 return 0;
0061 }
0062
0063 static const struct watchdog_info db8500_wdt_info = {
0064 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
0065 .identity = "DB8500 WDT",
0066 .firmware_version = 1,
0067 };
0068
0069 static const struct watchdog_ops db8500_wdt_ops = {
0070 .owner = THIS_MODULE,
0071 .start = db8500_wdt_start,
0072 .stop = db8500_wdt_stop,
0073 .ping = db8500_wdt_keepalive,
0074 .set_timeout = db8500_wdt_set_timeout,
0075 };
0076
0077 static struct watchdog_device db8500_wdt = {
0078 .info = &db8500_wdt_info,
0079 .ops = &db8500_wdt_ops,
0080 .min_timeout = WATCHDOG_MIN,
0081 .max_timeout = WATCHDOG_MAX28,
0082 };
0083
0084 static int db8500_wdt_probe(struct platform_device *pdev)
0085 {
0086 struct device *dev = &pdev->dev;
0087 int ret;
0088
0089 timeout = 600;
0090 db8500_wdt.parent = dev;
0091 watchdog_set_nowayout(&db8500_wdt, nowayout);
0092
0093
0094 prcmu_config_a9wdog(PRCMU_WDOG_CPU1, false);
0095
0096
0097 prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
0098
0099 ret = devm_watchdog_register_device(dev, &db8500_wdt);
0100 if (ret)
0101 return ret;
0102
0103 dev_info(dev, "initialized\n");
0104
0105 return 0;
0106 }
0107
0108 #ifdef CONFIG_PM
0109 static int db8500_wdt_suspend(struct platform_device *pdev,
0110 pm_message_t state)
0111 {
0112 if (watchdog_active(&db8500_wdt)) {
0113 db8500_wdt_stop(&db8500_wdt);
0114 prcmu_config_a9wdog(PRCMU_WDOG_CPU1, true);
0115
0116 prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
0117 db8500_wdt_start(&db8500_wdt);
0118 }
0119 return 0;
0120 }
0121
0122 static int db8500_wdt_resume(struct platform_device *pdev)
0123 {
0124 if (watchdog_active(&db8500_wdt)) {
0125 db8500_wdt_stop(&db8500_wdt);
0126 prcmu_config_a9wdog(PRCMU_WDOG_CPU1, false);
0127
0128 prcmu_load_a9wdog(PRCMU_WDOG_ALL, timeout * 1000);
0129 db8500_wdt_start(&db8500_wdt);
0130 }
0131 return 0;
0132 }
0133 #else
0134 #define db8500_wdt_suspend NULL
0135 #define db8500_wdt_resume NULL
0136 #endif
0137
0138 static struct platform_driver db8500_wdt_driver = {
0139 .probe = db8500_wdt_probe,
0140 .suspend = db8500_wdt_suspend,
0141 .resume = db8500_wdt_resume,
0142 .driver = {
0143 .name = "db8500_wdt",
0144 },
0145 };
0146
0147 module_platform_driver(db8500_wdt_driver);
0148
0149 MODULE_AUTHOR("Jonas Aaberg <jonas.aberg@stericsson.com>");
0150 MODULE_DESCRIPTION("DB8500 Watchdog Driver");
0151 MODULE_LICENSE("GPL");
0152 MODULE_ALIAS("platform:db8500_wdt");