0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/module.h>
0009 #include <linux/types.h>
0010 #include <linux/slab.h>
0011 #include <linux/kernel.h>
0012 #include <linux/watchdog.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/mfd/twl.h>
0015
0016 #define TWL4030_WATCHDOG_CFG_REG_OFFS 0x3
0017
0018 static bool nowayout = WATCHDOG_NOWAYOUT;
0019 module_param(nowayout, bool, 0);
0020 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
0021 "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
0022
0023 static int twl4030_wdt_write(unsigned char val)
0024 {
0025 return twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, val,
0026 TWL4030_WATCHDOG_CFG_REG_OFFS);
0027 }
0028
0029 static int twl4030_wdt_start(struct watchdog_device *wdt)
0030 {
0031 return twl4030_wdt_write(wdt->timeout + 1);
0032 }
0033
0034 static int twl4030_wdt_stop(struct watchdog_device *wdt)
0035 {
0036 return twl4030_wdt_write(0);
0037 }
0038
0039 static int twl4030_wdt_set_timeout(struct watchdog_device *wdt,
0040 unsigned int timeout)
0041 {
0042 wdt->timeout = timeout;
0043 return 0;
0044 }
0045
0046 static const struct watchdog_info twl4030_wdt_info = {
0047 .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
0048 .identity = "TWL4030 Watchdog",
0049 };
0050
0051 static const struct watchdog_ops twl4030_wdt_ops = {
0052 .owner = THIS_MODULE,
0053 .start = twl4030_wdt_start,
0054 .stop = twl4030_wdt_stop,
0055 .set_timeout = twl4030_wdt_set_timeout,
0056 };
0057
0058 static int twl4030_wdt_probe(struct platform_device *pdev)
0059 {
0060 struct device *dev = &pdev->dev;
0061 struct watchdog_device *wdt;
0062
0063 wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
0064 if (!wdt)
0065 return -ENOMEM;
0066
0067 wdt->info = &twl4030_wdt_info;
0068 wdt->ops = &twl4030_wdt_ops;
0069 wdt->status = 0;
0070 wdt->timeout = 30;
0071 wdt->min_timeout = 1;
0072 wdt->max_timeout = 30;
0073 wdt->parent = dev;
0074
0075 watchdog_set_nowayout(wdt, nowayout);
0076 platform_set_drvdata(pdev, wdt);
0077
0078 twl4030_wdt_stop(wdt);
0079
0080 return devm_watchdog_register_device(dev, wdt);
0081 }
0082
0083 #ifdef CONFIG_PM
0084 static int twl4030_wdt_suspend(struct platform_device *pdev, pm_message_t state)
0085 {
0086 struct watchdog_device *wdt = platform_get_drvdata(pdev);
0087 if (watchdog_active(wdt))
0088 return twl4030_wdt_stop(wdt);
0089
0090 return 0;
0091 }
0092
0093 static int twl4030_wdt_resume(struct platform_device *pdev)
0094 {
0095 struct watchdog_device *wdt = platform_get_drvdata(pdev);
0096 if (watchdog_active(wdt))
0097 return twl4030_wdt_start(wdt);
0098
0099 return 0;
0100 }
0101 #else
0102 #define twl4030_wdt_suspend NULL
0103 #define twl4030_wdt_resume NULL
0104 #endif
0105
0106 static const struct of_device_id twl_wdt_of_match[] = {
0107 { .compatible = "ti,twl4030-wdt", },
0108 { },
0109 };
0110 MODULE_DEVICE_TABLE(of, twl_wdt_of_match);
0111
0112 static struct platform_driver twl4030_wdt_driver = {
0113 .probe = twl4030_wdt_probe,
0114 .suspend = twl4030_wdt_suspend,
0115 .resume = twl4030_wdt_resume,
0116 .driver = {
0117 .name = "twl4030_wdt",
0118 .of_match_table = twl_wdt_of_match,
0119 },
0120 };
0121
0122 module_platform_driver(twl4030_wdt_driver);
0123
0124 MODULE_AUTHOR("Nokia Corporation");
0125 MODULE_LICENSE("GPL");
0126 MODULE_ALIAS("platform:twl4030_wdt");
0127