diff mbox

[U-Boot,v2,5/6] sunxi: axp: Add driver-model support to the axp_gpio code

Message ID 1430041887-20790-6-git-send-email-hdegoede@redhat.com
State Accepted
Delegated to: Hans de Goede
Headers show

Commit Message

Hans de Goede April 26, 2015, 9:51 a.m. UTC
Add driver-model support to the axp_gpio code, note that this needs a small
tweak to the driver-model version of sunxi_name_to_gpio to deal with the
vbus detect and enable pins which are not standard numbered gpios.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 arch/arm/include/asm/arch-sunxi/gpio.h |  6 ++++--
 drivers/gpio/axp_gpio.c                | 39 ++++++++++++++++++++++++++++++++++
 drivers/gpio/sunxi_gpio.c              | 14 +++++++++++-
 3 files changed, 56 insertions(+), 3 deletions(-)

Comments

Simon Glass April 28, 2015, 3:20 a.m. UTC | #1
Hi Hans,

On 26 April 2015 at 03:51, Hans de Goede <hdegoede@redhat.com> wrote:
> Add driver-model support to the axp_gpio code, note that this needs a small
> tweak to the driver-model version of sunxi_name_to_gpio to deal with the
> vbus detect and enable pins which are not standard numbered gpios.
>
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  arch/arm/include/asm/arch-sunxi/gpio.h |  6 ++++--
>  drivers/gpio/axp_gpio.c                | 39 ++++++++++++++++++++++++++++++++++
>  drivers/gpio/sunxi_gpio.c              | 14 +++++++++++-
>  3 files changed, 56 insertions(+), 3 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

> diff --git a/arch/arm/include/asm/arch-sunxi/gpio.h b/arch/arm/include/asm/arch-sunxi/gpio.h
> index 902e95b..2d66077 100644
> --- a/arch/arm/include/asm/arch-sunxi/gpio.h
> +++ b/arch/arm/include/asm/arch-sunxi/gpio.h
> @@ -204,8 +204,10 @@ enum sunxi_gpio_number {
>  #define SUNXI_GPIO_PULL_DOWN   2
>
>  /* Virtual AXP0 GPIOs */
> -#define SUNXI_GPIO_AXP0_VBUS_DETECT    8
> -#define SUNXI_GPIO_AXP0_VBUS_ENABLE    9
> +#define SUNXI_GPIO_AXP0_PREFIX "AXP0-"
> +#define SUNXI_GPIO_AXP0_VBUS_DETECT    4
> +#define SUNXI_GPIO_AXP0_VBUS_ENABLE    5
> +#define SUNXI_GPIO_AXP0_GPIO_COUNT     6
>
>  void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val);
>  void sunxi_gpio_set_cfgpin(u32 pin, u32 val);
> diff --git a/drivers/gpio/axp_gpio.c b/drivers/gpio/axp_gpio.c
> index d04ec22..17358e6 100644
> --- a/drivers/gpio/axp_gpio.c
> +++ b/drivers/gpio/axp_gpio.c
> @@ -9,6 +9,10 @@
>  #include <common.h>
>  #include <asm/arch/gpio.h>
>  #include <asm/arch/pmic_bus.h>
> +#include <asm/gpio.h>
> +#include <dm.h>
> +#include <dm/device-internal.h>
> +#include <dm/root.h>
>  #include <errno.h>
>
>  #ifdef CONFIG_AXP152_POWER
> @@ -135,13 +139,48 @@ int axp_gpio_set_value(struct udevice *dev, unsigned pin, int val)
>         }
>  }
>
> +#ifdef CONFIG_DM_GPIO
> +static const struct dm_gpio_ops gpio_axp_ops = {
> +       .direction_input        = axp_gpio_direction_input,
> +       .direction_output       = axp_gpio_direction_output,
> +       .get_value              = axp_gpio_get_value,
> +       .set_value              = axp_gpio_set_value,
> +};
> +
> +static int gpio_axp_probe(struct udevice *dev)
> +{
> +       struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
> +
> +       /* Tell the uclass how many GPIOs we have */
> +       uc_priv->bank_name = strdup(SUNXI_GPIO_AXP0_PREFIX);
> +       uc_priv->gpio_count = SUNXI_GPIO_AXP0_GPIO_COUNT;
> +
> +       return 0;
> +}
> +

U_BOOT_DRIVER()

> +struct driver gpio_axp_driver = {
> +       .name   = "gpio_axp",
> +       .id     = UCLASS_GPIO,
> +       .ops    = &gpio_axp_ops,
> +       .probe  = gpio_axp_probe,
> +};
> +#endif
> +
>  int axp_gpio_init(void)
>  {
> +       __maybe_unused struct udevice *dev;
>         int ret;
>
>         ret = pmic_bus_init();
>         if (ret)
>                 return ret;
>
> +#ifdef CONFIG_DM_GPIO
> +       /* There is no devicetree support for the axp yet, so bind directly */
> +       ret = device_bind(dm_root(), &gpio_axp_driver, "AXP", NULL, -1, &dev);
> +       if (ret)
> +               return ret;
> +#endif
> +
>         return 0;
>  }
> diff --git a/drivers/gpio/sunxi_gpio.c b/drivers/gpio/sunxi_gpio.c
> index 5a0b5e4..21c3ff1 100644
> --- a/drivers/gpio/sunxi_gpio.c
> +++ b/drivers/gpio/sunxi_gpio.c
> @@ -172,7 +172,19 @@ int sunxi_name_to_gpio(const char *name)
>  {
>         unsigned int gpio;
>         int ret;
> -
> +#if !defined CONFIG_SPL_BUILD && defined CONFIG_AXP_GPIO
> +       char lookup[8];
> +
> +       if (strcasecmp(name, "AXP0-VBUS-DETECT") == 0) {
> +               sprintf(lookup, SUNXI_GPIO_AXP0_PREFIX "%d",
> +                       SUNXI_GPIO_AXP0_VBUS_DETECT);
> +               name = lookup;
> +       } else if (strcasecmp(name, "AXP0-VBUS-ENABLE") == 0) {
> +               sprintf(lookup, SUNXI_GPIO_AXP0_PREFIX "%d",
> +                       SUNXI_GPIO_AXP0_VBUS_ENABLE);
> +               name = lookup;
> +       }
> +#endif
>         ret = gpio_lookup_name(name, NULL, NULL, &gpio);
>
>         return ret ? ret : gpio;
> --
> 2.3.5
>

Regards,
Simon
Ian Campbell May 2, 2015, 1:56 p.m. UTC | #2
On Sun, 2015-04-26 at 11:51 +0200, Hans de Goede wrote:
> Add driver-model support to the axp_gpio code, note that this needs a small
> tweak to the driver-model version of sunxi_name_to_gpio to deal with the
> vbus detect and enable pins which are not standard numbered gpios.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Modulo Simon's one comment:

Acked-by: Ian Campbell <ijc@hellion.org.uk>
diff mbox

Patch

diff --git a/arch/arm/include/asm/arch-sunxi/gpio.h b/arch/arm/include/asm/arch-sunxi/gpio.h
index 902e95b..2d66077 100644
--- a/arch/arm/include/asm/arch-sunxi/gpio.h
+++ b/arch/arm/include/asm/arch-sunxi/gpio.h
@@ -204,8 +204,10 @@  enum sunxi_gpio_number {
 #define SUNXI_GPIO_PULL_DOWN	2
 
 /* Virtual AXP0 GPIOs */
-#define SUNXI_GPIO_AXP0_VBUS_DETECT	8
-#define SUNXI_GPIO_AXP0_VBUS_ENABLE	9
+#define SUNXI_GPIO_AXP0_PREFIX "AXP0-"
+#define SUNXI_GPIO_AXP0_VBUS_DETECT	4
+#define SUNXI_GPIO_AXP0_VBUS_ENABLE	5
+#define SUNXI_GPIO_AXP0_GPIO_COUNT	6
 
 void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val);
 void sunxi_gpio_set_cfgpin(u32 pin, u32 val);
diff --git a/drivers/gpio/axp_gpio.c b/drivers/gpio/axp_gpio.c
index d04ec22..17358e6 100644
--- a/drivers/gpio/axp_gpio.c
+++ b/drivers/gpio/axp_gpio.c
@@ -9,6 +9,10 @@ 
 #include <common.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/pmic_bus.h>
+#include <asm/gpio.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+#include <dm/root.h>
 #include <errno.h>
 
 #ifdef CONFIG_AXP152_POWER
@@ -135,13 +139,48 @@  int axp_gpio_set_value(struct udevice *dev, unsigned pin, int val)
 	}
 }
 
+#ifdef CONFIG_DM_GPIO
+static const struct dm_gpio_ops gpio_axp_ops = {
+	.direction_input	= axp_gpio_direction_input,
+	.direction_output	= axp_gpio_direction_output,
+	.get_value		= axp_gpio_get_value,
+	.set_value		= axp_gpio_set_value,
+};
+
+static int gpio_axp_probe(struct udevice *dev)
+{
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+
+	/* Tell the uclass how many GPIOs we have */
+	uc_priv->bank_name = strdup(SUNXI_GPIO_AXP0_PREFIX);
+	uc_priv->gpio_count = SUNXI_GPIO_AXP0_GPIO_COUNT;
+
+	return 0;
+}
+
+struct driver gpio_axp_driver = {
+	.name	= "gpio_axp",
+	.id	= UCLASS_GPIO,
+	.ops	= &gpio_axp_ops,
+	.probe	= gpio_axp_probe,
+};
+#endif
+
 int axp_gpio_init(void)
 {
+	__maybe_unused struct udevice *dev;
 	int ret;
 
 	ret = pmic_bus_init();
 	if (ret)
 		return ret;
 
+#ifdef CONFIG_DM_GPIO
+	/* There is no devicetree support for the axp yet, so bind directly */
+	ret = device_bind(dm_root(), &gpio_axp_driver, "AXP", NULL, -1, &dev);
+	if (ret)
+		return ret;
+#endif
+
 	return 0;
 }
diff --git a/drivers/gpio/sunxi_gpio.c b/drivers/gpio/sunxi_gpio.c
index 5a0b5e4..21c3ff1 100644
--- a/drivers/gpio/sunxi_gpio.c
+++ b/drivers/gpio/sunxi_gpio.c
@@ -172,7 +172,19 @@  int sunxi_name_to_gpio(const char *name)
 {
 	unsigned int gpio;
 	int ret;
-
+#if !defined CONFIG_SPL_BUILD && defined CONFIG_AXP_GPIO
+	char lookup[8];
+
+	if (strcasecmp(name, "AXP0-VBUS-DETECT") == 0) {
+		sprintf(lookup, SUNXI_GPIO_AXP0_PREFIX "%d",
+			SUNXI_GPIO_AXP0_VBUS_DETECT);
+		name = lookup;
+	} else if (strcasecmp(name, "AXP0-VBUS-ENABLE") == 0) {
+		sprintf(lookup, SUNXI_GPIO_AXP0_PREFIX "%d",
+			SUNXI_GPIO_AXP0_VBUS_ENABLE);
+		name = lookup;
+	}
+#endif
 	ret = gpio_lookup_name(name, NULL, NULL, &gpio);
 
 	return ret ? ret : gpio;