[U-Boot] [PATCH RFC 11/17] sunxi: axp: Generalize register macros for VBUS drive GPIO

Chen-Yu Tsai
2016-03-29T16:26:56Z

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>
---
drivers/gpio/axp_gpio.c | 25 ++++++++++++++-----------
include/axp221.h | 8 ++++----
2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/gpio/axp_gpio.c b/drivers/gpio/axp_gpio.c
index bd2ac89..ec00827 100644
--- a/drivers/gpio/axp_gpio.c
+++ b/drivers/gpio/axp_gpio.c
@@ -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);
diff --git a/include/axp221.h b/include/axp221.h
index 04cd8c2..b4b64b0 100644
--- a/include/axp221.h
+++ b/include/axp221.h
@@ -43,12 +43,8 @@
#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 */
@@ -57,6 +53,10 @@
/* 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 */
--
2.7.0