All of lore.kernel.org
 help / color / mirror / Atom feed
From: davidm@egauge.net (David Mosberger-Tang)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] drivers: power: reset: at91-reset: Provide reset reason via sysfs.
Date: Thu, 21 Jan 2016 09:35:20 -0700	[thread overview]
Message-ID: <1453394120-15878-1-git-send-email-davidm@egauge.net> (raw)

Rather than just printing the reset-reason at boot-time, make it available
via sysfs as attribute "reset_reason" of the reset controller.  For example,
on SAMA5D2 Xplained, this sysfs attribute is available at:

 /sys/devices/platform/ahb/ahb:apb/f8048000.rstc/reset_reason
---
 drivers/power/reset/at91-reset.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/power/reset/at91-reset.c b/drivers/power/reset/at91-reset.c
index 264b9b8..184516b 100644
--- a/drivers/power/reset/at91-reset.c
+++ b/drivers/power/reset/at91-reset.c
@@ -45,6 +45,11 @@ enum reset_type {
 	RESET_TYPE_USER		= 4,
 };
 
+static ssize_t reset_reason_show(struct device *,
+				 struct device_attribute *attr,
+				 char *);
+static DEVICE_ATTR(reset_reason, S_IRUSR, reset_reason_show, NULL);
+
 static void __iomem *at91_ramc_base[2], *at91_rstc_base;
 
 /*
@@ -132,7 +137,7 @@ static int sama5d3_restart(struct notifier_block *this, unsigned long mode,
 	return NOTIFY_DONE;
 }
 
-static void __init at91_reset_status(struct platform_device *pdev)
+static const char *at91_reset_reason(struct platform_device *pdev)
 {
 	u32 reg = readl(at91_rstc_base + AT91_RSTC_SR);
 	char *reason;
@@ -157,8 +162,15 @@ static void __init at91_reset_status(struct platform_device *pdev)
 		reason = "unknown reset";
 		break;
 	}
+	return reason;
+}
 
-	pr_info("AT91: Starting after %s\n", reason);
+static ssize_t reset_reason_show(struct device *dev,
+				 struct device_attribute *attr,
+				 char *buf)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	return strcpy(buf, at91_reset_reason(pdev));
 }
 
 static const struct of_device_id at91_ramc_of_match[] = {
@@ -250,7 +262,13 @@ static int at91_reset_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	at91_reset_status(pdev);
+	ret = device_create_file(&pdev->dev, &dev_attr_reset_reason);
+	if (ret) {
+		dev_err(&pdev->dev, "Could not create sysfs entry\n");
+		return ret;
+	}
+
+	pr_info("AT91: Starting after %s\n", at91_reset_reason(pdev));
 
 	return 0;
 }
-- 
1.9.1

                 reply	other threads:[~2016-01-21 16:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1453394120-15878-1-git-send-email-davidm@egauge.net \
    --to=davidm@egauge.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.