]> git.sur5r.net Git - u-boot/blobdiff - drivers/gpio/omap_gpio.c
gpio: omap_gpio: Add DM_FLAG_PRE_RELOC flag
[u-boot] / drivers / gpio / omap_gpio.c
index 93d18e44a54eb1a5dc57604dc52c795be3b56e3a..559f29b8018ce832253b484e9d2330c1a183cd24 100644 (file)
@@ -23,9 +23,8 @@
 #include <fdtdec.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
-#include <asm/errno.h>
+#include <linux/errno.h>
 #include <malloc.h>
-#include <dt-bindings/gpio/gpio.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -277,22 +276,12 @@ static int omap_gpio_get_function(struct udevice *dev, unsigned offset)
                return GPIOF_INPUT;
 }
 
-static int omap_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
-                          struct fdtdec_phandle_args *args)
-{
-       desc->offset = args->args[0];
-       desc->flags = args->args[1] & GPIO_ACTIVE_LOW ? GPIOD_ACTIVE_LOW : 0;
-
-       return 0;
-}
-
 static const struct dm_gpio_ops gpio_omap_ops = {
        .direction_input        = omap_gpio_direction_input,
        .direction_output       = omap_gpio_direction_output,
        .get_value              = omap_gpio_get_value,
        .set_value              = omap_gpio_set_value,
        .get_function           = omap_gpio_get_function,
-       .xlate                  = omap_gpio_xlate,
 };
 
 static int omap_gpio_probe(struct udevice *dev)
@@ -310,28 +299,32 @@ static int omap_gpio_probe(struct udevice *dev)
 
 static int omap_gpio_bind(struct udevice *dev)
 {
-       struct omap_gpio_platdata *plat = dev->platdata;
+       struct omap_gpio_platdata *plat = dev_get_platdata(dev);
        fdt_addr_t base_addr;
 
        if (plat)
                return 0;
 
-       base_addr = dev_get_addr(dev);
+       base_addr = devfdt_get_addr(dev);
        if (base_addr == FDT_ADDR_T_NONE)
-               return -ENODEV;
+               return -EINVAL;
 
        /*
        * TODO:
        * When every board is converted to driver model and DT is
        * supported, this can be done by auto-alloc feature, but
        * not using calloc to alloc memory for platdata.
+       *
+       * For example am33xx_gpio uses platform data rather than device tree.
+       *
+       * NOTE: DO NOT COPY this code if you are using device tree.
        */
        plat = calloc(1, sizeof(*plat));
        if (!plat)
                return -ENOMEM;
 
        plat->base = base_addr;
-       plat->port_name = fdt_get_name(gd->fdt_blob, dev->of_offset, NULL);
+       plat->port_name = fdt_get_name(gd->fdt_blob, dev_of_offset(dev), NULL);
        dev->platdata = plat;
 
        return 0;
@@ -352,6 +345,7 @@ U_BOOT_DRIVER(gpio_omap) = {
        .bind   = omap_gpio_bind,
        .probe  = omap_gpio_probe,
        .priv_auto_alloc_size = sizeof(struct gpio_bank),
+       .flags = DM_FLAG_PRE_RELOC,
 };
 
 #endif /* CONFIG_DM_GPIO */