]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sunxi: pmic_bus: Use the DM PMIC interface when possible
authorSamuel Holland <samuel@sholland.org>
Fri, 8 Oct 2021 05:17:23 +0000 (00:17 -0500)
committerAndre Przywara <andre.przywara@arm.com>
Tue, 12 Oct 2021 09:48:37 +0000 (10:48 +0100)
The pmic_bus functions are used in both SPL (for regulator setup) and
U-Boot proper (for regulator setup, SID access, GPIO, and poweroff).

Currently, pmic_bus conflicts with DM_I2C because it uses the legacy I2C
interface. This commit makes pmic_bus dual-compatible with either the
legacy I2C functions or the newly-added PMIC_AXP driver (which uses
DM_I2C). In turn, this allows platforms to start transitioning to DM_I2C
in U-Boot proper, without breaking boards that still depend on the
legacy I2C interface for other reasons.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
arch/arm/mach-sunxi/Kconfig
arch/arm/mach-sunxi/pmic_bus.c

index 10401d3249a7adecd6083762e9a3526399049323..83f8f9513f697c4fedc720f4a7cf3909e5732c08 100644 (file)
@@ -96,6 +96,8 @@ config SUN6I_PRCM
 
 config AXP_PMIC_BUS
        bool
+       select DM_PMIC if DM_I2C
+       select PMIC_AXP if DM_I2C
        help
          Select this PMIC bus access helpers for Sunxi platform PRCM or other
          AXP family PMIC devices.
index 20ded436cd2d48d340c437e3264b4c5578fa6fe5..c0908406370e0ccddcbb4da1a4157b103c8466a9 100644 (file)
 
 #include <axp_pmic.h>
 #include <common.h>
+#include <dm.h>
 #include <asm/arch/p2wi.h>
 #include <asm/arch/rsb.h>
 #include <i2c.h>
+#include <power/pmic.h>
 #include <asm/arch/pmic_bus.h>
 
 #define AXP152_I2C_ADDR                        0x30
@@ -23,6 +25,9 @@
 
 #define AXP221_CHIP_ADDR               0x68
 
+#if CONFIG_IS_ENABLED(PMIC_AXP)
+static struct udevice *pmic;
+#else
 static int pmic_i2c_address(void)
 {
        if (IS_ENABLED(CONFIG_AXP152_POWER))
@@ -33,6 +38,7 @@ static int pmic_i2c_address(void)
        /* Other AXP2xx and AXP8xx variants */
        return AXP209_I2C_ADDR;
 }
+#endif
 
 int pmic_bus_init(void)
 {
@@ -43,6 +49,10 @@ int pmic_bus_init(void)
        if (!needs_init)
                return 0;
 
+#if CONFIG_IS_ENABLED(PMIC_AXP)
+       ret = uclass_get_device_by_driver(UCLASS_PMIC, DM_DRIVER_GET(axp_pmic),
+                                         &pmic);
+#else
        if (IS_ENABLED(CONFIG_SYS_I2C_SUN6I_P2WI)) {
                p2wi_init();
                ret = p2wi_change_to_p2wi_mode(AXP221_CHIP_ADDR,
@@ -56,6 +66,7 @@ int pmic_bus_init(void)
                ret = rsb_set_device_address(AXP_PMIC_PRI_DEVICE_ADDR,
                                             AXP_PMIC_PRI_RUNTIME_ADDR);
        }
+#endif
 
        needs_init = ret;
 
@@ -64,22 +75,30 @@ int pmic_bus_init(void)
 
 int pmic_bus_read(u8 reg, u8 *data)
 {
+#if CONFIG_IS_ENABLED(PMIC_AXP)
+       return pmic_read(pmic, reg, data, 1);
+#else
        if (IS_ENABLED(CONFIG_SYS_I2C_SUN6I_P2WI))
                return p2wi_read(reg, data);
        if (IS_ENABLED(CONFIG_SYS_I2C_SUN8I_RSB))
                return rsb_read(AXP_PMIC_PRI_RUNTIME_ADDR, reg, data);
 
        return i2c_read(pmic_i2c_address(), reg, 1, data, 1);
+#endif
 }
 
 int pmic_bus_write(u8 reg, u8 data)
 {
+#if CONFIG_IS_ENABLED(PMIC_AXP)
+       return pmic_write(pmic, reg, &data, 1);
+#else
        if (IS_ENABLED(CONFIG_SYS_I2C_SUN6I_P2WI))
                return p2wi_write(reg, data);
        if (IS_ENABLED(CONFIG_SYS_I2C_SUN8I_RSB))
                return rsb_write(AXP_PMIC_PRI_RUNTIME_ADDR, reg, data);
 
        return i2c_write(pmic_i2c_address(), reg, 1, &data, 1);
+#endif
 }
 
 int pmic_bus_setbits(u8 reg, u8 bits)