1 From 25434a394705d2de92c50981e31347db4074204a Mon Sep 17 00:00:00 2001
2 From: Samuel Holland <samuel@sholland.org>
3 Date: Thu, 26 Aug 2021 21:32:15 -0500
4 Subject: [PATCH 07/90] power: regulator: Add a driver for the AXP PMIC
7 The first AXP regulator converted to use the regulator uclass is the
8 drivevbus switch, since it is used by the USB PHY driver.
10 Signed-off-by: Samuel Holland <samuel@sholland.org>
12 drivers/power/regulator/Kconfig | 14 ++++++
13 drivers/power/regulator/Makefile | 1 +
14 drivers/power/regulator/axp_regulator.c | 58 +++++++++++++++++++++++++
15 3 files changed, 73 insertions(+)
16 create mode 100644 drivers/power/regulator/axp_regulator.c
18 --- a/drivers/power/regulator/Kconfig
19 +++ b/drivers/power/regulator/Kconfig
20 @@ -43,6 +43,20 @@ config REGULATOR_AS3722
21 but does not yet support change voltages. Currently this must be
22 done using direct register writes to the PMIC.
25 + bool "Enable driver for X-Powers AXP PMIC regulators"
26 + depends on DM_REGULATOR && PMIC_AXP
28 + Enable support for the regulators (DCDCs, LDOs) in the
29 + X-Powers AXP152, AXP2xx, and AXP8xx PMICs.
31 +config SPL_REGULATOR_AXP
32 + bool "Enable driver for X-Powers AXP PMIC regulators in SPL"
33 + depends on SPL_DM_REGULATOR && SPL_PMIC_AXP
35 + Enable support in SPL for the regulators (DCDCs, LDOs) in the
36 + X-Powers AXP152, AXP2xx, and AXP8xx PMICs.
38 config REGULATOR_AXP_USB_POWER
39 bool "Enable driver for X-Powers AXP PMIC USB power supply"
40 depends on DM_REGULATOR && PMIC_AXP
41 --- a/drivers/power/regulator/Makefile
42 +++ b/drivers/power/regulator/Makefile
44 obj-$(CONFIG_$(SPL_)DM_REGULATOR) += regulator-uclass.o
45 obj-$(CONFIG_REGULATOR_ACT8846) += act8846.o
46 obj-$(CONFIG_REGULATOR_AS3722) += as3722_regulator.o
47 +obj-$(CONFIG_$(SPL_)REGULATOR_AXP) += axp_regulator.o
48 obj-$(CONFIG_$(SPL_)REGULATOR_AXP_USB_POWER) += axp_usb_power.o
49 obj-$(CONFIG_$(SPL_)DM_REGULATOR_DA9063) += da9063.o
50 obj-$(CONFIG_DM_REGULATOR_MAX77686) += max77686.o
52 +++ b/drivers/power/regulator/axp_regulator.c
54 +// SPDX-License-Identifier: GPL-2.0+
58 +#include <power/pmic.h>
59 +#include <power/regulator.h>
61 +#define AXP_VBUS_IPSOUT 0x30
62 +#define AXP_VBUS_IPSOUT_DRIVEBUS BIT(2)
63 +#define AXP_MISC_CTRL 0x8f
64 +#define AXP_MISC_CTRL_N_VBUSEN_FUNC BIT(4)
66 +static int axp_drivevbus_get_enable(struct udevice *dev)
70 + ret = pmic_reg_read(dev->parent, AXP_VBUS_IPSOUT);
74 + return !!(ret & AXP_VBUS_IPSOUT_DRIVEBUS);
77 +static int axp_drivevbus_set_enable(struct udevice *dev, bool enable)
79 + return pmic_clrsetbits(dev->parent, AXP_VBUS_IPSOUT,
80 + AXP_VBUS_IPSOUT_DRIVEBUS,
81 + enable ? AXP_VBUS_IPSOUT_DRIVEBUS : 0);
84 +static const struct dm_regulator_ops axp_drivevbus_ops = {
85 + .get_enable = axp_drivevbus_get_enable,
86 + .set_enable = axp_drivevbus_set_enable,
89 +static int axp_drivevbus_probe(struct udevice *dev)
91 + struct dm_regulator_uclass_plat *uc_plat = dev_get_uclass_plat(dev);
94 + uc_plat->type = REGULATOR_TYPE_FIXED;
96 + if (dev_read_bool(dev->parent, "x-powers,drive-vbus-en")) {
97 + ret = pmic_clrsetbits(dev->parent, AXP_MISC_CTRL,
98 + AXP_MISC_CTRL_N_VBUSEN_FUNC, 0);
106 +U_BOOT_DRIVER(axp_drivevbus) = {
107 + .name = "axp_drivevbus",
108 + .id = UCLASS_REGULATOR,
109 + .probe = axp_drivevbus_probe,
110 + .ops = &axp_drivevbus_ops,