[U-Boot] [PATCH 18/26] power: Add a regulator driver for the as3722 PMIC

Simon Glass sjg at chromium.org
Fri May 19 14:31:01 UTC 2017


This pmic includes regulators which should have their own driver. Add
a driver to support these.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/power/regulator/Kconfig            |   9 ++
 drivers/power/regulator/Makefile           |   1 +
 drivers/power/regulator/as3722_regulator.c | 149 +++++++++++++++++++++++++++++
 include/power/as3722.h                     |   8 ++
 4 files changed, 167 insertions(+)
 create mode 100644 drivers/power/regulator/as3722_regulator.c

diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig
index ef057e0e2f..2583a19910 100644
--- a/drivers/power/regulator/Kconfig
+++ b/drivers/power/regulator/Kconfig
@@ -34,6 +34,15 @@ config REGULATOR_ACT8846
 	by the PMIC device. This driver is controlled by a device tree node
 	which includes voltage limits.
 
+config REGULATOR_AS3722
+	bool "Enable driver for AS7322 regulator"
+	depends on DM_REGULATOR && PMIC_AS3722
+	help
+	  Enable support for the regulator functions of the AS3722. The
+	  driver implements enable/disable for step-down bucks and LDOs,
+	  but does not yet support change voltages. Currently this must be
+	  done using direct register writes to the PMIC.
+
 config DM_REGULATOR_PFUZE100
 	bool "Enable Driver Model for REGULATOR PFUZE100"
 	depends on DM_REGULATOR && DM_PMIC_PFUZE100
diff --git a/drivers/power/regulator/Makefile b/drivers/power/regulator/Makefile
index 3e01021b76..48d3735d6c 100644
--- a/drivers/power/regulator/Makefile
+++ b/drivers/power/regulator/Makefile
@@ -7,6 +7,7 @@
 
 obj-$(CONFIG_$(SPL_)DM_REGULATOR) += regulator-uclass.o
 obj-$(CONFIG_REGULATOR_ACT8846) += act8846.o
+obj-$(CONFIG_REGULATOR_AS3722)	+= as3722_regulator.o
 obj-$(CONFIG_DM_REGULATOR_MAX77686) += max77686.o
 obj-$(CONFIG_DM_REGULATOR_PFUZE100) += pfuze100.o
 obj-$(CONFIG_REGULATOR_PWM) += pwm_regulator.o
diff --git a/drivers/power/regulator/as3722_regulator.c b/drivers/power/regulator/as3722_regulator.c
new file mode 100644
index 0000000000..0122e1e389
--- /dev/null
+++ b/drivers/power/regulator/as3722_regulator.c
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2017 Google, Inc
+ * Written by Simon Glass <sjg at chromium.org>
+ *
+ * Placeholder regulator driver for as3722.
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <power/as3722.h>
+#include <power/pmic.h>
+#include <power/regulator.h>
+
+static int stepdown_get_value(struct udevice *dev)
+{
+	return -ENOSYS;
+}
+
+static int stepdown_set_value(struct udevice *dev, int uvolt)
+{
+	return -ENOSYS;
+}
+
+static int stepdown_set_enable(struct udevice *dev, bool enable)
+{
+	struct udevice *pmic = dev_get_parent(dev);
+	int sd = dev->driver_data;
+	int ret;
+
+	ret = pmic_clrsetbits(pmic, AS3722_SD_CONTROL, 0, 1 << sd);
+	if (ret < 0) {
+		debug("%s: failed to write SD control register: %d", __func__,
+		      ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static bool stepdown_get_enable(struct udevice *dev)
+{
+	struct udevice *pmic = dev_get_parent(dev);
+	int sd = dev->driver_data;
+	int ret;
+
+	ret = pmic_reg_read(pmic, AS3722_SD_CONTROL);
+	if (ret < 0) {
+		debug("%s: failed to read SD control register: %d", __func__,
+		      ret);
+		return false;
+	}
+
+	return ret & (1 << sd) ? true : false;
+}
+
+static int ldo_get_value(struct udevice *dev)
+{
+	return -ENOSYS;
+}
+
+static int ldo_set_value(struct udevice *dev, int uvolt)
+{
+	return -ENOSYS;
+}
+
+static int ldo_set_enable(struct udevice *dev, bool enable)
+{
+	struct udevice *pmic = dev_get_parent(dev);
+	int ldo = dev->driver_data;
+	int ret;
+
+	ret = pmic_clrsetbits(pmic, AS3722_LDO_CONTROL, 0, 1 << ldo);
+	if (ret < 0) {
+		debug("%s: failed to write LDO control register: %d", __func__,
+		      ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static bool ldo_get_enable(struct udevice *dev)
+{
+	struct udevice *pmic = dev_get_parent(dev);
+	int ldo = dev->driver_data;
+	int ret;
+
+	ret = pmic_reg_read(pmic, AS3722_LDO_CONTROL);
+	if (ret < 0) {
+		debug("%s: failed to read SD control register: %d", __func__,
+		      ret);
+		return false;
+	}
+
+	return ret & (1 << ldo) ? true : false;
+}
+
+static int as3722_stepdown_probe(struct udevice *dev)
+{
+	struct dm_regulator_uclass_platdata *uc_pdata;
+
+	uc_pdata = dev_get_uclass_platdata(dev);
+
+	uc_pdata->type = REGULATOR_TYPE_BUCK;
+
+	return 0;
+}
+
+static int as3722_ldo_probe(struct udevice *dev)
+{
+	struct dm_regulator_uclass_platdata *uc_pdata;
+
+	uc_pdata = dev_get_uclass_platdata(dev);
+
+	uc_pdata->type = REGULATOR_TYPE_LDO;
+
+	return 0;
+}
+
+static const struct dm_regulator_ops as3722_stepdown_ops = {
+	.get_value  = stepdown_get_value,
+	.set_value  = stepdown_set_value,
+	.get_enable = stepdown_get_enable,
+	.set_enable = stepdown_set_enable,
+};
+
+static const struct dm_regulator_ops as3722_ldo_ops = {
+	.get_value  = ldo_get_value,
+	.set_value  = ldo_set_value,
+	.get_enable = ldo_get_enable,
+	.set_enable = ldo_set_enable,
+};
+
+U_BOOT_DRIVER(as3722_stepdown) = {
+	.name = "as3722_stepdown",
+	.id = UCLASS_REGULATOR,
+	.ops = &as3722_stepdown_ops,
+	.probe = as3722_stepdown_probe,
+};
+
+U_BOOT_DRIVER(as3722_ldo) = {
+	.name = "as3722_ldo",
+	.id = UCLASS_REGULATOR,
+	.ops = &as3722_ldo_ops,
+	.probe = as3722_ldo_probe,
+};
diff --git a/include/power/as3722.h b/include/power/as3722.h
index 0f22482ff7..14afa0c81a 100644
--- a/include/power/as3722.h
+++ b/include/power/as3722.h
@@ -12,6 +12,14 @@
 #define AS3722_GPIO_OUTPUT_VDDH (1 << 0)
 #define AS3722_GPIO_INVERT (1 << 1)
 
+#define AS3722_DEVICE_ID 0x0c
+#define AS3722_SD_VOLTAGE(n) (0x00 + (n))
+#define AS3722_LDO_VOLTAGE(n) (0x10 + (n))
+#define AS3722_SD_CONTROL 0x4d
+#define AS3722_LDO_CONTROL 0x4e
+#define AS3722_ASIC_ID1 0x90
+#define AS3722_ASIC_ID2 0x91
+
 struct udevice;
 
 int as3722_init(struct udevice **devp);
-- 
2.13.0.303.g4ebf302169-goog



More information about the U-Boot mailing list