From: Johannes Thumshirn <johannes.thumshirn@men.de>
To: <wim@iguana.be>
Cc: <linux-kernel@vger.kernel.org>, <linux-watchdog@vger.kernel.org>,
<guenter@roeck-us.net>, <johannes.thumshirn@men.de>
Subject: [PATCH v10 2/2] watchdog: Sysfs interface for MEN A21 watchdog
Date: Mon, 17 Jun 2013 12:24:13 +0200 [thread overview]
Message-ID: <20130617102407.GA25443@jtlinux> (raw)
In-Reply-To: <20130617102242.GA25393@jtlinux>
This patch adds a sysfs interface for the watchdog
device found on MEN A21 Boards.
The newly generated files are:
* rebootcause:
Can be one of:
Power on Reset,
CPU Reset Request,
Push Button,
FPGA Reset Request,
Watchdog,
Local Power Bad,
Invalid or
BDI
and shows the reason of the boards last reboot.
* active:
Shows if the watchdog CPLD is actually running
* allow_disable:
Shows if the watchdog is allowed to be disabled (NOWAYOUT disabled)
* fastmode:
Shows if the CPLD is running in fast mode (1s timeout), once it is in
fastmode it can't be switched back to slow mode (30s timeout) until the
next reboot.
Revision 2:
* Re-worked sysfs patch to apply on re-worked base
Revision 3:
* Re-worked sysfs patch to apply on re-worked base
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@men.de>
---
drivers/watchdog/mena21_wdt.c | 89 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 89 insertions(+)
diff --git a/drivers/watchdog/mena21_wdt.c b/drivers/watchdog/mena21_wdt.c
index 96dbba9..91cc90b 100644
--- a/drivers/watchdog/mena21_wdt.c
+++ b/drivers/watchdog/mena21_wdt.c
@@ -22,6 +22,17 @@
#define NUM_GPIOS 6
+static char *reset_causes[] = {
+ "Power On Reset",
+ "CPU Reset Request",
+ "Push Button",
+ "FPGA Reset Request",
+ "Watchdog",
+ "Local Power Bad",
+ "Invalid",
+ "BDI",
+};
+
enum a21_wdt_gpios {
GPIO_WD_ENAB,
GPIO_WD_FAST,
@@ -53,6 +64,73 @@ static unsigned int a21_wdt_get_bootstatus(struct a21_wdt_drv *drv)
return reset;
}
+static ssize_t rebootcause_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct a21_wdt_drv *drv = dev_get_drvdata(dev);
+ unsigned int reset = 0;
+
+ reset = a21_wdt_get_bootstatus(drv);
+
+ return sprintf(buf, "%s\n", reset_causes[reset]);
+}
+static DEVICE_ATTR(rebootcause, S_IRUGO, rebootcause_show, NULL);
+
+static ssize_t active_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct a21_wdt_drv *drv = dev_get_drvdata(dev);
+
+ return sprintf(buf, "%d\n", !!gpio_get_value(drv->gpios[GPIO_WD_ENAB]));
+}
+static DEVICE_ATTR(active, S_IRUGO, active_show, NULL);
+
+static ssize_t allow_disable_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ return sprintf(buf, "%d\n", !nowayout);
+}
+static DEVICE_ATTR(allow_disable, S_IRUGO, allow_disable_show, NULL);
+
+static ssize_t fastmode_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct a21_wdt_drv *drv = dev_get_drvdata(dev);
+
+ return sprintf(buf, "%d\n", !!gpio_get_value(drv->gpios[GPIO_WD_FAST]));
+}
+static DEVICE_ATTR(fastmode, S_IRUGO, fastmode_show, NULL);
+
+static int a21_wdt_create_files(struct watchdog_device *wdev)
+{
+ int ret;
+
+ ret = device_create_file(wdev->dev, &dev_attr_rebootcause);
+ if (ret)
+ return ret;
+ ret = device_create_file(wdev->dev, &dev_attr_active);
+ if (ret)
+ return ret;
+ ret = device_create_file(wdev->dev, &dev_attr_allow_disable);
+ if (ret)
+ return ret;
+ ret = device_create_file(wdev->dev, &dev_attr_fastmode);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static void a21_wdt_remove_files(struct watchdog_device *wdev)
+{
+ device_remove_file(wdev->dev, &dev_attr_rebootcause);
+ device_remove_file(wdev->dev, &dev_attr_active);
+ device_remove_file(wdev->dev, &dev_attr_allow_disable);
+ device_remove_file(wdev->dev, &dev_attr_fastmode);
+}
+
static int a21_wdt_start(struct watchdog_device *wdt)
{
struct a21_wdt_drv *drv = watchdog_get_drvdata(wdt);
@@ -215,11 +293,20 @@ static int a21_wdt_probe(struct platform_device *pdev)
}
dev_set_drvdata(&pdev->dev, drv);
+ dev_set_drvdata(a21_wdt.dev, drv);
+
+ ret = a21_wdt_create_files(&a21_wdt);
+ if (ret) {
+ dev_err(&pdev->dev, "Cannot create sysfs entries\n");
+ goto err_create_sysfs;
+ }
dev_info(&pdev->dev, "MEN A21 watchdog timer driver enabled\n");
return 0;
+err_create_sysfs:
+ watchdog_unregister_device(&drv->wdt);
err_register_wd:
mutex_destroy(&drv->lock);
@@ -233,6 +320,8 @@ static int a21_wdt_remove(struct platform_device *pdev)
dev_warn(&pdev->dev,
"Unregistering A21 watchdog driver, board may reboot\n");
+ a21_wdt_remove_files(&drv->wdt);
+
watchdog_unregister_device(&drv->wdt);
mutex_destroy(&drv->lock);
--
1.7.9.5
next prev parent reply other threads:[~2013-06-17 10:21 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-31 8:58 [PATCH v5 1/2] watchdog: New watchdog driver for MEN A21 watchdogs Johannes Thumshirn
2013-05-31 9:01 ` [PATCH v2 2/2] This patch adds a sysfs interface for the watchdog device found on MEN A21 Boards Johannes Thumshirn
2013-05-31 9:04 ` [PATCH v5 1/2] watchdog: New watchdog driver for MEN A21 watchdogs Johannes Thumshirn
2013-05-31 10:36 ` Guenter Roeck
2013-05-31 10:53 ` Johannes Thumshirn
2013-05-31 11:08 ` [PATCH v6] " Johannes Thumshirn
2013-05-31 11:40 ` Guenter Roeck
2013-05-31 12:55 ` Johannes Thumshirn
2013-06-01 4:15 ` Guenter Roeck
2013-06-03 9:50 ` Johannes Thumshirn
2013-06-06 10:51 ` Some problems with sysfs patch (was Re: [PATCH v6] watchdog: New watchdog driver for MEN A21 watchdogs) Johannes Thumshirn
2013-06-06 11:31 ` Guenter Roeck
2013-06-06 13:00 ` Johannes Thumshirn
2013-06-06 17:08 ` Guenter Roeck
2013-06-07 7:45 ` Johannes Thumshirn
2013-06-07 9:14 ` Guenter Roeck
2013-06-07 9:49 ` Johannes Thumshirn
2013-05-31 13:32 ` [PATCH v7] watchdog: New watchdog driver for MEN A21 watchdogs Johannes Thumshirn
2013-06-01 15:28 ` Guenter Roeck
2013-06-03 14:34 ` [PATCH v8] " Johannes Thumshirn
2013-06-07 9:55 ` [PATCH v8 2/2] watchdog: Sysfs interface for MEN A21 watchdog Johannes Thumshirn
2013-06-14 3:55 ` [PATCH v8] watchdog: New watchdog driver for MEN A21 watchdogs Guenter Roeck
2013-06-14 7:39 ` Johannes Thumshirn
2013-06-14 10:58 ` [PATCH v9] " Johannes Thumshirn
2013-06-14 11:19 ` [PATCH v9 2/2] watchdog: Sysfs interface for MEN A21 watchdog Johannes Thumshirn
2013-06-16 22:07 ` [PATCH v9] watchdog: New watchdog driver for MEN A21 watchdogs Guenter Roeck
2013-06-17 6:40 ` Johannes Thumshirn
2013-06-17 10:22 ` [PATCH v10 1/2] " Johannes Thumshirn
2013-06-17 10:24 ` Johannes Thumshirn [this message]
2013-06-17 14:00 ` Guenter Roeck
2013-06-18 15:19 ` [PATCH RESEND " Johannes Thumshirn
2013-06-18 15:21 ` [PATCH RESEND v10 2/2] watchdog: Sysfs interface for MEN A21 watchdog Johannes Thumshirn
2013-07-01 7:32 ` Johannes Thumshirn
2013-07-05 21:03 ` Wim Van Sebroeck
2013-07-08 7:06 ` Johannes Thumshirn
2013-07-05 21:01 ` [PATCH RESEND v10 1/2] watchdog: New watchdog driver for MEN A21 watchdogs Wim Van Sebroeck
2013-07-08 6:59 ` Johannes Thumshirn
2013-06-01 8:56 ` [PATCH v5 " Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130617102407.GA25443@jtlinux \
--to=johannes.thumshirn@men.de \
--cc=guenter@roeck-us.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=wim@iguana.be \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).