mfd: as3722: add watchdog support
Subsystems (2)
PATCH 1/2 mfd: as3722: add watchdog support
Add watchdog device support for as3722
--- drivers/mfd/as3722.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mfd/as3722.c +3 -0
@@ -74,6 +74,9 @@ static struct mfd_cell as3722_devs[] = { { .name = "as3722-power-off", }, + { + .name = "as3722-wdt", + }, }; static const struct regmap_irq as3722_irqs[] = {
Signature · 1 line
1.8.1.5
PATCH 2/2 watchdog: as3722_wdt: support for AMS AS3722
Add watchdog timer driver for as3722 device. The timer can be start/stop and set timing through watchdog subsystem callbacks.
--- drivers/watchdog/Kconfig | 9 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/as3722_wdt.c | 300 ++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/as3722.h | 1 + 4 files changed, 311 insertions(+) create mode 100644 drivers/watchdog/as3722_wdt.c
drivers/watchdog/Kconfig +9 -0
@@ -53,6 +53,15 @@ comment "Watchdog Device Drivers" # Architecture Independent +config AS3722_WATCHDOG + tristate "AS3722 watchdog" + depends on MFD_AS3722 + select WATCHDOG_CORE + help + Support for the watchdog in the AMS AS3722 PMIC. When + the watchdog triggers the system will be reset/Off based on + configuration. + config SOFT_WATCHDOG tristate "Software watchdog" select WATCHDOG_CORE
drivers/watchdog/Makefile +1 -0
@@ -169,6 +169,7 @@ obj-$(CONFIG_WATCHDOG_CP1XXX) += cpwd.o obj-$(CONFIG_XEN_WDT) += xen_wdt.o # Architecture Independent +obj-$(CONFIG_AS3722_WATCHDOG) += as3722_wdt.o obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o obj-$(CONFIG_DA9055_WATCHDOG) += da9055_wdt.o obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o
drivers/watchdog/as3722_wdt.c new file +300 -0
300 lines not on this page · raw message
include/linux/mfd/as3722.h +1 -0
@@ -336,6 +336,7 @@#define AS3722_WATCHDOG_TIMER_MAX 0x7F#define AS3722_WATCHDOG_ON BIT(0)#define AS3722_WATCHDOG_SW_SIG BIT(0) +#define AS3722_WATCHDOG_MODE_MASK 0x06#define AS3722_EXT_CONTROL_ENABLE1 0x1#define AS3722_EXT_CONTROL_ENABLE2 0x2
Signature · 1 line
1.8.1.5
Guenter Roeck
maintainerRe: [PATCH 2/2] watchdog: as3722_wdt: support for AMS AS3722
Quoted 5 lines · Bibek Basu
Add watchdog timer driver for as3722 device. The timer can be start/stop and set timing through watchdog subsystem callbacks.
Change-Id: I5e252fd762764afaa1598cd98fed91864dc23d8d
Is this a new standard tag ? If not it should go.
Quoted 6 lines
Signed-off-by Bibek Basu <[email protected]>--- drivers/watchdog/Kconfig | 9 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/as3722_wdt.c | 300 ++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/as3722.h | 1 +
There is no bindings document.
Quoted 8 lines
4 files changed, 311 insertions(+)create mode 100644
drivers/watchdog/as3722_wdt.cdrivers/watchdog/Kconfig +0
-0
drivers/watchdog/Kconfig comment "Watchdog Device Drivers" · line 62
Quoted 10 lines
drivers/watchdog/Kconfig +7
-0@@ -53,6 +53,15 @@ comment "Watchdog Device Drivers" # Architecture Independent +config AS3722_WATCHDOG + tristate "AS3722 watchdog" + depends on MFD_AS3722 + select WATCHDOG_CORE + help + Support for the watchdog in the AMS AS3722 PMIC. When + the watchdog triggers the system will be reset/Off based on
triggers, reset/Off -> reset / turned off ?
Which configuration ?
drivers/watchdog/Kconfig comment "Watchdog Device Drivers" · line 64
Quoted 2 lines
drivers/watchdog/Kconfig +2
-0+ configuration. +
Unlikely that this watchdog is architecture independent.
Quoted 68 lines
drivers/watchdog/Kconfig +0
-0config SOFT_WATCHDOG tristate "Software watchdog" select WATCHDOG_COREdrivers/watchdog/Makefile +1
-0@@ -169,6 +169,7 @@ obj-$(CONFIG_WATCHDOG_CP1XXX) += cpwd.o obj-$(CONFIG_XEN_WDT) += xen_wdt.o # Architecture Independent +obj-$(CONFIG_AS3722_WATCHDOG) += as3722_wdt.o obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o obj-$(CONFIG_DA9055_WATCHDOG) += da9055_wdt.o obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.odrivers/watchdog/as3722_wdt.c new file +47
-0@@ -0,0 +1,300 @@ +/* +* as3722_wdt.c -- AS3722 Watchdog Timer. +* +* Watchdog timer for AS3722 PMIC. +* +* Copyright (c) 2013, NVIDIA Corporation. All rights reserved. +* +* Author: Bibek Basu <[email protected]> +* based on Palmas_wdt driver (c) Laxman Dewangan , 2013 +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation version 2. +* +* This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, +* whether express or implied; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +*/ +#include <linux/device.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mfd/as3722.h> +#include <linux/platform_device.h> +#include <linux/pm.h> +#include <linux/slab.h> +#include <linux/watchdog.h> +#include <linux/of.h> + +static bool nowayout =WATCHDOG_NOWAYOUT ; + +struct as3722_wdt { +struct watchdog_device wdt_dev; +struct device *dev; +struct as3722 *as3722; +int timeout; +int irq; +int timer_initial_period; +int timer_mode; +}; + +static irqreturn_t as3722_wdt_irq (int irq,void *data)
drivers/watchdog/as3722_wdt.c line 57
Quoted 10 lines
drivers/watchdog/as3722_wdt.c new file +10
-0+{ +struct as3722_wdt *wdt = data; +int ret; + + ret =as3722_update_bits (wdt->as3722, +AS3722_WATCHDOG_SOFTWARE_SIGNAL_REG , +AS3722_WATCHDOG_SW_SIG ,AS3722_WATCHDOG_SW_SIG ); +if (ret <0 ) +dev_err (wdt->dev,"WATCHDOG kick failed: %d\n" , ret); +dev_info (wdt->dev,"WDT interrupt occur\n" );
I don't see any value in all this noisiness. In my opinion, the driver should only create error messages during initialization. In all other instances, errors should be passed back to userspace. And error messages in interrupt code just ask for trouble.
I am curious - what is this function doing anyway ? I think a brief explanation might be in order.
Quoted 54 lines
drivers/watchdog/as3722_wdt.c new file +54
-0+return IRQ_HANDLED ; +} + +static int as3722_wdt_start (struct watchdog_device *wdt_dev) +{ +struct as3722_wdt *wdt =watchdog_get_drvdata (wdt_dev); +int ret; + + ret =as3722_update_bits (wdt->as3722,AS3722_WATCHDOG_CONTROL_REG , +AS3722_WATCHDOG_ON ,AS3722_WATCHDOG_ON ); +if (ret <0 ) { +dev_err (wdt->dev,"WATCHDOG update failed: %d\n" , ret); +return ret; + } +return 0 ; +} + +static int as3722_wdt_stop (struct watchdog_device *wdt_dev) +{ +struct as3722_wdt *wdt =watchdog_get_drvdata (wdt_dev); +int ret; + + ret =as3722_update_bits (wdt->as3722,AS3722_WATCHDOG_CONTROL_REG , +AS3722_WATCHDOG_ON ,0 ); +if (ret <0 ) { +dev_err (wdt->dev,"WATCHDOG update failed: %d\n" , ret); +return ret; + } +return 0 ; +} + +static int as3722_wdt_set_timeout (struct watchdog_device *wdt_dev, +unsigned int timeout) +{ +struct as3722_wdt *wdt =watchdog_get_drvdata (wdt_dev); +int ret; +unsigned int val = timeout -1 ; + + ret =as3722_update_bits (wdt->as3722,AS3722_WATCHDOG_TIMER_REG , +AS3722_WATCHDOG_TIMER_MAX , val); +if (ret <0 ) { +dev_err (wdt->dev,"WATCHDOG update failed: %d\n" , ret); +return ret; + } + wdt->timeout = timeout; +return 0 ; +} + +static const struct watchdog_info as3722_wdt_info = { + .options =WDIOF_SETTIMEOUT |WDIOF_MAGICCLOSE , + .identity ="AS3722 Watchdog" , +}; + +static const struct watchdog_ops as3722_wdt_ops = {
drivers/watchdog/as3722_wdt.c line 121
Quoted 10 lines
drivers/watchdog/as3722_wdt.c new file +10
-0+ .owner = THIS_MODULE, + .start = as3722_wdt_start, + .stop = as3722_wdt_stop, + .set_timeout = as3722_wdt_set_timeout, +}; + +#ifdef CONFIG_OF +static int as3722_parse_dt_wdt_data ( +struct platform_device *pdev, +struct as3722_wdt *wdt)
Continuation lines should be aligned with (, and there should be no unnecessary ones.
drivers/watchdog/as3722_wdt.c line 126
Quoted 5 lines
drivers/watchdog/as3722_wdt.c new file +5
-0+{ +struct device_node *np = pdev->dev.of_node; +const __be32 *prop; + + prop =of_get_property (np,"ams,timer_initial_period" ,NULL );
Any reason for not using of_property_read_u32 ?
drivers/watchdog/as3722_wdt.c line 129
Quoted 3 lines
drivers/watchdog/as3722_wdt.c new file +3
-0+if (prop) + wdt->timer_initial_period =be32_to_cpu (*prop); +
Seems to me that such a property (and the related code) should be made generic, to apply to all watchdog drivers.
Also, I think the driver should support the standard timeout property.
drivers/watchdog/as3722_wdt.c line 132
Quoted 3 lines
drivers/watchdog/as3722_wdt.c new file +3
-0+ prop =of_get_property (np,"ams,timer_mode" ,NULL ); +if (prop) + wdt->timer_mode =be32_to_cpu (*prop);
Extra space after =.
Also, you might want to do some value checking.
Quoted 41 lines
drivers/watchdog/as3722_wdt.c new file +41
-0+ else + wdt->timer_mode = -1; +return 0 ; +} +#else +static inline int as3722_parse_dt_wdt_data ( +struct platform_device *pdev, +struct as3722_wdt *wdt) +{ +return 0 ; +} +#endif + +static int as3722_wdt_probe (struct platform_device *pdev) +{ +struct as3722 *as3722 =dev_get_drvdata (pdev->dev.parent); +struct as3722_wdt *wdt; +struct watchdog_device *wdt_dev; +int ret; + + wdt =devm_kzalloc (&pdev->dev,sizeof (*wdt),GFP_KERNEL ); +if (!wdt) +return -ENOMEM ; + +as3722_parse_dt_wdt_data (pdev, wdt); + wdt->dev = &pdev->dev; + wdt->as3722 = as3722; + wdt->irq =as3722_irq_get_virq (wdt->as3722,AS3722_IRQ_WATCHDOG ); + wdt_dev = &wdt->wdt_dev; + + wdt_dev->info = &as3722_wdt_info; + wdt_dev->ops = &as3722_wdt_ops; + wdt_dev->timeout =128 ; + wdt_dev->min_timeout =8 ; + wdt_dev->max_timeout =128 ; +watchdog_set_nowayout (wdt_dev, nowayout); +watchdog_set_drvdata (wdt_dev, wdt); +platform_set_drvdata (pdev, wdt); + + ret = request_threaded_irq(wdt->irq, NULL, as3722_wdt_irq, + IRQF_ONESHOT | IRQF_EARLY_RESUME,
drivers/watchdog/as3722_wdt.c line 183
Quoted 10 lines
drivers/watchdog/as3722_wdt.c new file +10
-0+ dev_name(&pdev->dev), wdt); +if (ret <0 ) { +dev_err (&pdev->dev,"request IRQ:%d failed, err = %d\n" , + wdt->irq, ret); +return ret; + } + + ret =watchdog_register_device (wdt_dev); +if (ret <0 ) { +dev_err (&pdev->dev,"watchdog registration failed: %d\n" , ret);
you might want to release the interrupt here.
Quoted 17 lines
drivers/watchdog/as3722_wdt.c new file +17
-0+return ret; + } + +/* set mode */ +if (wdt->timer_mode >=0 ) { + ret =as3722_update_bits (wdt->as3722, +AS3722_WATCHDOG_CONTROL_REG , +AS3722_WATCHDOG_MODE_MASK , wdt->timer_mode); +if (ret <0 ) { +dev_err (wdt->dev,"WATCHDOG update mode failed: %d\n" , + ret); + goto scrub; + } + } + +/* configure timer */ +if (wdt->timer_initial_period >0 ) {
drivers/watchdog/as3722_wdt.c line 210
Quoted 10 lines
drivers/watchdog/as3722_wdt.c new file +10
-0+ ret =as3722_wdt_set_timeout (wdt_dev, + wdt->timer_initial_period); +if (ret <0 ) { +dev_err (wdt->dev,"wdt set timeout failed: %d\n" , ret); + goto scrub; + } + ret =as3722_wdt_start (wdt_dev); +if (ret <0 ) { +dev_err (wdt->dev, +"wdt start failed: %d\n" , ret);
This continuation line seems quite unnecessary.
drivers/watchdog/as3722_wdt.c line 218
Quoted 8 lines
drivers/watchdog/as3722_wdt.c new file +8
-0+ goto scrub; + } + } + +device_set_wakeup_capable (&pdev->dev,1 ); +return 0 ; +scrub: +free_irq (wdt->irq, wdt);
If you free the interrupt before unregistering the hwmon device, you might want to request it after registering the hwmon device.
Quoted 13 lines
drivers/watchdog/as3722_wdt.c new file +13
-0+watchdog_unregister_device (&wdt->wdt_dev); +return ret; +} + +static int as3722_wdt_remove (struct platform_device *pdev) +{ +struct as3722_wdt *wdt =platform_get_drvdata (pdev); + +as3722_wdt_stop (&wdt->wdt_dev); +watchdog_unregister_device (&wdt->wdt_dev); +free_irq (wdt->irq, wdt); +return 0 ; +}
drivers/watchdog/as3722_wdt.c line 241
Quoted 10 lines
drivers/watchdog/as3722_wdt.c new file +10
-0+ +#ifdef CONFIG_PM_SLEEP +static int as3722_wdt_suspend (struct device *dev) +{ +struct as3722_wdt *wdt =dev_get_drvdata (dev); +int ret; + +if (device_may_wakeup (dev)) { +enable_irq_wake (wdt->irq); + }else if (wdt->timeout >0 ) {
Shouldn't you check if the watchdog is running instead ?
I understand that is the idea, but that isn't what it does. This value is 0 if and only if the watchdog timer was never updated, which is unrelated to its current status.
drivers/watchdog/as3722_wdt.c line 244
Quoted 3 lines
drivers/watchdog/as3722_wdt.c new file +3
-0+ ret =as3722_wdt_stop (&wdt->wdt_dev); +if (ret <0 ) +dev_err (wdt->dev,"wdt stop failed: %d\n" , ret);
Shouldn't this return the error ?
Quoted 5 lines
drivers/watchdog/as3722_wdt.c new file +5
-0+ } +return 0 ; +} + +static int as3722_wdt_resume (struct device *dev)
drivers/watchdog/as3722_wdt.c line 259
Quoted 10 lines
drivers/watchdog/as3722_wdt.c new file +10
-0+{ +struct as3722_wdt *wdt =dev_get_drvdata (dev); +int ret; + +if (device_may_wakeup (dev)) { +disable_irq_wake (wdt->irq); + }else if (wdt->timeout >0 ) { + ret =as3722_wdt_start (&wdt->wdt_dev); +if (ret <0 ) +dev_err (wdt->dev,"wdt start failed: %d\n" , ret);
Same here.
Quoted 8 lines
drivers/watchdog/as3722_wdt.c new file +8
-0+ } +return 0 ; +} +#endif + +static const struct dev_pm_ops as3722_wdt_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (as3722_wdt_suspend, as3722_wdt_resume) +};
drivers/watchdog/as3722_wdt.c line 277
Quoted 10 lines
drivers/watchdog/as3722_wdt.c new file +10
-0+ +static const struct of_device_id as3722_wdt_of_match[] = { + { .compatible ="ams,as3722-wdt" , }, + {/* end */ } +}; + +static struct platform_driver as3722_wdt_driver = { + .driver = { + .name ="as3722-wdt" , + .owner =THIS_MODULE ,
Inconsistent spacing. I would suggest to drop all the extra spaces.
Quoted 36 lines
drivers/watchdog/as3722_wdt.c new file +23
-0+ .pm = &as3722_wdt_pm_ops, + .of_match_table = as3722_wdt_of_match, + }, + .probe = as3722_wdt_probe, + .remove = as3722_wdt_remove, +}; + +static int __init as3722_wdt_init (void ) +{ +return platform_driver_register (&as3722_wdt_driver); +} +subsys_initcall (as3722_wdt_init); + +static void __exit as3722_wdt_exit(void) +{ +platform_driver_unregister (&as3722_wdt_driver); +} +module_exit (as3722_wdt_exit); + +MODULE_ALIAS ("platform:as3722-wdt" ); +MODULE_DESCRIPTION ("AMS AS3722 watchdog timer driver" ); +MODULE_AUTHOR ("Bibek Basu <[email protected]>" ); +MODULE_LICENSE ("GPL v2" );include/linux/mfd/as3722.h +1
-0@@ -336,6 +336,7 @@#define AS3722_WATCHDOG_TIMER_MAX 0x7F#define AS3722_WATCHDOG_ON BIT(0)#define AS3722_WATCHDOG_SW_SIG BIT(0) +#define AS3722_WATCHDOG_MODE_MASK 0x06#define AS3722_EXT_CONTROL_ENABLE1 0x1#define AS3722_EXT_CONTROL_ENABLE2 0x2
Guenter Roeck
maintainerRe: [PATCH 2/2] watchdog: as3722_wdt: support for AMS AS3722
In reply to Bibek BasuQuoted 6 lines · Bibek Basu
Add watchdog timer driver for as3722 device. The timer can be start/stop and set timing through watchdog subsystem callbacks.
Change-Id I5e252fd762764afaa1598cd98fed91864dc23d8dSigned-off-by Bibek Basu <[email protected]>
[ ... ]
drivers/watchdog/as3722_wdt.c line 165
Quoted 3 lines
drivers/watchdog/as3722_wdt.c new file +3
-0+ wdt_dev->info = &as3722_wdt_info; + wdt_dev->ops = &as3722_wdt_ops; + wdt_dev->timeout =128 ;
One more comment:
Unless I am missing something, this won't work if timer_initial_period is set.
If the watchdog is opened without explicitly setting a timeout, the chip timeout will still be set to the value of initial_timeout, while the watchdog susbystem will believe it to be 128 seconds, and report that value to userspace when asked.
If initial_timeout is low, say, less than 60 seconds, the watchdog will not be updated in time by userspace, since userspace will believe that the timeout is 128 seconds and likely only ping the watchdog every 64 seconds or so.
Guenter
Lee Jones
AppliedQuoted 6 lines · Bibek Basu
Add watchdog device support for as3722
Signed-off-by Bibek Basu <[email protected]>--- drivers/mfd/as3722.c | 3 +++ 1 file changed, 3 insertions(+)
Applied, thanks.
Signature · 8 lines
Lee Jones Linaro STMicroelectronics Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html