linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] watchdog: add Palmas Watchdog support
@ 2013-02-27 18:36 Ian Lartey
  2013-02-27 18:36 ` [PATCH 2/2] watchdog: Kconfig for Palmas watchdog driver Ian Lartey
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Ian Lartey @ 2013-02-27 18:36 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-watchdog, ldewangan, j-keerthy, gg, wim, grant.likely,
	rob.herring, Ian Lartey

From: Graeme Gregory <gg@slimlogic.co.uk>

Add support for the Palmas watchdog timer which has a timeout configurable
from 1s to 128s.

Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
Signed-off-by: Ian Lartey <ian@slimlogic.co.uk>
---
 drivers/watchdog/palmas_wdt.c |  291 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 291 insertions(+), 0 deletions(-)
 create mode 100644 drivers/watchdog/palmas_wdt.c

diff --git a/drivers/watchdog/palmas_wdt.c b/drivers/watchdog/palmas_wdt.c
new file mode 100644
index 0000000..68cdc1e
--- /dev/null
+++ b/drivers/watchdog/palmas_wdt.c
@@ -0,0 +1,291 @@
+/*
+ * Driver for Watchdog part of Palmas PMIC Chips
+ *
+ * Copyright 2011 Texas Instruments Inc.
+ *
+ * Author: Graeme Gregory <gg@slimlogic.co.uk>
+ * Author: Ian Lartey <ian@slimlogic.co.uk>
+ *
+ * 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 <gg@slimlogic.co.uk>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
+MODULE_ALIAS("platform:palmas-wdt");
+MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] watchdog: Kconfig for Palmas watchdog driver
  2013-02-27 18:36 [PATCH 1/2] watchdog: add Palmas Watchdog support Ian Lartey
@ 2013-02-27 18:36 ` Ian Lartey
  2013-02-27 18:38 ` [PATCH 1/2] watchdog: add Palmas Watchdog support Stephen Warren
  2013-02-28  5:50 ` Laxman Dewangan
  2 siblings, 0 replies; 7+ messages in thread
From: Ian Lartey @ 2013-02-27 18:36 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-watchdog, ldewangan, j-keerthy, gg, wim, grant.likely,
	rob.herring, Ian Lartey

Add the Kconfig and MAkefile for the Palmas Watchdog driver

Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
Signed-off-by: Ian Lartey <ian@slimlogic.co.uk>
---
 drivers/watchdog/Kconfig  |    7 +++++++
 drivers/watchdog/Makefile |    1 +
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 0374e0e..dae5a91 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -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
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index a300b94..e845c21 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -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
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] watchdog: add Palmas Watchdog support
  2013-02-27 18:36 [PATCH 1/2] watchdog: add Palmas Watchdog support Ian Lartey
  2013-02-27 18:36 ` [PATCH 2/2] watchdog: Kconfig for Palmas watchdog driver Ian Lartey
@ 2013-02-27 18:38 ` Stephen Warren
  2013-02-27 20:17   ` Ian Lartey
  2013-02-28  5:50 ` Laxman Dewangan
  2 siblings, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2013-02-27 18:38 UTC (permalink / raw)
  To: Ian Lartey
  Cc: linux-kernel, linux-watchdog, ldewangan, j-keerthy, gg, wim,
	grant.likely, rob.herring

On 02/27/2013 11:36 AM, Ian Lartey wrote:
> From: Graeme Gregory <gg@slimlogic.co.uk>
> 
> Add support for the Palmas watchdog timer which has a timeout configurable
> from 1s to 128s.

> diff --git a/drivers/watchdog/palmas_wdt.c b/drivers/watchdog/palmas_wdt.c

> +static struct of_device_id of_palmas_match_tbl[] = {
> +	{ .compatible = "ti,palmas-wdt", },
> +	{ /* end */ }
> +};

Is there a DT binding document for that compatible value?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] watchdog: add Palmas Watchdog support
  2013-02-27 18:38 ` [PATCH 1/2] watchdog: add Palmas Watchdog support Stephen Warren
@ 2013-02-27 20:17   ` Ian Lartey
  2013-02-27 20:36     ` Stephen Warren
  0 siblings, 1 reply; 7+ messages in thread
From: Ian Lartey @ 2013-02-27 20:17 UTC (permalink / raw)
  To: Stephen Warren
  Cc: linux-kernel, linux-watchdog, ldewangan, j-keerthy, gg, wim,
	grant.likely, rob.herring

On 27/02/13 18:38, Stephen Warren wrote:
> On 02/27/2013 11:36 AM, Ian Lartey wrote:
>> From: Graeme Gregory <gg@slimlogic.co.uk>
>>
>> Add support for the Palmas watchdog timer which has a timeout configurable
>> from 1s to 128s.
>
>> diff --git a/drivers/watchdog/palmas_wdt.c b/drivers/watchdog/palmas_wdt.c
>
>> +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.

> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] watchdog: add Palmas Watchdog support
  2013-02-27 20:17   ` Ian Lartey
@ 2013-02-27 20:36     ` Stephen Warren
  2013-02-27 22:29       ` Ian Lartey
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2013-02-27 20:36 UTC (permalink / raw)
  To: Ian Lartey
  Cc: linux-kernel, linux-watchdog, ldewangan, j-keerthy, gg, wim,
	grant.likely, rob.herring

On 02/27/2013 01:17 PM, Ian Lartey wrote:
> On 27/02/13 18:38, Stephen Warren wrote:
>> On 02/27/2013 11:36 AM, Ian Lartey wrote:
>>> From: Graeme Gregory <gg@slimlogic.co.uk>
>>>
>>> Add support for the Palmas watchdog timer which has a timeout
>>> configurable
>>> from 1s to 128s.
>>
>>> diff --git a/drivers/watchdog/palmas_wdt.c
>>> b/drivers/watchdog/palmas_wdt.c
>>
>>> +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.

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] watchdog: add Palmas Watchdog support
  2013-02-27 20:36     ` Stephen Warren
@ 2013-02-27 22:29       ` Ian Lartey
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Lartey @ 2013-02-27 22:29 UTC (permalink / raw)
  To: Stephen Warren
  Cc: linux-kernel, linux-watchdog, ldewangan, j-keerthy, gg, wim,
	grant.likely, rob.herring

On 27/02/13 20:36, Stephen Warren wrote:
> On 02/27/2013 01:17 PM, Ian Lartey wrote:
>> On 27/02/13 18:38, Stephen Warren wrote:
>>> On 02/27/2013 11:36 AM, Ian Lartey wrote:
>>>> From: Graeme Gregory <gg@slimlogic.co.uk>
>>>>
>>>> Add support for the Palmas watchdog timer which has a timeout
>>>> configurable
>>>> from 1s to 128s.
>>>
>>>> diff --git a/drivers/watchdog/palmas_wdt.c
>>>> b/drivers/watchdog/palmas_wdt.c
>>>
>>>> +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.
>
> 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.

I've not reviewed your comments on the other patches, so I'll look at
those before responding properly.

> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] watchdog: add Palmas Watchdog support
  2013-02-27 18:36 [PATCH 1/2] watchdog: add Palmas Watchdog support Ian Lartey
  2013-02-27 18:36 ` [PATCH 2/2] watchdog: Kconfig for Palmas watchdog driver Ian Lartey
  2013-02-27 18:38 ` [PATCH 1/2] watchdog: add Palmas Watchdog support Stephen Warren
@ 2013-02-28  5:50 ` Laxman Dewangan
  2 siblings, 0 replies; 7+ messages in thread
From: Laxman Dewangan @ 2013-02-28  5:50 UTC (permalink / raw)
  To: Ian Lartey
  Cc: linux-kernel, linux-watchdog, j-keerthy, gg, wim, grant.likely,
	rob.herring

On Thursday 28 February 2013 12:06 AM, Ian Lartey wrote:
> From: Graeme Gregory <gg@slimlogic.co.uk>
>
> Add support for the Palmas watchdog timer which has a timeout configurable
> from 1s to 128s.
>
> Signed-off-by: Graeme Gregory <gg@slimlogic.co.uk>
> Signed-off-by: Ian Lartey <ian@slimlogic.co.uk>
> ---
>   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.



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-02-28  5:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-27 18:36 [PATCH 1/2] watchdog: add Palmas Watchdog support Ian Lartey
2013-02-27 18:36 ` [PATCH 2/2] watchdog: Kconfig for Palmas watchdog driver Ian Lartey
2013-02-27 18:38 ` [PATCH 1/2] watchdog: add Palmas Watchdog support Stephen Warren
2013-02-27 20:17   ` Ian Lartey
2013-02-27 20:36     ` Stephen Warren
2013-02-27 22:29       ` Ian Lartey
2013-02-28  5:50 ` Laxman Dewangan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).