]> git.sur5r.net Git - u-boot/blobdiff - drivers/gpio/axp_gpio.c
SPDX: Convert all of our single license tags to Linux Kernel style
[u-boot] / drivers / gpio / axp_gpio.c
index d04ec221ac0d672d9e0f7538850a995ce957482d..73058cf40b4b9a8f55d92b19d7627baf76cce526 100644 (file)
@@ -1,25 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
  *
  * X-Powers AXP Power Management ICs gpio driver
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/pmic_bus.h>
+#include <asm/gpio.h>
+#include <axp_pmic.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+#include <dm/lists.h>
+#include <dm/root.h>
 #include <errno.h>
 
-#ifdef CONFIG_AXP152_POWER
-#include <axp152.h>
-#elif defined CONFIG_AXP209_POWER
-#include <axp209.h>
-#elif defined CONFIG_AXP221_POWER
-#include <axp221.h>
-#else
-#error Unknown AXP model
-#endif
+static int axp_gpio_set_value(struct udevice *dev, unsigned pin, int val);
 
 static u8 axp_get_gpio_ctrl_reg(unsigned pin)
 {
@@ -36,7 +33,7 @@ static u8 axp_get_gpio_ctrl_reg(unsigned pin)
        return 0;
 }
 
-int axp_gpio_direction_input(struct udevice *dev, unsigned pin)
+static int axp_gpio_direction_input(struct udevice *dev, unsigned pin)
 {
        u8 reg;
 
@@ -54,16 +51,18 @@ int axp_gpio_direction_input(struct udevice *dev, unsigned pin)
        }
 }
 
-int axp_gpio_direction_output(struct udevice *dev, unsigned pin, int val)
+static int axp_gpio_direction_output(struct udevice *dev, unsigned pin,
+                                    int val)
 {
        __maybe_unused int ret;
        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;
 
@@ -79,7 +78,7 @@ int axp_gpio_direction_output(struct udevice *dev, unsigned pin, int val)
        }
 }
 
-int axp_gpio_get_value(struct udevice *dev, unsigned pin)
+static int axp_gpio_get_value(struct udevice *dev, unsigned pin)
 {
        u8 reg, val, mask;
        int ret;
@@ -91,10 +90,11 @@ 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:
@@ -111,19 +111,20 @@ int axp_gpio_get_value(struct udevice *dev, unsigned pin)
        return (val & mask) ? 1 : 0;
 }
 
-int axp_gpio_set_value(struct udevice *dev, unsigned pin, int val)
+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);
@@ -135,13 +136,44 @@ int axp_gpio_set_value(struct udevice *dev, unsigned pin, int val)
        }
 }
 
+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(gpio_axp) = {
+       .name   = "gpio_axp",
+       .id     = UCLASS_GPIO,
+       .ops    = &gpio_axp_ops,
+       .probe  = gpio_axp_probe,
+};
+
 int axp_gpio_init(void)
 {
+       struct udevice *dev;
        int ret;
 
        ret = pmic_bus_init();
        if (ret)
                return ret;
 
+       /* There is no devicetree support for the axp yet, so bind directly */
+       ret = device_bind_driver(dm_root(), "gpio_axp", "AXP-gpio", &dev);
+       if (ret)
+               return ret;
+
        return 0;
 }