]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/commitdiff
watchdog: max77620: add sysfs to enable/disable WDT on suspend
authorLaxman Dewangan <ldewangan@nvidia.com>
Fri, 3 Jul 2015 08:14:51 +0000 (13:44 +0530)
committerLaxman Dewangan <ldewangan@nvidia.com>
Wed, 8 Jul 2015 07:14:39 +0000 (00:14 -0700)
Add support to enable/disable watchdog on suspend although it
is enabled on boottime.

This will help to dynamically change the property of watchdog.

Sysfs path: /sys/devices/platform/7000d000.i2c/i2c-4/4-003c/max77620-wdt.5
Sysfs file: watchdog_suspend_state
$ cat watchdog_suspend_state
disable
$ echo enable > watchdog_suspend_state
$ cat watchdog_suspend_state
enable
$ echo disable > watchdog_suspend_state
$ cat atchdog_suspend_state
disable

bug 200120580

Change-Id: I06f0188bf655f77e6ba29fa8d1d25567cf69cabc
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-by: Robert Shih <rshih@nvidia.com>
(cherry picked from commit 4504f04c575d5c744f3b8fd867bb4dad3dfa9cb6)
Reviewed-on: http://git-master/r/767157

drivers/watchdog/max77620_wdt.c

index 40569b68a0c2d9b235ecb8014cec59e20e23452b..843d7ca865d5c85e7a24ea7e74161646de37b7a0 100644 (file)
@@ -50,6 +50,7 @@ struct max77620_wdt {
        bool                            otp_wdten;
        bool                            enable_on_off;
        int                             suspend_timeout;
+       int                             org_suspend_timeout;
        int                             current_timeout;
        int                             resume_timeout;
        struct delayed_work             clear_wdt_wq;
@@ -264,6 +265,41 @@ static const struct watchdog_ops max77620_wdt_ops = {
        .set_timeout = max77620_wdt_set_timeout,
 };
 
+static ssize_t show_wdt_suspend_state(struct device *dev,
+                struct device_attribute *attr, char *buf)
+{
+       struct max77620_wdt *wdt = dev_get_drvdata(dev);
+
+        return sprintf(buf, "%s",
+                       (wdt->suspend_timeout) ? "enable\n" : "disable\n");
+}
+
+static ssize_t set_wdt_suspend_state(struct device *dev,
+                struct device_attribute *attr, const char *buf, size_t count)
+{
+       struct max77620_wdt *wdt = dev_get_drvdata(dev);
+       int enable;
+        char *p = (char *)buf;
+       char ch = *p;
+
+       if ((ch == 'e') || (ch == 'E'))
+               enable = 1;
+       else if ((ch == 'd') || (ch == 'D'))
+               enable = 0;
+       else
+               return -EINVAL;
+
+       if (enable)
+               wdt->suspend_timeout = wdt->org_suspend_timeout;
+       else
+               wdt->suspend_timeout = 0;
+
+       alarmtimer_set_maximum_wakeup_interval_time(wdt->suspend_timeout);
+        return count;
+}
+static DEVICE_ATTR(watchdog_suspend_state, 0644, show_wdt_suspend_state,
+                       set_wdt_suspend_state);
+
 static int max77620_wdt_probe(struct platform_device *pdev)
 {
        struct max77620_wdt *wdt;
@@ -325,6 +361,8 @@ static int max77620_wdt_probe(struct platform_device *pdev)
        wdt_dev->min_timeout = 2;
        wdt_dev->max_timeout = 128;
 
+       wdt->org_suspend_timeout = wdt->suspend_timeout;
+
        watchdog_set_nowayout(wdt_dev, nowayout);
        watchdog_set_drvdata(wdt_dev, wdt);
        platform_set_drvdata(pdev, wdt);
@@ -345,6 +383,10 @@ static int max77620_wdt_probe(struct platform_device *pdev)
                return ret;
        }
 
+       ret = device_create_file(&pdev->dev, &dev_attr_watchdog_suspend_state);
+       if (ret < 0)
+               dev_warn(&pdev->dev, "sysfs creation failed: %d\n", ret);
+
        /*Enable WD_RST_WK - WDT expire results in a restart*/
        ret = max77620_reg_update(wdt->chip->dev, MAX77620_PWR_SLAVE,
                MAX77620_REG_ONOFFCNFG2, MAX77620_ONOFFCNFG2_WD_RST_WK,
@@ -372,7 +414,8 @@ static int max77620_wdt_probe(struct platform_device *pdev)
                        dev_err(wdt->dev, "wdt stop failed: %d\n", ret);
                        goto scrub;
                }
-               return 0;
+               wdt->current_timeout = 0;
+               goto suspend_timeout;
        }
 
        ret = _max77620_wdt_set_timeout(wdt_dev, wdt->boot_timeout);
@@ -388,6 +431,7 @@ static int max77620_wdt_probe(struct platform_device *pdev)
        schedule_delayed_work(&wdt->clear_wdt_wq,
                        msecs_to_jiffies(wdt->clear_time * HZ));
 
+suspend_timeout:
        if (wdt->suspend_timeout) {
                int alarm_time = wdt->suspend_timeout;
                alarm_time = (alarm_time > 10) ? alarm_time - 10 : alarm_time;