watchdog: add Palmas Watchdog support
PATCH 1/2 watchdog: add Palmas Watchdog support
From: Graeme Gregory <[email protected]>
Add support for the Palmas watchdog timer which has a timeout configurable from 1s to 128s.
--- drivers/watchdog/palmas_wdt.c | 291 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 291 insertions(+), 0 deletions(-) create mode 100644 drivers/watchdog/palmas_wdt.c
drivers/watchdog/palmas_wdt.c new file +291 -0
@@ -0,0 +1,291 @@ +/* +* Driver for Watchdog part of Palmas PMIC Chips +* +* Copyright 2011 Texas Instruments Inc. +* +* Author: Graeme Gregory <[email protected]> +* Author: Ian Lartey <[email protected]> +* +* Based on twl4030_wdt.c +* +* Author: Timo Kokkonen <timo.t.kokkonen at nokia.com> +* +* 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; either version 2 of the License, or (at your +* option) any later version. +* +*/ + +#include <linux/module.h> +#include <linux/types.h> +#include <linux/slab.h> +#include <linux/kernel.h> +#include <linux/fs.h> +#include <linux/watchdog.h> +#include <linux/platform_device.h> +#include <linux/miscdevice.h> +#include <linux/uaccess.h> +#include <linux/mfd/palmas.h> + +static struct platform_device *palmas_wdt_dev; + +struct palmas_wdt { +struct palmas *palmas; + +struct miscdevice miscdev; +int timer_margin; +unsigned long state; +}; + +#define PALMAS_WDT_ENABLED (1<<1) + +static int nowayout =WATCHDOG_NOWAYOUT ; +module_param (nowayout, int,0 ); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " + "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static int palmas_wdt_write (struct palmas *palmas,unsigned int data) +{ +unsigned int addr; + + addr =PALMAS_BASE_TO_REG (PALMAS_PMU_CONTROL_BASE ,PALMAS_WATCHDOG ); + +return palmas_write (palmas,PALMAS_PMU_CONTROL_BASE , addr, addr); +} + +static int palmas_wdt_enable (struct palmas_wdt *wdt) +{ +return palmas_wdt_write (wdt->palmas, + wdt->timer_margin |PALMAS_WATCHDOG_ENABLE ); +} + +static int palmas_wdt_disable (struct palmas_wdt *wdt) +{ +return palmas_wdt_write (wdt->palmas, wdt->timer_margin); +} + +static int palmas_wdt_set_timeout (struct palmas_wdt *wdt,int timeout) +{ +if (timeout <1 || timeout >128 ) { +dev_warn (wdt->miscdev.parent, +"Timeout can only be in the range [1-128] seconds" ); +return -EINVAL ; + } + wdt->timer_margin =fls (timeout) -1 ; +return palmas_wdt_enable (wdt); +} + +static ssize_t palmas_wdt_write_fop (struct file *file, +const char __user *data,size_t len,loff_t *ppos) +{ +struct palmas_wdt *wdt = file->private_data; + +if (len) +palmas_wdt_enable (wdt); + +return len; +} + +static long palmas_wdt_ioctl (struct file *file, +unsigned int cmd,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +int __user *p = argp; +int new_margin; +struct palmas_wdt *wdt = file->private_data; +int time =0 ; + +static const struct watchdog_info palmas_wd_ident = { + .identity ="Palmas Watchdog" , + .options =WDIOF_SETTIMEOUT , + .firmware_version =0 , + }; + +switch (cmd) { +case WDIOC_GETSUPPORT : +return copy_to_user (argp, &palmas_wd_ident, +sizeof (palmas_wd_ident)) ? -EFAULT :0 ; + +case WDIOC_GETSTATUS : +case WDIOC_GETBOOTSTATUS : +return put_user (0 , p); + +case WDIOC_KEEPALIVE : +palmas_wdt_enable (wdt); +break ; + +case WDIOC_SETTIMEOUT : +if (get_user (new_margin, p)) +return -EFAULT ; +if (palmas_wdt_set_timeout (wdt, new_margin)) +return -EINVAL ; + + time =1 << wdt->timer_margin; + +return put_user (time, p); + +case WDIOC_GETTIMEOUT : + time =1 << wdt->timer_margin; + +return put_user (time, p); + +default : +return -ENOTTY ; + } + +return 0 ; +} + +static int palmas_wdt_open (struct inode *inode,struct file *file) +{ +struct palmas_wdt *wdt =platform_get_drvdata (palmas_wdt_dev); + +/* /dev/watchdog can only be opened once */ +if (test_and_set_bit (0 , &wdt->state)) +return -EBUSY ; + + wdt->state |=PALMAS_WDT_ENABLED ; + file->private_data = (void *) wdt; + +palmas_wdt_enable (wdt); +return nonseekable_open (inode, file); +} + +static int palmas_wdt_release (struct inode *inode,struct file *file) +{ +struct palmas_wdt *wdt = file->private_data; +if (nowayout) { +dev_alert (wdt->miscdev.parent, +"Unexpected close, watchdog still running!\n" ); +palmas_wdt_enable (wdt); + }else { +if (palmas_wdt_disable (wdt)) +return -EFAULT ; + wdt->state &= ~PALMAS_WDT_ENABLED ; + } + +clear_bit (0 , &wdt->state); +return 0 ; +} + +static const struct file_operations palmas_wdt_fops = { + .owner =THIS_MODULE , + .llseek = no_llseek, + .open = palmas_wdt_open, + .release = palmas_wdt_release, + .unlocked_ioctl = palmas_wdt_ioctl, + .write = palmas_wdt_write_fop, +}; + +static int palmas_wdt_probe (struct platform_device *pdev) +{ +struct palmas *palmas =dev_get_drvdata (pdev->dev.parent); +struct palmas_wdt *wdt; +int ret =0 ; + + wdt =kzalloc (sizeof (*wdt),GFP_KERNEL ); +if (!wdt) +return -ENOMEM ; + + wdt->palmas = palmas; + wdt->state =0 ; + wdt->timer_margin =7 ; + wdt->miscdev.parent = &pdev->dev; + wdt->miscdev.fops = &palmas_wdt_fops; + wdt->miscdev.minor =WATCHDOG_MINOR ; + wdt->miscdev.name ="watchdog" ; + +platform_set_drvdata (pdev, wdt); + + palmas_wdt_dev = pdev; + +palmas_wdt_disable (wdt); + + ret =misc_register (&wdt->miscdev); +if (ret) { +dev_err (wdt->miscdev.parent, +"Failed to register misc device\n" ); +platform_set_drvdata (pdev,NULL ); +kfree (wdt); + palmas_wdt_dev =NULL ; +return ret; + } +return 0 ; +} + +static int palmas_wdt_remove (struct platform_device *pdev) +{ +struct palmas_wdt *wdt =platform_get_drvdata (pdev); + +if (wdt->state &PALMAS_WDT_ENABLED ) +if (palmas_wdt_disable (wdt)) +return -EFAULT ; + + wdt->state &= ~PALMAS_WDT_ENABLED ; +misc_deregister (&wdt->miscdev); + +platform_set_drvdata (pdev,NULL ); +kfree (wdt); + palmas_wdt_dev =NULL ; + +return 0 ; +} + +#ifdef CONFIG_PM +static int palmas_wdt_suspend (struct platform_device *pdev,pm_message_t state) +{ +struct palmas_wdt *wdt =platform_get_drvdata (pdev); +if (wdt->state &PALMAS_WDT_ENABLED ) +return palmas_wdt_disable (wdt); + +return 0 ; +} + +static int palmas_wdt_resume (struct platform_device *pdev) +{ +struct palmas_wdt *wdt =platform_get_drvdata (pdev); +if (wdt->state &PALMAS_WDT_ENABLED ) +return palmas_wdt_enable (wdt); + +return 0 ; +} +#else +#define palmas_wdt_suspend NULL +#define palmas_wdt_resume NULL +#endif + +static struct of_device_id of_palmas_match_tbl[] = { + { .compatible ="ti,palmas-wdt" , }, + {/* end */ } +}; + +static struct platform_driver palmas_wdt_driver = { + .probe = palmas_wdt_probe, + .remove = palmas_wdt_remove, + .suspend = palmas_wdt_suspend, + .resume = palmas_wdt_resume, + .driver = { + .owner =THIS_MODULE , + .of_match_table = of_palmas_match_tbl, + .name ="palmas-wdt" , + }, +}; + +static int palmas_wdt_init (void ) +{ +return platform_driver_register (&palmas_wdt_driver); +} +module_init (palmas_wdt_init); + +static void palmas_wdt_exit (void ) +{ +platform_driver_unregister (&palmas_wdt_driver); +} +module_exit (palmas_wdt_exit); + +MODULE_AUTHOR ("Graeme Gregory <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS_MISCDEV (WATCHDOG_MINOR ); +MODULE_ALIAS ("platform:palmas-wdt" ); +MODULE_DEVICE_TABLE (of, of_palmas_match_tbl);
Signature · 1 line
1.7.0.4
PATCH 2/2 watchdog: Kconfig for Palmas watchdog driver
Add the Kconfig and MAkefile for the Palmas Watchdog driver
--- drivers/watchdog/Kconfig | 7 +++++++ drivers/watchdog/Makefile | 1 + 2 files changed, 8 insertions(+), 0 deletions(-)
drivers/watchdog/Kconfig +7 -0
@@ -103,6 +103,13 @@ config WM8350_WATCHDOG Support for the watchdog in the WM8350 AudioPlus PMIC. When the watchdog triggers the system will be reset. +config PALMAS_WATCHDOG + tristate "Palmas Watchdog" + depends on MFD_PALMAS + help + Support for the watchdog in the Palmas family of PMICs. When the + watchdog times out system will be reset. + # ALPHA Architecture # ARM Architecture
drivers/watchdog/Makefile +1 -0
@@ -171,3 +171,4 @@ obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o +obj-$(CONFIG_PALMAS_WATCHDOG) += palmas_wdt.o
Signature · 1 line
1.7.0.4
drivers/watchdog/palmas_wdt.c line 261
Quoted 11 lines · Ian Lartey
From: Graeme Gregory <[email protected]>
Add support for the Palmas watchdog timer which has a timeout configurable from 1s to 128s.
drivers/watchdog/palmas_wdt.c +4
-0+static struct of_device_id of_palmas_match_tbl[] = { + { .compatible ="ti,palmas-wdt" , }, + {/* end */ } +};
Is there a DT binding document for that compatible value?
Quoted 6 lines · Stephen Warren
Quoted 4 lines · Ian Lartey
From: Graeme Gregory <[email protected]>
Add support for the Palmas watchdog timer which has a timeout configurable from 1s to 128s.
Quoted 8 lines
drivers/watchdog/palmas_wdt.c line 261
Quoted 6 lines
drivers/watchdog/palmas_wdt.c +4
-0+static struct of_device_id of_palmas_match_tbl[] = { + { .compatible ="ti,palmas-wdt" , }, + {/* end */ } +};Is there a DT binding document for that compatible value?
The device tree for this compatible value is actually empty, shall I remove it or is it OK to show it as empty in the bindings document ?
There will be other palmas device bindings in this document.
Quoted 6 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 18 lines · Ian Lartey
Quoted 10 lines · Stephen Warren
Quoted 8 lines · Ian Lartey
From: Graeme Gregory <[email protected]>
Add support for the Palmas watchdog timer which has a timeout configurable
from 1s to 128s.drivers/watchdog/palmas_wdt.c +0
-0Quoted 6 lines
drivers/watchdog/palmas_wdt.c line 261
Quoted 4 lines
drivers/watchdog/palmas_wdt.c +4
-0+static struct of_device_id of_palmas_match_tbl[] = { + { .compatible ="ti,palmas-wdt" , }, + {/* end */ } +};Is there a DT binding document for that compatible value?
Quoted 4 lines
The device tree for this compatible value is actually empty, shall I remove it or is it OK to show it as empty in the bindings document ?
There will be other palmas device bindings in this document.
Well, you need a binding document that describes how to create this node. If it needs no properties other than compatible, it'll be a simple document!
Did you review my comments on the other patches re: whether the sub-modules of this HW actually should be sub-nodes in DT or not? If not, then you don't need this node in DT, and hence there will be no compatible value for the node, and hence no need to write a binding document.
Quoted 28 lines · Stephen Warren
Quoted 18 lines · Ian Lartey
Quoted 10 lines · Stephen Warren
Quoted 8 lines · Ian Lartey
From: Graeme Gregory <[email protected]>
Add support for the Palmas watchdog timer which has a timeout configurable
from 1s to 128s.drivers/watchdog/palmas_wdt.c +0
-0Quoted 6 lines
drivers/watchdog/palmas_wdt.c line 261
Quoted 4 lines
drivers/watchdog/palmas_wdt.c +4
-0+static struct of_device_id of_palmas_match_tbl[] = { + { .compatible ="ti,palmas-wdt" , }, + {/* end */ } +};Is there a DT binding document for that compatible value?
Quoted 4 lines
The device tree for this compatible value is actually empty, shall I remove it or is it OK to show it as empty in the bindings document ?
There will be other palmas device bindings in this document.Well, you need a binding document that describes how to create this node. If it needs no properties other than compatible, it'll be a simple document!
Quoted 5 lines
Did you review my comments on the other patches re: whether the sub-modules of this HW actually should be sub-nodes in DT or not? If not, then you don't need this node in DT, and hence there will be no compatible value for the node, and hence no need to write a binding document.
I've not reviewed your comments on the other patches, so I'll look at those before responding properly.
Quoted 6 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 11 lines · Ian Lartey
From: Graeme Gregory <[email protected]>
Add support for the Palmas watchdog timer which has a timeout configurable from 1s to 128s.
Signed-off-by Graeme Gregory <[email protected]>Signed-off-by Ian Lartey <[email protected]>--- drivers/watchdog/palmas_wdt.c | 291 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 291 insertions(+), 0 deletions(-)create mode 100644
drivers/watchdog/palmas_wdt.c
patch 1 and 2 can be merge as single patch.
generic comment, we have proper watchdog framework where we can have some api for watchdog_ops and register as watchdog_register_device(). Then core parts take care of the all fileops/sysfs interface.
This need not to be develop locally.
You can refer wm831x_wdt.c, wm8350_wdt.c driver for more reference where it is really used watchdog framework.
I think you can use the watchdog framework for this.