21 #include <linux/module.h>
22 #include <linux/types.h>
23 #include <linux/slab.h>
24 #include <linux/kernel.h>
26 #include <linux/watchdog.h>
32 #define TWL4030_WATCHDOG_CFG_REG_OFFS 0x3
34 #define TWL4030_WDT_STATE_OPEN 0x1
35 #define TWL4030_WDT_STATE_ACTIVE 0x8
50 static int twl4030_wdt_write(
unsigned char val)
56 static int twl4030_wdt_enable(
struct twl4030_wdt *wdt)
61 static int twl4030_wdt_disable(
struct twl4030_wdt *wdt)
63 return twl4030_wdt_write(0);
66 static int twl4030_wdt_set_timeout(
struct twl4030_wdt *wdt,
int timeout)
68 if (timeout < 0 || timeout > 30) {
70 "Timeout can only be in the range [0-30] seconds");
74 return twl4030_wdt_enable(wdt);
78 const char __user *
data,
size_t len, loff_t *ppos)
83 twl4030_wdt_enable(wdt);
88 static long twl4030_wdt_ioctl(
struct file *file,
89 unsigned int cmd,
unsigned long arg)
99 .firmware_version = 0,
105 sizeof(twl4030_wd_ident)) ? -
EFAULT : 0;
112 twl4030_wdt_enable(wdt);
118 if (twl4030_wdt_set_timeout(wdt, new_margin))
132 static int twl4030_wdt_open(
struct inode *
inode,
struct file *file)
134 struct twl4030_wdt *wdt = platform_get_drvdata(twl4030_wdt_dev);
143 twl4030_wdt_enable(wdt);
147 static int twl4030_wdt_release(
struct inode *inode,
struct file *file)
152 "Unexpected close, watchdog still running!\n");
153 twl4030_wdt_enable(wdt);
155 if (twl4030_wdt_disable(wdt))
167 .open = twl4030_wdt_open,
168 .release = twl4030_wdt_release,
169 .unlocked_ioctl = twl4030_wdt_ioctl,
170 .write = twl4030_wdt_write_fop,
185 wdt->
miscdev.fops = &twl4030_wdt_fops;
187 wdt->
miscdev.name =
"watchdog";
189 platform_set_drvdata(pdev, wdt);
191 twl4030_wdt_dev = pdev;
193 twl4030_wdt_disable(wdt);
198 "Failed to register misc device\n");
199 platform_set_drvdata(pdev,
NULL);
201 twl4030_wdt_dev =
NULL;
209 struct twl4030_wdt *wdt = platform_get_drvdata(pdev);
212 if (twl4030_wdt_disable(wdt))
218 platform_set_drvdata(pdev,
NULL);
220 twl4030_wdt_dev =
NULL;
228 struct twl4030_wdt *wdt = platform_get_drvdata(pdev);
230 return twl4030_wdt_disable(wdt);
237 struct twl4030_wdt *wdt = platform_get_drvdata(pdev);
239 return twl4030_wdt_enable(wdt);
244 #define twl4030_wdt_suspend NULL
245 #define twl4030_wdt_resume NULL
249 .probe = twl4030_wdt_probe,
255 .name =
"twl4030_wdt",