]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
zynqmp: gpio: Add support for zynqmp gpio modepin driver
authorT Karthik Reddy <t.karthik.reddy@xilinx.com>
Thu, 21 Oct 2021 09:04:06 +0000 (03:04 -0600)
committerMichal Simek <michal.simek@xilinx.com>
Thu, 18 Nov 2021 07:30:15 +0000 (08:30 +0100)
ZynqMP modepin driver has capability to get/set/check status of modepin
gpios. These modepins are accessed using xilinx firmware. In modepin
register, [3:0] bits set direction, [7:4] bits read IO, [11:8] bits
set/clear IO.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
MAINTAINERS
arch/arm/Kconfig
drivers/gpio/Kconfig
drivers/gpio/Makefile
drivers/gpio/zynqmp_gpio_modepin.c [new file with mode: 0644]

index c43610489917c591e4aafd719a3a02ec05e49a5e..2f832b2c9ea0f0ff3965225ad434903a4bdf31c6 100644 (file)
@@ -536,6 +536,7 @@ F:  drivers/net/xilinx_axi_mrmac.*
 F:     drivers/soc/soc_xilinx_versal.c
 F:     drivers/spi/cadence_ospi_versal.c
 F:     drivers/watchdog/xilinx_wwdt.c
+F:     drivers/gpio/zynqmp_gpio_modepin.c
 N:     (?<!uni)versal
 
 ARM VERSATILE EXPRESS DRIVERS
index 4306203a4ac39b4a8c96899ba09ad66c4f6c38e0..64f1f024960561e31678b18bdf33f9dae99b8597 100644 (file)
@@ -1166,6 +1166,7 @@ config ARCH_ZYNQMP
        select SUPPORT_SPL
        select ZYNQMP_IPI
        select SOC_DEVICE
+       select ZYNQMP_GPIO_MODEPIN if DM_GPIO && USB
        imply BOARD_LATE_INIT
        imply CMD_DM
        imply ENV_VARS_UBOOT_RUNTIME_CONFIG
index 202fcc6f4759ec54c8d6ef9a7c102097b98aa33e..164cdf315d988d189ab9b7d7526301362fdbb610 100644 (file)
@@ -302,6 +302,15 @@ config XILINX_GPIO
        help
          This config enable the Xilinx GPIO driver for Microblaze.
 
+config ZYNQMP_GPIO_MODEPIN
+       bool "ZynqMP gpio modepin"
+       depends on DM_GPIO
+       help
+         This config enables the ZynqMP gpio modepin driver. ZynqMP modepin
+         driver will set and get the status of PS_MODE pins. These modepins
+         are accessed using xilinx firmware. In modepin register, [3:0] bits
+         set direction, [7:4] bits read IO, [11:8] bits set/clear IO.
+
 config CMD_TCA642X
        bool "tca642x - Command to access tca642x state"
        help
index d3d0d3cacf072cd120d92f2f494978420d567353..0c511195c1a89a458145db9d3fb3dad826d4f38d 100644 (file)
@@ -47,6 +47,7 @@ obj-$(CONFIG_OMAP_GPIO)       += omap_gpio.o
 obj-$(CONFIG_DB8500_GPIO)      += db8500_gpio.o
 obj-$(CONFIG_BCM2835_GPIO)     += bcm2835_gpio.o
 obj-$(CONFIG_XILINX_GPIO)      += xilinx_gpio.o
+obj-$(CONFIG_ZYNQMP_GPIO_MODEPIN)      += zynqmp_gpio_modepin.o
 obj-$(CONFIG_ADI_GPIO2)        += adi_gpio2.o
 obj-$(CONFIG_TCA642X)          += tca642x.o
 obj-$(CONFIG_SUNXI_GPIO)       += sunxi_gpio.o
diff --git a/drivers/gpio/zynqmp_gpio_modepin.c b/drivers/gpio/zynqmp_gpio_modepin.c
new file mode 100644 (file)
index 0000000..078fd83
--- /dev/null
@@ -0,0 +1,153 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ZynqMP GPIO modepin driver
+ *
+ * Copyright (C) 2021 Xilinx, Inc.
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <asm/io.h>
+#include <asm/gpio.h>
+#include <dm.h>
+#include <asm/arch/hardware.h>
+#include <zynqmp_firmware.h>
+
+#define OUTEN(pin)             (BIT(0) << (pin))
+#define INVAL(pin)             (BIT(4) << (pin))
+#define OUTVAL(pin)            (BIT(8) << (pin))
+
+#define ZYNQMP_CRL_APB_BOOTPIN_CTRL_MASK       0xF0F
+#define ZYNQMP_CRL_APB_BOOT_PIN_CTRL           (ZYNQMP_CRL_APB_BASEADDR + \
+                                               (0x250U))
+
+static int get_gpio_modepin(u32 *ret_payload)
+{
+       return xilinx_pm_request(PM_MMIO_READ, ZYNQMP_CRL_APB_BOOT_PIN_CTRL,
+                                0, 0, 0, ret_payload);
+}
+
+static int set_gpio_modepin(int val)
+{
+       return xilinx_pm_request(PM_MMIO_WRITE, ZYNQMP_CRL_APB_BOOT_PIN_CTRL,
+                                ZYNQMP_CRL_APB_BOOTPIN_CTRL_MASK,
+                                val, 0, NULL);
+}
+
+static int modepin_gpio_direction_input(struct udevice *dev,
+                                       unsigned int offset)
+{
+       return 0;
+}
+
+static int modepin_gpio_set_value(struct udevice *dev, unsigned int offset,
+                                 int value)
+{
+       u32 ret_payload[PAYLOAD_ARG_CNT];
+       u32 out_val = 0;
+       int ret;
+
+       ret = get_gpio_modepin(ret_payload);
+       if (value)
+               out_val = OUTVAL(offset) | ret_payload[1];
+       else
+               out_val = ~OUTVAL(offset) & ret_payload[1];
+
+       return set_gpio_modepin(out_val);
+}
+
+static int modepin_gpio_direction_output(struct udevice *dev,
+                                        unsigned int offset, int value)
+{
+       u32 ret_payload[PAYLOAD_ARG_CNT];
+       u32 out_en = 0;
+       int ret;
+
+       ret = get_gpio_modepin(ret_payload);
+       if (ret)
+               return ret;
+
+       if (value)
+               out_en = OUTEN(offset) | ret_payload[1];
+       else
+               out_en = ~OUTEN(offset) & ret_payload[1];
+
+       ret = set_gpio_modepin(out_en);
+       if (ret)
+               return ret;
+
+       return modepin_gpio_set_value(dev, offset, value);
+}
+
+static int modepin_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
+                             struct ofnode_phandle_args *args)
+{
+       desc->offset = args->args[0];
+
+       return 0;
+}
+
+static int modepin_gpio_get_value(struct udevice *dev, unsigned int offset)
+{
+       u32 ret_payload[PAYLOAD_ARG_CNT];
+       int ret;
+
+       ret = get_gpio_modepin(ret_payload);
+       if (ret)
+               return ret;
+
+       return (INVAL(offset) & ret_payload[1]) ? 1 : 0;
+}
+
+static int modepin_gpio_get_function(struct udevice *dev, unsigned int offset)
+{
+       u32 ret_payload[PAYLOAD_ARG_CNT];
+       int ret;
+
+       ret = get_gpio_modepin(ret_payload);
+       if (ret)
+               return ret;
+
+       return (OUTEN(offset) & ret_payload[1]) ? GPIOF_OUTPUT : GPIOF_INPUT;
+}
+
+static const struct dm_gpio_ops modepin_gpio_ops = {
+       .direction_input = modepin_gpio_direction_input,
+       .direction_output = modepin_gpio_direction_output,
+       .get_value = modepin_gpio_get_value,
+       .set_value = modepin_gpio_set_value,
+       .get_function = modepin_gpio_get_function,
+       .xlate = modepin_gpio_xlate,
+};
+
+static int modepin_gpio_probe(struct udevice *dev)
+{
+       struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+       const void *label_ptr;
+
+       label_ptr = dev_read_prop(dev, "label", NULL);
+       if (label_ptr) {
+               uc_priv->bank_name = strdup(label_ptr);
+               if (!uc_priv->bank_name)
+                       return -ENOMEM;
+       } else {
+               uc_priv->bank_name = dev->name;
+       }
+
+       uc_priv->gpio_count = 4;
+
+       return 0;
+}
+
+static const struct udevice_id modepin_gpio_ids[] = {
+       { .compatible = "xlnx,zynqmp-gpio-modepin",},
+       { }
+};
+
+U_BOOT_DRIVER(modepin_gpio) = {
+       .name = "modepin_gpio",
+       .id = UCLASS_GPIO,
+       .ops = &modepin_gpio_ops,
+       .of_match = modepin_gpio_ids,
+       .probe = modepin_gpio_probe,
+};