Merge branch '2021-10-19-assorted-changes'
[platform/kernel/u-boot.git] / drivers / gpio / tegra_gpio.c
index 5a03115..e00f104 100644 (file)
@@ -1,9 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * NVIDIA Tegra20 GPIO handling.
  *  (C) Copyright 2010-2012,2015
  *  NVIDIA Corporation <www.nvidia.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
@@ -13,6 +12,7 @@
 
 #include <common.h>
 #include <dm.h>
+#include <log.h>
 #include <malloc.h>
 #include <errno.h>
 #include <fdtdec.h>
 #include <dm/device-internal.h>
 #include <dt-bindings/gpio/gpio.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
-static const int CONFIG_SFIO = 0;
-static const int CONFIG_GPIO = 1;
+static const int CFG_SFIO = 0;
+static const int CFG_GPIO = 1;
 static const int DIRECTION_INPUT = 0;
 static const int DIRECTION_OUTPUT = 1;
 
-struct tegra_gpio_platdata {
+struct tegra_gpio_plat {
        struct gpio_ctlr_bank *bank;
        const char *port_name;  /* Name of port, e.g. "B" */
        int base_gpio;          /* Port number for this port (0, 1,.., n-1) */
@@ -56,7 +54,7 @@ static int get_config(unsigned gpio)
        debug("get_config: port = %d, bit = %d is %s\n",
                GPIO_FULLPORT(gpio), GPIO_BIT(gpio), type ? "GPIO" : "SFPIO");
 
-       return type ? CONFIG_GPIO : CONFIG_SFIO;
+       return type ? CFG_GPIO : CFG_SFIO;
 }
 
 /* Config pin 'gpio' as GPIO or SFIO, based on 'type' */
@@ -70,7 +68,7 @@ static void set_config(unsigned gpio, int type)
                GPIO_FULLPORT(gpio), GPIO_BIT(gpio), type ? "GPIO" : "SFPIO");
 
        u = readl(&bank->gpio_config[GPIO_PORT(gpio)]);
-       if (type != CONFIG_SFIO)
+       if (type != CFG_SFIO)
                u |= 1 << GPIO_BIT(gpio);
        else
                u &= ~(1 << GPIO_BIT(gpio));
@@ -218,7 +216,7 @@ void gpio_config_table(const struct tegra_gpio_config *config, int len)
                        set_direction(config[i].gpio, DIRECTION_OUTPUT);
                        break;
                }
-               set_config(config[i].gpio, CONFIG_GPIO);
+               set_config(config[i].gpio, CFG_GPIO);
        }
 }
 
@@ -236,7 +234,7 @@ static int tegra_gpio_get_function(struct udevice *dev, unsigned offset)
 }
 
 static int tegra_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
-                           struct fdtdec_phandle_args *args)
+                           struct ofnode_phandle_args *args)
 {
        int gpio, port, ret;
 
@@ -293,8 +291,8 @@ static const struct udevice_id tegra_gpio_ids[] = {
 static int gpio_tegra_probe(struct udevice *dev)
 {
        struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-       struct tegra_port_info *priv = dev->priv;
-       struct tegra_gpio_platdata *plat = dev->platdata;
+       struct tegra_port_info *priv = dev_get_priv(dev);
+       struct tegra_gpio_plat *plat = dev_get_plat(dev);
 
        /* Only child devices have ports */
        if (!plat)
@@ -315,7 +313,7 @@ static int gpio_tegra_probe(struct udevice *dev)
  */
 static int gpio_tegra_bind(struct udevice *parent)
 {
-       struct tegra_gpio_platdata *plat = parent->platdata;
+       struct tegra_gpio_plat *plat = dev_get_plat(parent);
        struct gpio_ctlr *ctlr;
        int bank_count;
        int bank;
@@ -337,17 +335,20 @@ static int gpio_tegra_bind(struct udevice *parent)
         * This driver does not make use of interrupts, other than to figure
         * out the number of GPIO banks
         */
-       if (!fdt_getprop(gd->fdt_blob, parent->of_offset, "interrupts", &len))
-               return -EINVAL;
+       len = dev_read_size(parent, "interrupts");
+       if (len < 0)
+               return len;
        bank_count = len / 3 / sizeof(u32);
-       ctlr = (struct gpio_ctlr *)dev_get_addr(parent);
+       ctlr = (struct gpio_ctlr *)dev_read_addr(parent);
+       if ((ulong)ctlr == FDT_ADDR_T_NONE)
+               return -EINVAL;
        }
 #endif
        for (bank = 0; bank < bank_count; bank++) {
                int port;
 
                for (port = 0; port < TEGRA_PORTS_PER_BANK; port++) {
-                       struct tegra_gpio_platdata *plat;
+                       struct tegra_gpio_plat *plat;
                        struct udevice *dev;
                        int base_port;
 
@@ -360,10 +361,10 @@ static int gpio_tegra_bind(struct udevice *parent)
                        plat->port_name = gpio_port_name(base_port);
 
                        ret = device_bind(parent, parent->driver,
-                                         plat->port_name, plat, -1, &dev);
+                                         plat->port_name, plat,
+                                         dev_ofnode(parent), &dev);
                        if (ret)
                                return ret;
-                       dev->of_offset = parent->of_offset;
                }
        }
 
@@ -376,7 +377,6 @@ U_BOOT_DRIVER(gpio_tegra) = {
        .of_match = tegra_gpio_ids,
        .bind   = gpio_tegra_bind,
        .probe = gpio_tegra_probe,
-       .priv_auto_alloc_size = sizeof(struct tegra_port_info),
+       .priv_auto      = sizeof(struct tegra_port_info),
        .ops    = &gpio_tegra_ops,
-       .flags  = DM_FLAG_PRE_RELOC,
 };