mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Juergen Borleis <jbe@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/6] MFD/DA9053: provide system reset
Date: Tue, 16 Jun 2015 13:56:07 +0200	[thread overview]
Message-ID: <1434455769-17216-4-git-send-email-jbe@pengutronix.de> (raw)
In-Reply-To: <1434455769-17216-1-git-send-email-jbe@pengutronix.de>

When using power management features like voltage regulators when switching
down the CPU clock speed, a SoC reset must also reset the power supplies to
their expected values after a POR. Most internal units (like watchdogs used to
reset the SoC) are not able to signal the SoC reset to external devices. This
can end up in various and unpredictable system crashes because the CPU restarts
with the expectation the power supplies were also reset.

By using the reset feature of the PMIC unit this expectation about the power
supplies is always true.

Downside of this approach: the SoC cannot longer detect the reset reason with
its own mechanism. Each PMIC based reset looks like a POR from the SoC's point
of view.

Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
---
 drivers/mfd/Kconfig  |  6 ++++++
 drivers/mfd/da9053.c | 61 +++++++++++++++++++++++-----------------------------
 2 files changed, 33 insertions(+), 34 deletions(-)

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 8c8f537..bf012bf 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -14,6 +14,12 @@ config MFD_DA9053_RESET_SOURCE
 	help
 	  This PMIC unit can provide the reset reason.
 
+config MFD_DA9053_RESET_FEATURE
+	depends on MFD_DA9053
+	bool "Use for system reset"
+	help
+	  This PMIC unit can be used to reset/restart the system.
+
 config MFD_LP3972
 	depends on I2C
 	bool "LP3972 driver"
diff --git a/drivers/mfd/da9053.c b/drivers/mfd/da9053.c
index 9294a6a..b376d8d 100644
--- a/drivers/mfd/da9053.c
+++ b/drivers/mfd/da9053.c
@@ -20,7 +20,6 @@
 #include <xfuncs.h>
 #include <errno.h>
 #include <watchdog.h>
-#include <linux/err.h>
 
 #include <i2c/i2c.h>
 
@@ -92,7 +91,6 @@ struct da9053_priv {
 	struct cdev		cdev;
 	struct watchdog		wd;
 	struct i2c_client	*client;
-	unsigned int		param_shutdown;
 };
 
 #define cdev_to_da9053_priv(x)	container_of(x, struct da9053_priv, cdev)
@@ -178,30 +176,6 @@ static struct file_operations da9053_fops = {
 	.read	= da9053_read,
 };
 
-static int da9053_set_shutdown(struct param_d *param, void *priv)
-{
-	struct da9053_priv *da9053 = priv;
-	int ret;
-	u8 val;
-
-	if (da9053->param_shutdown) {
-		ret = da9053_reg_read(da9053, DA9053_CONTROL_B_REG, &val);
-		if (ret < 0)
-			return ret;
-
-		val |= DA9053_CONTROLB_SHUTDOWN;
-		ret = da9053_reg_write(da9053, DA9053_CONTROL_B_REG, val);
-		if (ret < 0)
-			return ret;
-
-		ret = da9053_park(da9053);
-		if (ret < 0)
-			return ret;
-	}
-
-	return 0;
-}
-
 static int da9053_set_timeout(struct watchdog *wd, unsigned timeout)
 {
 	struct da9053_priv *da9053 = wd_to_da9053_priv(wd);
@@ -300,10 +274,31 @@ static void da9053_detect_reset_source(struct da9053_priv *da9053)
 	/* else keep the default 'unknown' state */
 }
 
+#ifdef CONFIG_MFD_DA9053_RESET_FEATURE
+static struct da9053_priv *wd_da9053;
+void __noreturn reset_cpu(unsigned long addr)
+{
+	u8 val;
+	int ret;
+
+	ret = da9053_reg_read(wd_da9053, DA9053_CONTROL_B_REG, &val);
+	if (ret < 0)
+		hang();
+
+	val |= DA9053_CONTROLB_SHUTDOWN;
+	ret = da9053_reg_write(wd_da9053, DA9053_CONTROL_B_REG, val);
+	if (ret < 0)
+		hang();
+
+	da9053_park(wd_da9053);
+
+	hang();
+}
+#endif
+
 static int da9053_probe(struct device_d *dev)
 {
 	struct da9053_priv *da9053;
-	struct param_d *p;
 	int ret;
 
 	da9053 = xzalloc(sizeof(struct da9053_priv));
@@ -319,19 +314,17 @@ static int da9053_probe(struct device_d *dev)
 	if (ret < 0)
 		return ret;
 
-	p = dev_add_param_bool(dev, "shutdown", da9053_set_shutdown, NULL,
-			       &da9053->param_shutdown, da9053);
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	devfs_create(&da9053->cdev);
-
 	ret = watchdog_register(&da9053->wd);
 	if (ret)
 		return ret;
 
 	if (IS_ENABLED(CONFIG_MFD_DA9053_RESET_SOURCE))
 		da9053_detect_reset_source(da9053);
+
+#ifdef CONFIG_MFD_DA9053_RESET_FEATURE
+	if (wd_da9053 == NULL)
+		wd_da9053 = da9053;
+#endif
 	return 0;
 }
 
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2015-06-16 11:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-16 11:56 [PATCH 1/6] Documentation: add some info about the reset variants Juergen Borleis
2015-06-16 11:56 ` [PATCH 2/6] Watchdog/i.MX: make the watchdog driver a regular driver Juergen Borleis
2015-06-16 11:56 ` [PATCH 3/6] MFD/DA9053: adapt driver to the current reset source framework Juergen Borleis
2015-06-16 11:56 ` Juergen Borleis [this message]
2015-06-16 11:56 ` [PATCH 5/6] MFD/DA9053: remove not required header file Juergen Borleis
2015-06-16 11:56 ` [PATCH 6/6] mfd: da9063: add da9063 watchdog and system restart driver Juergen Borleis
2015-06-16 12:05 ` [PATCH 1/6] Documentation: add some info about the reset variants Jürgen Borleis

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=1434455769-17216-4-git-send-email-jbe@pengutronix.de \
    --to=jbe@pengutronix.de \
    --cc=barebox@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox