sunxi: gpio: Add support for gpio pins on the AXP209 pmic

Some boards use GPIO-s on the pmic, one example of this is the A13-OLinuXino
board, which uses gpio0 of the axp209 for the lcd-power signal.

This commit adds support for gpio pins on the AXP209 pmic, the sunxi_gpio.c
changes are universal, adding gpio support for the other AXP pmics (when
necessary) should be a matter of adding the necessary axp_gpio_foo functions
to their resp. drivers, and add "#define AXP_GPIO" to their header file.

Note this commit only adds support for the non device-model version of the
gpio code, patches for adding support to the device-model version are very
welcome.

The string representation for these gpio-s is AXP0-#, the 0 in the AXP0 prefix
is there in case we need to support gpio-s on more then 1 pmic in the future.
At least A80 boards have 2 pmics, and we may end up needing to support gpio-s
on both.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>
diff --git a/drivers/gpio/sunxi_gpio.c b/drivers/gpio/sunxi_gpio.c
index 2fa50f9..6296092 100644
--- a/drivers/gpio/sunxi_gpio.c
+++ b/drivers/gpio/sunxi_gpio.c
@@ -18,6 +18,9 @@
 #include <asm/io.h>
 #include <asm/gpio.h>
 #include <dm/device-internal.h>
+#ifdef CONFIG_AXP209_POWER
+#include <axp209.h>
+#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -73,6 +76,10 @@
 
 int gpio_direction_input(unsigned gpio)
 {
+#ifdef AXP_GPIO
+	if (gpio >= SUNXI_GPIO_AXP0_START)
+		return axp_gpio_direction_input(gpio - SUNXI_GPIO_AXP0_START);
+#endif
 	sunxi_gpio_set_cfgpin(gpio, SUNXI_GPIO_INPUT);
 
 	return 0;
@@ -80,6 +87,11 @@
 
 int gpio_direction_output(unsigned gpio, int value)
 {
+#ifdef AXP_GPIO
+	if (gpio >= SUNXI_GPIO_AXP0_START)
+		return axp_gpio_direction_output(gpio - SUNXI_GPIO_AXP0_START,
+						 value);
+#endif
 	sunxi_gpio_set_cfgpin(gpio, SUNXI_GPIO_OUTPUT);
 
 	return sunxi_gpio_output(gpio, value);
@@ -87,11 +99,19 @@
 
 int gpio_get_value(unsigned gpio)
 {
+#ifdef AXP_GPIO
+	if (gpio >= SUNXI_GPIO_AXP0_START)
+		return axp_gpio_get_value(gpio - SUNXI_GPIO_AXP0_START);
+#endif
 	return sunxi_gpio_input(gpio);
 }
 
 int gpio_set_value(unsigned gpio, int value)
 {
+#ifdef AXP_GPIO
+	if (gpio >= SUNXI_GPIO_AXP0_START)
+		return axp_gpio_set_value(gpio - SUNXI_GPIO_AXP0_START, value);
+#endif
 	return sunxi_gpio_output(gpio, value);
 }
 
@@ -101,6 +121,16 @@
 	int groupsize = 9 * 32;
 	long pin;
 	char *eptr;
+
+#ifdef AXP_GPIO
+	if (strncasecmp(name, "AXP0-", 5) == 0) {
+		name += 5;
+		pin = simple_strtol(name, &eptr, 10);
+		if (!*name || *eptr)
+			return -1;
+		return SUNXI_GPIO_AXP0_START + pin;
+	}
+#endif
 	if (*name == 'P' || *name == 'p')
 		name++;
 	if (*name >= 'A') {