summaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2015-03-22 18:07:09 +0100
committerHans de Goede <hdegoede@redhat.com>2015-04-15 16:17:17 +0200
commitf7c7ab636ab2c81d9fb1def7256c94b998c7298f (patch)
tree3b6126d1c3be0916c745c595f2aa95abbc6707cc /drivers/power
parent991963bce9e3a8f51499785c736ec54e527f3a2b (diff)
downloadtalos-obmc-uboot-f7c7ab636ab2c81d9fb1def7256c94b998c7298f.tar.gz
talos-obmc-uboot-f7c7ab636ab2c81d9fb1def7256c94b998c7298f.zip
power: axp221: Virtual VBUS detect and enable GPIOs to replace separate logic
This converts the VBUS detection and enable logic to GPIO instead of separate axp functions and checks that have to be used aside usual GPIO functions. Signed-off-by: Paul Kocialkowski <contact@paulk.fr> Acked-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/axp221.c75
1 files changed, 44 insertions, 31 deletions
diff --git a/drivers/power/axp221.c b/drivers/power/axp221.c
index c2c3988804..f758a75e9a 100644
--- a/drivers/power/axp221.c
+++ b/drivers/power/axp221.c
@@ -14,6 +14,7 @@
#include <errno.h>
#include <asm/arch/p2wi.h>
#include <asm/arch/rsb.h>
+#include <asm/arch/gpio.h>
#include <axp221.h>
/*
@@ -385,54 +386,66 @@ int axp221_get_sid(unsigned int *sid)
return 0;
}
-int axp_get_vbus(void)
+int axp_gpio_direction_input(unsigned int pin)
{
- int ret;
- u8 val;
-
- ret = axp221_init();
- if (ret)
- return ret;
-
- ret = pmic_bus_read(AXP221_POWER_STATUS, &val);
- if (ret)
- return ret;
-
- return (val & AXP221_POWER_STATUS_VBUS_USABLE) ? 1 : 0;
+ switch (pin) {
+ case SUNXI_GPIO_AXP0_VBUS_DETECT:
+ return 0;
+ default:
+ return -EINVAL;
+ }
}
-static int axp_drivebus_setup(void)
+int axp_gpio_direction_output(unsigned int pin, unsigned int val)
{
int ret;
- ret = axp221_init();
- if (ret)
- return ret;
+ switch (pin) {
+ case SUNXI_GPIO_AXP0_VBUS_ENABLE:
+ ret = axp221_clrbits(AXP221_MISC_CTRL,
+ AXP221_MISC_CTRL_N_VBUSEN_FUNC);
+ if (ret)
+ return ret;
- /* Set N_VBUSEN pin to output / DRIVEBUS function */
- return axp221_clrbits(AXP221_MISC_CTRL, AXP221_MISC_CTRL_N_VBUSEN_FUNC);
+ return axp_gpio_set_value(pin, val);
+ default:
+ return -EINVAL;
+ }
}
-int axp_drivebus_enable(void)
+int axp_gpio_get_value(unsigned int pin)
{
int ret;
+ u8 val;
- ret = axp_drivebus_setup();
- if (ret)
- return ret;
+ switch (pin) {
+ case SUNXI_GPIO_AXP0_VBUS_DETECT:
+ ret = pmic_bus_read(AXP221_POWER_STATUS, &val);
+ if (ret)
+ return ret;
- /* Set DRIVEBUS high */
- return axp221_setbits(AXP221_VBUS_IPSOUT, AXP221_VBUS_IPSOUT_DRIVEBUS);
+ return !!(val & AXP221_POWER_STATUS_VBUS_USABLE);
+ default:
+ return -EINVAL;
+ }
}
-int axp_drivebus_disable(void)
+int axp_gpio_set_value(unsigned int pin, unsigned int val)
{
int ret;
- ret = axp_drivebus_setup();
- if (ret)
- return ret;
+ switch (pin) {
+ case SUNXI_GPIO_AXP0_VBUS_ENABLE:
+ if (val)
+ ret = axp221_setbits(AXP221_VBUS_IPSOUT,
+ AXP221_VBUS_IPSOUT_DRIVEBUS);
+ else
+ ret = axp221_clrbits(AXP221_VBUS_IPSOUT,
+ AXP221_VBUS_IPSOUT_DRIVEBUS);
- /* Set DRIVEBUS low */
- return axp221_clrbits(AXP221_VBUS_IPSOUT, AXP221_VBUS_IPSOUT_DRIVEBUS);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
}
OpenPOWER on IntegriCloud