]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
power: Add a regulator driver for the as3722 PMIC
authorSimon Glass <sjg@chromium.org>
Tue, 25 Jul 2017 14:30:10 +0000 (08:30 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 28 Jul 2017 18:02:47 +0000 (12:02 -0600)
This pmic includes regulators which should have their own driver. Add
a driver to support these.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Tested-on: Beaver, Jetson-TK1
Tested-by: Stephen Warren <swarren@nvidia.com>
drivers/power/regulator/Kconfig
drivers/power/regulator/Makefile
drivers/power/regulator/as3722_regulator.c [new file with mode: 0644]
include/power/as3722.h

index f2134874c277af66c50bba2c4ad1e3023f12faaf..c82a936e8af3d30f7c57dc97c20a41aee7fdf8e3 100644 (file)
@@ -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
index ce14d08fd4d86d20c52b1022f1c9492c6f1a56fc..18fb870e430ecce700a20bc18550a94e6abfdacb 100644 (file)
@@ -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 (file)
index 0000000..3e1e6f1
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2017 Google, Inc
+ * Written by Simon Glass <sjg@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 int 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 ret;
+       }
+
+       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 int 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 ret;
+       }
+
+       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,
+};
index 0f22482ff705f4cb7c3c5c9ae70b963e5415d55f..14afa0c81a8c78326890304e6a0849672cc35241 100644 (file)
 #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);