[PATCH 3/6] MFD/DA9053: adapt driver to the current reset source framework

Juergen Borleis jbe at pengutronix.de
Tue Jun 16 04:56:06 PDT 2015


Since commit 106956783018635cef9a35bcb109073513d1ead4 barebox has a generic
framework to provide the reset reason to upper layers. Use it in the
DA9053 driver as well.

Signed-off-by: Juergen Borleis <jbe at pengutronix.de>
---
 drivers/mfd/Kconfig  |  6 ++++
 drivers/mfd/da9053.c | 79 ++++++++++++++++++++++------------------------------
 2 files changed, 40 insertions(+), 45 deletions(-)

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 3d230f1..8c8f537 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -8,6 +8,12 @@ config MFD_DA9053
 	depends on I2C
 	bool "DA9053 PMIC driver"
 
+config MFD_DA9053_RESET_SOURCE
+	depends on MFD_DA9053
+	bool "Reset source provider"
+	help
+	  This PMIC unit can provide the reset reason.
+
 config MFD_LP3972
 	depends on I2C
 	bool "LP3972 driver"
diff --git a/drivers/mfd/da9053.c b/drivers/mfd/da9053.c
index 4bce8cc..9294a6a 100644
--- a/drivers/mfd/da9053.c
+++ b/drivers/mfd/da9053.c
@@ -25,6 +25,7 @@
 #include <i2c/i2c.h>
 
 #include <asm/byteorder.h>
+#include <reset_source.h>
 
 #define DRIVERNAME		"da9053"
 
@@ -92,7 +93,6 @@ struct da9053_priv {
 	struct watchdog		wd;
 	struct i2c_client	*client;
 	unsigned int		param_shutdown;
-	unsigned int		param_faultlog;
 };
 
 #define cdev_to_da9053_priv(x)	container_of(x, struct da9053_priv, cdev)
@@ -178,45 +178,6 @@ static struct file_operations da9053_fops = {
 	.read	= da9053_read,
 };
 
-static int da9053_set_faultlog(struct param_d *param, void *priv)
-{
-	struct da9053_priv *da9053 = priv;
-	int ret;
-	u8 val;
-
-	val = da9053->param_faultlog & 0xff;
-	if (val) {
-		ret = da9053_reg_write(da9053, DA9053_FAULTLOG_REG, val);
-		if (ret < 0)
-			return ret;
-
-		ret = da9053_park(da9053);
-		if (ret < 0)
-			return ret;
-	}
-
-	return 0;
-}
-
-static int da9053_get_faultlog(struct param_d *param, void *priv)
-{
-	struct da9053_priv *da9053 = priv;
-	int ret;
-	u8 val;
-
-	ret = da9053_reg_read(da9053, DA9053_FAULTLOG_REG, &val);
-	if (ret < 0)
-		return ret;
-
-	ret = da9053_park(da9053);
-	if (ret < 0)
-		return ret;
-
-	da9053->param_faultlog = val;
-
-	return 0;
-}
-
 static int da9053_set_shutdown(struct param_d *param, void *priv)
 {
 	struct da9053_priv *da9053 = priv;
@@ -308,6 +269,37 @@ static int da9053_set_timeout(struct watchdog *wd, unsigned timeout)
 	return 0;
 }
 
+static void da9053_detect_reset_source(struct da9053_priv *da9053)
+{
+	int ret;
+	u8 val;
+
+	ret = da9053_reg_read(da9053, DA9053_FAULTLOG_REG, &val);
+	if (ret < 0)
+		return;
+
+	ret = da9053_park(da9053);
+	if (ret < 0)
+		return;
+
+	if (val & DA9053_FAULTLOG_TWDERROR) {
+		reset_source_set(RESET_WDG);
+		return;
+	}
+
+	if (val & DA9053_FAULTLOG_VDDFAULT) {
+		reset_source_set(RESET_POR);
+		return;
+	}
+
+	if (val & DA9053_FAULTLOG_NSDSET) {
+		reset_source_set(RESET_RST);
+		return;
+	}
+
+	/* else keep the default 'unknown' state */
+}
+
 static int da9053_probe(struct device_d *dev)
 {
 	struct da9053_priv *da9053;
@@ -327,11 +319,6 @@ static int da9053_probe(struct device_d *dev)
 	if (ret < 0)
 		return ret;
 
-	p = dev_add_param_int(dev, "faultlog", da9053_set_faultlog, da9053_get_faultlog,
-			      &da9053->param_faultlog, "0x%02x", da9053);
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
 	p = dev_add_param_bool(dev, "shutdown", da9053_set_shutdown, NULL,
 			       &da9053->param_shutdown, da9053);
 	if (IS_ERR(p))
@@ -343,6 +330,8 @@ static int da9053_probe(struct device_d *dev)
 	if (ret)
 		return ret;
 
+	if (IS_ENABLED(CONFIG_MFD_DA9053_RESET_SOURCE))
+		da9053_detect_reset_source(da9053);
 	return 0;
 }
 
-- 
2.1.4




More information about the barebox mailing list