[PATCH v2 3/4] drivers: pmic: Add sysreset driver for da9063 PMIC

Alexandre Ghiti alexandre.ghiti at canonical.com
Fri Sep 24 10:42:30 CEST 2021


Some da9063 chips can't use the watchdog as a restart means since the OTP
does not set the AUTOBOOT bit [1]. So we need a new reset driver that
implements a small i2c sequence that will allow to reset the boards that
have this chip.

[1] https://www.dialog-semiconductor.com/products/pmics?post_id=10052#tab-support_tab_content

Signed-off-by: Alexandre Ghiti <alexandre.ghiti at canonical.com>
---
 drivers/power/pmic/da9063.c | 51 ++++++++++++++++++++++++++++++++++++-
 include/power/da9063_pmic.h |  1 +
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/drivers/power/pmic/da9063.c b/drivers/power/pmic/da9063.c
index 25101d18f7..eb470e4255 100644
--- a/drivers/power/pmic/da9063.c
+++ b/drivers/power/pmic/da9063.c
@@ -10,6 +10,8 @@
 #include <dm.h>
 #include <i2c.h>
 #include <log.h>
+#include <sysreset.h>
+#include <dm/lists.h>
 #include <power/pmic.h>
 #include <power/regulator.h>
 #include <power/da9063_pmic.h>
@@ -85,8 +87,9 @@ static int da9063_read(struct udevice *dev, uint reg, uint8_t *buff, int len)
 
 static int da9063_bind(struct udevice *dev)
 {
-	ofnode regulators_node;
+	ofnode regulators_node, reset_node;
 	int children;
+	int ret;
 
 	regulators_node = dev_read_subnode(dev, "regulators");
 	if (!ofnode_valid(regulators_node)) {
@@ -101,6 +104,17 @@ static int da9063_bind(struct udevice *dev)
 	if (!children)
 		debug("%s: %s - no child found\n", __func__, dev->name);
 
+	if (CONFIG_IS_ENABLED(SYSRESET)) {
+		reset_node = dev_read_subnode(dev, "reset");
+		if (ofnode_valid(reset_node)) {
+			ret = device_bind_driver(dev, DA9063_SYSRESET_DRIVER,
+						 DA9063_SYSRESET_DRIVER, NULL);
+			if (ret)
+				pr_err("%s: %s - failed to bind sysreset driver\n",
+				       __func__, dev->name);
+		}
+	}
+
 	/* Always return success for this device */
 	return 0;
 }
@@ -129,3 +143,38 @@ U_BOOT_DRIVER(pmic_da9063) = {
 	.probe = da9063_probe,
 	.ops = &da9063_ops,
 };
+
+static int da9063_sysreset_request(struct udevice *dev, enum sysreset_t type)
+{
+	struct udevice *pmic_dev = dev->parent;
+	uint ret;
+
+	if (type != SYSRESET_WARM && type != SYSRESET_COLD)
+		return -EPROTONOSUPPORT;
+
+	ret = pmic_reg_write(pmic_dev, DA9063_REG_PAGE_CON, 0x00);
+	if (ret < 0)
+		return ret;
+
+	/* Sets the WAKE_UP bit */
+	ret = pmic_reg_write(pmic_dev, DA9063_REG_CONTROL_F, 0x04);
+	if (ret < 0)
+		return ret;
+
+	/* Powerdown! */
+	ret = pmic_reg_write(pmic_dev, DA9063_REG_CONTROL_A, 0x68);
+	if (ret < 0)
+		return ret;
+
+	return -EINPROGRESS;
+}
+
+static struct sysreset_ops da9063_sysreset_ops = {
+	.request = da9063_sysreset_request,
+};
+
+U_BOOT_DRIVER(da9063_sysreset) = {
+	.name = DA9063_SYSRESET_DRIVER,
+	.id = UCLASS_SYSRESET,
+	.ops = &da9063_sysreset_ops,
+};
diff --git a/include/power/da9063_pmic.h b/include/power/da9063_pmic.h
index 273a07ef41..1c676c242a 100644
--- a/include/power/da9063_pmic.h
+++ b/include/power/da9063_pmic.h
@@ -304,6 +304,7 @@
 /* Drivers name */
 #define DA9063_LDO_DRIVER	"da9063_ldo"
 #define DA9063_BUCK_DRIVER	"da9063_buck"
+#define DA9063_SYSRESET_DRIVER	"da9063_sysreset"
 
 /* Regulator modes */
 enum {
-- 
2.30.2



More information about the U-Boot mailing list