watchdog: max77620: Add support for watchdog timer
PATCH v2 1/1 watchdog: max77620: Add support for watchdog timer
Maxim PMIC MAX77620 is Power management IC which have multiple sub blocks like regulators (DCDC/LDOs), GPIO, RTC, Clock, Watchdog timer etc.
Add the driver for watchdog timer under watchdog framework. The driver implements the watchdog callbacks to start, stop, ping and set timeout for watchodg framework.
---
Changes from V1:
- Remove the error prints from start/stop/ping to simplify the function.
- Instead of stopping running WDT, inform HW RUNNING and update the required param accordingly.
- Resequence the param sets for wdt device to avoid race condition, move all wdt device setting before registration.
drivers/watchdog/Kconfig | 9 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/max77620_wdt.c | 222 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 drivers/watchdog/max77620_wdt.c
drivers/watchdog/Kconfig +9 -0
@@ -516,6 +516,15 @@ config MAX63XX_WATCHDOG help Support for memory mapped max63{69,70,71,72,73,74} watchdog timer. +config MAX77620_WATCHDOG + tristate "Maxim Max77620 Watchdog Timer" + depends on MFD_MAX77620 + help + This is the driver for the Max77620 watchdog timer. + Say 'Y' here to enable the watchdog timer support for + MAX77620 chips. To compile this driver as a module, + choose M here: the module will be called max77620_wdt. + config IMX2_WDT tristate "IMX2+ Watchdog" depends on ARCH_MXC || ARCH_LAYERSCAPE
drivers/watchdog/Makefile +1 -0
@@ -203,6 +203,7 @@ obj-$(CONFIG_TANGOX_WATCHDOG) += tangox_wdt.o obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o +obj-$(CONFIG_MAX77620_WATCHDOG) += max77620_wdt.o obj-$(CONFIG_ZIIRAVE_WATCHDOG) += ziirave_wdt.o obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o obj-$(CONFIG_MENF21BMC_WATCHDOG) += menf21bmc_wdt.o
drivers/watchdog/max77620_wdt.c new file +222 -0
222 lines not on this page · raw message
Signature · 1 line
2.1.4
Guenter Roeck
maintainerHi,
Quoted 8 lines · Laxman Dewangan
Maxim PMIC MAX77620 is Power management IC which have multiple sub blocks like regulators (DCDC/LDOs), GPIO, RTC, Clock, Watchdog timer etc.
Add the driver for watchdog timer under watchdog framework. The driver implements the watchdog callbacks to start, stop, ping and set timeout for watchodg framework.
Almost good. One more comment below.
Quoted 10 lines
Signed-off-by Laxman Dewangan <[email protected]>---
Changes from V1:
- Remove the error prints from start/stop/ping to simplify the function.
- Instead of stopping running WDT, inform HW RUNNING and update the required param accordingly.
- Resequence the param sets for wdt device to avoid race condition, move all wdt device setting before registration.
[ ... ]
Quoted 54 lines
drivers/watchdog/max77620_wdt.c new file +54
-0+static int max77620_wdt_probe (struct platform_device *pdev) +{ +struct max77620_wdt *wdt; +struct watchdog_device *wdt_dev; +unsigned int regval; +int ret; + + wdt =devm_kzalloc (&pdev->dev,sizeof (*wdt),GFP_KERNEL ); +if (!wdt) +return -ENOMEM ; + + wdt->dev = &pdev->dev; + wdt->rmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!wdt->rmap) { +dev_err (wdt->dev,"Failed to get parent regmap\n" ); +return -ENODEV ; + } + + wdt_dev = &wdt->wdt_dev; + wdt_dev->info = &max77620_wdt_info; + wdt_dev->ops = &max77620_wdt_ops; + wdt_dev->min_timeout =2 ; + wdt_dev->max_timeout =128 ; + wdt_dev->max_hw_heartbeat_ms =128 *1000 ; + +platform_set_drvdata (pdev, wdt); + +/* Enable WD_RST_WK - WDT expire results in a restart */ + ret =regmap_update_bits (wdt->rmap,MAX77620_REG_ONOFFCNFG2 , +MAX77620_ONOFFCNFG2_WD_RST_WK , +MAX77620_ONOFFCNFG2_WD_RST_WK ); +if (ret <0 ) { +dev_err (wdt->dev,"Failed to set WD_RST_WK: %d\n" , ret); +return ret; + } + +/* Set WDT clear in OFF and sleep mode */ + ret =regmap_update_bits (wdt->rmap,MAX77620_REG_CNFGGLBL2 , +MAX77620_WDTOFFC |MAX77620_WDTSLPC , +MAX77620_WDTOFFC |MAX77620_WDTSLPC ); +if (ret <0 ) { +dev_err (wdt->dev,"Failed to set WDT OFF mode: %d\n" , ret); +return ret; + } + +/* Check if WDT running and ig yes then set flags properly */ + ret =regmap_read (wdt->rmap,MAX77620_REG_CNFGGLBL2 , ®val); +if (ret <0 ) { +dev_err (wdt->dev,"Failed to read WDT CFG register: %d\n" , ret); +return ret; + } + +if (regval &MAX77620_WDTEN ) { + regval = regval &MAX77620_TWD_MASK ;
drivers/watchdog/max77620_wdt.c line 175
Quoted 10 lines
drivers/watchdog/max77620_wdt.c new file +10
-0+if (regval == MAX77620_TWD_2s) + wdt_dev->timeout =2 ; +else if (regval == MAX77620_TWD_16s) + wdt_dev->timeout =16 ; +else if (regval == MAX77620_TWD_64s) + wdt_dev->timeout =64 ; +else + wdt_dev->timeout =128 ; +set_bit (WDOG_HW_RUNNING , &wdt_dev->status); + }
Please also set a default timeout if the watchdog is not running (and remember to write it to the chip). Otherwise the core won't know the timeout and can not report it to user space when the watchdog device is opened.
Thanks,
Guenter