]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
allwinner: Return the PMIC to I2C mode after use
authorSamuel Holland <samuel@sholland.org>
Mon, 14 Dec 2020 04:43:15 +0000 (22:43 -0600)
committerSamuel Holland <samuel@sholland.org>
Mon, 14 Dec 2020 04:58:21 +0000 (22:58 -0600)
This gives the rich OS the flexibility to choose between I2C and RSB
communication. Since a runtime address can only be assigned once after
entering RSB mode, it also lets the rich OS choose any runtime address.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Change-Id: Id49c124c5e925985fc31c0ba38c7fb6c941aafa8

include/drivers/allwinner/axp.h
plat/allwinner/sun50i_a64/sunxi_power.c

index 9c0035f96bd7b04995387ef4571da2a6727ae3ca..222820b12030257beb1c513e40fbaceb475b64b1 100644 (file)
@@ -9,6 +9,10 @@
 
 #include <stdint.h>
 
+#define AXP20X_MODE_REG 0x3e
+#define AXP20X_MODE_I2C 0x00
+#define AXP20X_MODE_RSB 0x7c
+
 #define NA 0xff
 
 enum {
index 8aa610cc3a2bef2b85c7160b86f1450c8ad3ba7f..80a69c3404336e7374b257bfc88cba21cf0bd834 100644 (file)
@@ -97,11 +97,8 @@ static int rsb_init(void)
        if (ret)
                return ret;
 
-       /*
-        * Initiate an I2C transaction to write 0x7c into register 0x3e,
-        * switching the PMIC to RSB mode.
-        */
-       ret = rsb_set_device_mode(0x7c3e00);
+       /* Initiate an I2C transaction to switch the PMIC to RSB mode. */
+       ret = rsb_set_device_mode(AXP20X_MODE_RSB << 16 | AXP20X_MODE_REG << 8);
        if (ret)
                return ret;
 
@@ -151,6 +148,11 @@ int sunxi_pmic_setup(uint16_t socid, const void *fdt)
                pmic = AXP803_RSB;
                axp_setup_regulators(fdt);
 
+               /* Switch the PMIC back to I2C mode. */
+               ret = axp_write(AXP20X_MODE_REG, AXP20X_MODE_I2C);
+               if (ret)
+                       return ret;
+
                break;
        default:
                return -ENODEV;