gpio: add helper GPIOD_FLAGS_OUTPUT
[oweals/u-boot.git] / drivers / gpio / gpio-rcar.c
index 8504dceb8493e142c5213e596599886359042216..9dc4cd6042271263f98c421e6b39268ec8573b4e 100644 (file)
@@ -1,15 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2017 Marek Vasut <marek.vasut@gmail.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <clk.h>
 #include <dm.h>
+#include <malloc.h>
+#include <dm/device_compat.h>
+#include <dm/pinctrl.h>
 #include <errno.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
+#include "../pinctrl/renesas/sh_pfc.h"
 
 #define GPIO_IOINTSEL  0x00    /* General IO/Interrupt Switching Register */
 #define GPIO_INOUTSEL  0x04    /* General Input/Output Switching Register */
@@ -29,7 +32,8 @@
 DECLARE_GLOBAL_DATA_PTR;
 
 struct rcar_gpio_priv {
-       void __iomem *regs;
+       void __iomem            *regs;
+       int                     pfc_offset;
 };
 
 static int rcar_gpio_get_value(struct udevice *dev, unsigned offset)
@@ -113,7 +117,20 @@ static int rcar_gpio_get_function(struct udevice *dev, unsigned offset)
                return GPIOF_INPUT;
 }
 
+static int rcar_gpio_request(struct udevice *dev, unsigned offset,
+                            const char *label)
+{
+       return pinctrl_gpio_request(dev, offset);
+}
+
+static int rcar_gpio_free(struct udevice *dev, unsigned offset)
+{
+       return pinctrl_gpio_free(dev, offset);
+}
+
 static const struct dm_gpio_ops rcar_gpio_ops = {
+       .request                = rcar_gpio_request,
+       .rfree                  = rcar_gpio_free,
        .direction_input        = rcar_gpio_direction_input,
        .direction_output       = rcar_gpio_direction_output,
        .get_value              = rcar_gpio_get_value,
@@ -135,6 +152,7 @@ static int rcar_gpio_probe(struct udevice *dev)
 
        ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, node, "gpio-ranges",
                                             NULL, 3, 0, &args);
+       priv->pfc_offset = ret == 0 ? args.args[1] : -1;
        uc_priv->gpio_count = ret == 0 ? args.args[2] : RCAR_MAX_GPIO_PER_BANK;
 
        ret = clk_get_by_index(dev, 0, &clk);
@@ -156,6 +174,12 @@ static int rcar_gpio_probe(struct udevice *dev)
 static const struct udevice_id rcar_gpio_ids[] = {
        { .compatible = "renesas,gpio-r8a7795" },
        { .compatible = "renesas,gpio-r8a7796" },
+       { .compatible = "renesas,gpio-r8a77965" },
+       { .compatible = "renesas,gpio-r8a77970" },
+       { .compatible = "renesas,gpio-r8a77990" },
+       { .compatible = "renesas,gpio-r8a77995" },
+       { .compatible = "renesas,rcar-gen2-gpio" },
+       { .compatible = "renesas,rcar-gen3-gpio" },
        { /* sentinel */ }
 };