uboot-d1: add bootloader for upcoming d1 target
[openwrt/staging/981213.git] / package / boot / uboot-d1 / patches / 0007-power-regulator-Add-a-driver-for-the-AXP-PMIC-drivev.patch
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
5 drivevbus
6
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.
9
10 Signed-off-by: Samuel Holland <samuel@sholland.org>
11 ---
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
17
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.
23
24 +config REGULATOR_AXP
25 + bool "Enable driver for X-Powers AXP PMIC regulators"
26 + depends on DM_REGULATOR && PMIC_AXP
27 + help
28 + Enable support for the regulators (DCDCs, LDOs) in the
29 + X-Powers AXP152, AXP2xx, and AXP8xx PMICs.
30 +
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
34 + help
35 + Enable support in SPL for the regulators (DCDCs, LDOs) in the
36 + X-Powers AXP152, AXP2xx, and AXP8xx PMICs.
37 +
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
43 @@ -7,6 +7,7 @@
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
51 --- /dev/null
52 +++ b/drivers/power/regulator/axp_regulator.c
53 @@ -0,0 +1,58 @@
54 +// SPDX-License-Identifier: GPL-2.0+
55 +
56 +#include <dm.h>
57 +#include <errno.h>
58 +#include <power/pmic.h>
59 +#include <power/regulator.h>
60 +
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)
65 +
66 +static int axp_drivevbus_get_enable(struct udevice *dev)
67 +{
68 + int ret;
69 +
70 + ret = pmic_reg_read(dev->parent, AXP_VBUS_IPSOUT);
71 + if (ret < 0)
72 + return ret;
73 +
74 + return !!(ret & AXP_VBUS_IPSOUT_DRIVEBUS);
75 +}
76 +
77 +static int axp_drivevbus_set_enable(struct udevice *dev, bool enable)
78 +{
79 + return pmic_clrsetbits(dev->parent, AXP_VBUS_IPSOUT,
80 + AXP_VBUS_IPSOUT_DRIVEBUS,
81 + enable ? AXP_VBUS_IPSOUT_DRIVEBUS : 0);
82 +}
83 +
84 +static const struct dm_regulator_ops axp_drivevbus_ops = {
85 + .get_enable = axp_drivevbus_get_enable,
86 + .set_enable = axp_drivevbus_set_enable,
87 +};
88 +
89 +static int axp_drivevbus_probe(struct udevice *dev)
90 +{
91 + struct dm_regulator_uclass_plat *uc_plat = dev_get_uclass_plat(dev);
92 + int ret;
93 +
94 + uc_plat->type = REGULATOR_TYPE_FIXED;
95 +
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);
99 + if (ret)
100 + return ret;
101 + }
102 +
103 + return 0;
104 +}
105 +
106 +U_BOOT_DRIVER(axp_drivevbus) = {
107 + .name = "axp_drivevbus",
108 + .id = UCLASS_REGULATOR,
109 + .probe = axp_drivevbus_probe,
110 + .ops = &axp_drivevbus_ops,
111 +};