[PATCH 4/6] MFD/DA9053: provide system reset

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux