sunxi: axp: Generalize register macros for VBUS drive GPIO
authorChen-Yu Tsai <wens@csie.org>
Tue, 29 Mar 2016 16:26:56 +0000 (00:26 +0800)
committerHans de Goede <hdegoede@redhat.com>
Thu, 31 Mar 2016 15:03:52 +0000 (17:03 +0200)
VBUS drive is supported on AXP221 and later PMICs. Rework the macros
so we can support this on later PMICs without too much work.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/gpio/axp_gpio.c
include/axp221.h

index bd2ac892d088d8fde21edf4cf2805cdf7eafe2c3..ec00827f8f80e8d25b0ea0adc2113fd47c8ffe35 100644 (file)
@@ -59,10 +59,11 @@ static int axp_gpio_direction_output(struct udevice *dev, unsigned pin,
        u8 reg;
 
        switch (pin) {
-#ifdef CONFIG_AXP221_POWER /* Only available on axp221/axp223 */
+#ifdef AXP_MISC_CTRL_N_VBUSEN_FUNC
+       /* Only available on later PMICs */
        case SUNXI_GPIO_AXP0_VBUS_ENABLE:
-               ret = pmic_bus_clrbits(AXP221_MISC_CTRL,
-                                      AXP221_MISC_CTRL_N_VBUSEN_FUNC);
+               ret = pmic_bus_clrbits(AXP_MISC_CTRL,
+                                      AXP_MISC_CTRL_N_VBUSEN_FUNC);
                if (ret)
                        return ret;
 
@@ -90,10 +91,11 @@ static int axp_gpio_get_value(struct udevice *dev, unsigned pin)
                mask = AXP_POWER_STATUS_VBUS_PRESENT;
                break;
 #endif
-#ifdef CONFIG_AXP221_POWER /* Only available on axp221/axp223 */
+#ifdef AXP_MISC_CTRL_N_VBUSEN_FUNC
+       /* Only available on later PMICs */
        case SUNXI_GPIO_AXP0_VBUS_ENABLE:
-               ret = pmic_bus_read(AXP221_VBUS_IPSOUT, &val);
-               mask = AXP221_VBUS_IPSOUT_DRIVEBUS;
+               ret = pmic_bus_read(AXP_VBUS_IPSOUT, &val);
+               mask = AXP_VBUS_IPSOUT_DRIVEBUS;
                break;
 #endif
        default:
@@ -115,14 +117,15 @@ static int axp_gpio_set_value(struct udevice *dev, unsigned pin, int val)
        u8 reg;
 
        switch (pin) {
-#ifdef CONFIG_AXP221_POWER /* Only available on axp221/axp223 */
+#ifdef AXP_MISC_CTRL_N_VBUSEN_FUNC
+       /* Only available on later PMICs */
        case SUNXI_GPIO_AXP0_VBUS_ENABLE:
                if (val)
-                       return pmic_bus_setbits(AXP221_VBUS_IPSOUT,
-                                               AXP221_VBUS_IPSOUT_DRIVEBUS);
+                       return pmic_bus_setbits(AXP_VBUS_IPSOUT,
+                                               AXP_VBUS_IPSOUT_DRIVEBUS);
                else
-                       return pmic_bus_clrbits(AXP221_VBUS_IPSOUT,
-                                               AXP221_VBUS_IPSOUT_DRIVEBUS);
+                       return pmic_bus_clrbits(AXP_VBUS_IPSOUT,
+                                               AXP_VBUS_IPSOUT_DRIVEBUS);
 #endif
        default:
                reg = axp_get_gpio_ctrl_reg(pin);
index 04cd8c2be48b2e516cc3c27fb755626e091d2a4b..b4b64b0e870ca2f2eab9a8dd350b0c6cf1e4a9cc 100644 (file)
 #define AXP221_ALDO1_CTRL      0x28
 #define AXP221_ALDO2_CTRL      0x29
 #define AXP221_ALDO3_CTRL      0x2a
-#define AXP221_VBUS_IPSOUT     0x30
-#define AXP221_VBUS_IPSOUT_DRIVEBUS    (1 << 2)
 #define AXP221_SHUTDOWN                0x32
 #define AXP221_SHUTDOWN_POWEROFF       (1 << 7)
-#define AXP221_MISC_CTRL       0x8f
-#define AXP221_MISC_CTRL_N_VBUSEN_FUNC (1 << 4)
 #define AXP221_PAGE            0xff
 
 /* Page 1 addresses */
 /* For axp_gpio.c */
 #define AXP_POWER_STATUS               0x00
 #define AXP_POWER_STATUS_VBUS_PRESENT          (1 << 5)
+#define AXP_VBUS_IPSOUT                        0x30
+#define AXP_VBUS_IPSOUT_DRIVEBUS               (1 << 2)
+#define AXP_MISC_CTRL                  0x8f
+#define AXP_MISC_CTRL_N_VBUSEN_FUNC            (1 << 4)
 #define AXP_GPIO0_CTRL                 0x90
 #define AXP_GPIO1_CTRL                 0x92
 #define AXP_GPIO_CTRL_OUTPUT_LOW               0x00 /* Drive pin low */