lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1362662276-20792-5-git-send-email-ian@slimlogic.co.uk>
Date:	Thu,  7 Mar 2013 13:17:49 +0000
From:	Ian Lartey <ian@...mlogic.co.uk>
To:	linux-kernel@...r.kernel.org
Cc:	linux-doc@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
	linux-leds@...r.kernel.org, linux-watchdog@...r.kernel.org,
	swarren@...dotorg.org, grant.likely@...retlab.ca,
	broonie@...nsource.wolfsonmicro.com, rob.herring@...xeda.com,
	rob@...dley.net, mturquette@...aro.org, linus.walleij@...aro.org,
	cooloney@...il.com, rpurdie@...ys.net, sameo@...ux.intel.com,
	wim@...ana.be, lgirdwood@...il.com, gg@...mlogic.co.uk,
	j-keerthy@...com, ldewangan@...dia.com, t-kristo@...com,
	Ian Lartey <ian@...mlogic.co.uk>
Subject: [PATCH v8 05/12] watchdog: add Palmas Watchdog support

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

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

Signed-off-by: Graeme Gregory <gg@...mlogic.co.uk>
Signed-off-by: Ian Lartey <ian@...mlogic.co.uk>
---
 drivers/watchdog/palmas_wdt.c |  170 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 170 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..5bdd78a
--- /dev/null
+++ b/drivers/watchdog/palmas_wdt.c
@@ -0,0 +1,170 @@
+/*
+ * Driver for Watchdog part of Palmas PMIC Chips
+ *
+ * Copyright 2011-2013 Texas Instruments Inc.
+ *
+ * Author: Graeme Gregory <gg@...mlogic.co.uk>
+ * Author: Ian Lartey <ian@...mlogic.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/watchdog.h>
+#include <linux/mfd/palmas.h>
+
+struct palmas_wdt {
+	struct palmas *palmas;
+	struct watchdog_device wdt;
+	struct device *dev;
+
+	int timer_margin;
+};
+
+
+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 watchdog_device *wdt)
+{
+	struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt);
+	struct palmas *palmas = driver_data->palmas;
+
+	return palmas_wdt_write(palmas, driver_data->timer_margin |
+				PALMAS_WATCHDOG_ENABLE);
+}
+
+static int palmas_wdt_disable(struct watchdog_device *wdt)
+{
+	struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt);
+	struct palmas *palmas = driver_data->palmas;
+
+	return palmas_wdt_write(palmas, driver_data->timer_margin);
+}
+
+static int palmas_wdt_set_timeout(struct watchdog_device *wdt, unsigned timeout)
+{
+	struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt);
+
+	if (timeout < 1 || timeout > 128) {
+		dev_warn(driver_data->dev,
+			"Timeout can only be in the range [1-128] seconds");
+		return -EINVAL;
+	}
+	driver_data->timer_margin = fls(timeout) - 1;
+	return 0;
+}
+
+static const struct watchdog_info palmas_wdt_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
+	.identity = "Palmas Watchdog",
+	.firmware_version = 0,
+};
+
+static const struct watchdog_ops palmas_wdt_ops = {
+	.owner = THIS_MODULE,
+	.start = palmas_wdt_enable,
+	.stop = palmas_wdt_disable,
+	.ping = palmas_wdt_enable,
+	.set_timeout = palmas_wdt_set_timeout,
+};
+
+static int palmas_wdt_probe(struct platform_device *pdev)
+{
+	struct palmas *palmas = dev_get_drvdata(pdev->dev.parent);
+	struct palmas_wdt *driver_data;
+	struct watchdog_device *palmas_wdt;
+	int ret = 0;
+
+	driver_data = devm_kzalloc(&pdev->dev, sizeof(*driver_data),
+				   GFP_KERNEL);
+	if (!driver_data) {
+		dev_err(&pdev->dev, "Unable to alloacate watchdog device\n");
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	driver_data->palmas = palmas;
+
+	palmas_wdt = &driver_data->wdt;
+
+	palmas_wdt->info = &palmas_wdt_info;
+	palmas_wdt->ops = &palmas_wdt_ops;
+	watchdog_set_nowayout(palmas_wdt, nowayout);
+	watchdog_set_drvdata(palmas_wdt, driver_data);
+
+	ret = watchdog_register_device(&driver_data->wdt);
+	if (ret) {
+		platform_set_drvdata(pdev, NULL);
+		goto err;
+	}
+
+	dev_set_drvdata(&pdev->dev, driver_data);
+
+	return 0;
+err:
+	return ret;
+}
+
+static int palmas_wdt_remove(struct platform_device *pdev)
+{
+	struct palmas_wdt *driver_data = dev_get_drvdata(&pdev->dev);
+
+	watchdog_unregister_device(&driver_data->wdt);
+
+	return 0;
+}
+
+static struct of_device_id of_palmas_match_tbl[] = {
+	{ .compatible = "ti,palmas-wdt", },
+	{ .compatible = "ti,palmas-charger-wdt", },
+	{ .compatible = "ti,twl6035-wdt", },
+	{ .compatible = "ti,twl6036-wdt", },
+	{ .compatible = "ti,twl6037-wdt", },
+	{ .compatible = "ti,tps65913-wdt", },
+	{ .compatible = "ti,tps65914-wdt", },
+	{ .compatible = "ti,tps80036-wdt", },
+	{ /* end */ }
+};
+
+static struct platform_driver palmas_wdt_driver = {
+	.probe = palmas_wdt_probe,
+	.remove = palmas_wdt_remove,
+	.driver = {
+		.owner = THIS_MODULE,
+		.of_match_table = of_palmas_match_tbl,
+		.name = "palmas-wdt",
+	},
+};
+
+module_platform_driver(palmas_wdt_driver);
+
+MODULE_AUTHOR("Graeme Gregory <gg@...mlogic.co.uk>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:palmas-wdt");
+MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);
-- 
1.7.0.4

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ