Merge branch '2019-05-28-master-imports'
[oweals/u-boot.git] / arch / arm / mach-sunxi / pmic_bus.c
index 5b81a8d8e127c950b6310348cc80d62049e788db..dea42de833f12bc48c2c48739c3fba8ac7d1224e 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
  *
@@ -5,8 +6,6 @@
  *
  * The axp152 & axp209 use an i2c bus, the axp221 uses the p2wi bus and the
  * axp223 uses the rsb bus, these functions abstract this.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -36,11 +35,14 @@ int pmic_bus_init(void)
        if (!needs_init)
                return 0;
 
-#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP818_POWER
+#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
 # ifdef CONFIG_MACH_SUN6I
        p2wi_init();
        ret = p2wi_change_to_p2wi_mode(AXP221_CHIP_ADDR, AXP221_CTRL_ADDR,
                                       AXP221_INIT_DATA);
+# elif defined CONFIG_MACH_SUN8I_R40
+       /* Nothing. R40 uses the AXP221s in I2C mode */
+       ret = 0;
 # else
        ret = rsb_init();
        if (ret)
@@ -62,9 +64,11 @@ int pmic_bus_read(u8 reg, u8 *data)
        return i2c_read(AXP152_I2C_ADDR, reg, 1, data, 1);
 #elif defined CONFIG_AXP209_POWER
        return i2c_read(AXP209_I2C_ADDR, reg, 1, data, 1);
-#elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP818_POWER
+#elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
 # ifdef CONFIG_MACH_SUN6I
        return p2wi_read(reg, data);
+# elif defined CONFIG_MACH_SUN8I_R40
+       return i2c_read(AXP209_I2C_ADDR, reg, 1, data, 1);
 # else
        return rsb_read(AXP223_RUNTIME_ADDR, reg, data);
 # endif
@@ -77,9 +81,11 @@ int pmic_bus_write(u8 reg, u8 data)
        return i2c_write(AXP152_I2C_ADDR, reg, 1, &data, 1);
 #elif defined CONFIG_AXP209_POWER
        return i2c_write(AXP209_I2C_ADDR, reg, 1, &data, 1);
-#elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP818_POWER
+#elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
 # ifdef CONFIG_MACH_SUN6I
        return p2wi_write(reg, data);
+# elif defined CONFIG_MACH_SUN8I_R40
+       return i2c_write(AXP209_I2C_ADDR, reg, 1, &data, 1);
 # else
        return rsb_write(AXP223_RUNTIME_ADDR, reg, data);
 # endif
@@ -95,6 +101,9 @@ int pmic_bus_setbits(u8 reg, u8 bits)
        if (ret)
                return ret;
 
+       if ((val & bits) == bits)
+               return 0;
+
        val |= bits;
        return pmic_bus_write(reg, val);
 }
@@ -108,6 +117,9 @@ int pmic_bus_clrbits(u8 reg, u8 bits)
        if (ret)
                return ret;
 
+       if (!(val & bits))
+               return 0;
+
        val &= ~bits;
        return pmic_bus_write(reg, val);
 }