public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Suneel Garapati <suneelglinux@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH 19/29] drivers: gpio: add GPIO controller driver for OcteonTX
Date: Tue, 29 Oct 2019 14:08:11 -0700	[thread overview]
Message-ID: <20191029210821.1954-20-suneelglinux@gmail.com> (raw)
In-Reply-To: <20191029210821.1954-1-suneelglinux@gmail.com>

From: Suneel Garapati <sgarapati@marvell.com>

Adds support for GPIO controllers found on OcteonTX or
OcteonTX2 SoC platforms.

Signed-off-by: Aaron Williams <awilliams@marvell.com>
Signed-off-by: Suneel Garapati <sgarapati@marvell.com>
---
 drivers/gpio/Kconfig         |   7 ++
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/octeontx_gpio.c | 218 +++++++++++++++++++++++++++++++++++
 3 files changed, 226 insertions(+)
 create mode 100644 drivers/gpio/octeontx_gpio.c

diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index c1ad5d64a3..91265180d3 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -276,6 +276,13 @@ config PIC32_GPIO
 	help
 	  Say yes here to support Microchip PIC32 GPIOs.
 
+config OCTEONTX_GPIO
+	bool "OcteonTX GPIO driver"
+	depends on DM_GPIO && (ARCH_OCTEONTX || ARCH_OCTEONTX2)
+	default y
+	help
+	  Say yes here to support OcteonTX GPIOs.
+
 config STM32_GPIO
 	bool "ST STM32 GPIO driver"
 	depends on DM_GPIO && (STM32 || ARCH_STM32MP)
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index ccc49e2eb0..d7651bff4b 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_HIKEY_GPIO)	+= hi6220_gpio.o
 obj-$(CONFIG_HSDK_CREG_GPIO)	+= hsdk-creg-gpio.o
 obj-$(CONFIG_IMX_RGPIO2P)	+= imx_rgpio2p.o
 obj-$(CONFIG_PIC32_GPIO)	+= pic32_gpio.o
+obj-$(CONFIG_OCTEONTX_GPIO)	+= octeontx_gpio.o
 obj-$(CONFIG_MVEBU_GPIO)	+= mvebu_gpio.o
 obj-$(CONFIG_MSM_GPIO)		+= msm_gpio.o
 obj-$(CONFIG_$(SPL_)PCF8575_GPIO)	+= pcf8575_gpio.o
diff --git a/drivers/gpio/octeontx_gpio.c b/drivers/gpio/octeontx_gpio.c
new file mode 100644
index 0000000000..d012044c47
--- /dev/null
+++ b/drivers/gpio/octeontx_gpio.c
@@ -0,0 +1,218 @@
+// SPDX-License-Identifier:    GPL-2.0
+/*
+ * Copyright (C) 2018 Marvell International Ltd.
+ *
+ * https://spdx.org/licenses
+ *
+ * (C) Copyright 2011
+ * eInfochips Ltd. <www.einfochips.com>
+ * Written-by: Ajay Bhargav <ajay.bhargav@einfochips.com>
+ *
+ * (C) Copyright 2010
+ * Marvell Semiconductor <www.marvell.com>
+ *
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <malloc.h>
+#include <errno.h>
+#include <fdtdec.h>
+#include <asm/io.h>
+#include <asm/gpio.h>
+#include <asm/bitops.h>
+#include <dt-bindings/gpio/gpio.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/** Returns the bit value to write or read based on the offset */
+#define GPIO_BIT(x)		(1ULL << ((x) & 0x3f))
+
+#define GPIO_RX_DAT		(0x0)
+#define GPIO_TX_SET		(0x8)
+#define GPIO_TX_CLR		(0x10)
+#define GPIO_CONST		(0x90)
+#define GPIO_RX1_DAT		(0x1400)
+#define GPIO_TX1_SET		(0x1408)
+#define GPIO_TX1_CLR		(0x1410)
+
+/** Returns the offset to the output register based on the offset and value */
+#define GPIO_TX_REG(offset, value)					\
+	((offset) >= 64 ? ((value) ? GPIO_TX1_SET : GPIO_TX1_CLR) :	\
+			  ((value) ? GPIO_TX_SET : GPIO_TX_CLR))
+
+/** Returns the offset to the input data register based on the offset */
+#define GPIO_RX_DAT_REG(offset) (((offset) >= 64) ? GPIO_RX1_DAT : GPIO_RX_DAT)
+
+/** Returns the bit configuration register based on the offset */
+#define GPIO_BIT_CFG(x)		(0x400 + 8 * (x))
+#define GPIO_BIT_CFG_FN(x)	(((x) >> 16) & 0x3ff)
+#define GPIO_BIT_CFG_TX_OE(x)	((x) & 0x1)
+#define GPIO_BIT_CFG_RX_DAT(x)	((x) & 0x1)
+
+/** PCI ID on NCB bus */
+#define PCI_DEVICE_ID_OCTEONTX_GPIO	0xa00a
+
+union gpio_const {
+	u64 u;
+	struct {
+		u64 gpios:8;	/** Number of GPIOs implemented */
+		u64 pp:8;	/** Number of PP vectors */
+		u64:48;	/* Reserved */
+	} s;
+};
+
+struct octeontx_gpio {
+	void __iomem *baseaddr;
+};
+
+static int octeontx_gpio_dir_input(struct udevice *dev, unsigned int offset)
+{
+	struct octeontx_gpio *gpio = dev_get_priv(dev);
+
+	debug("%s(%s, %u)\n", __func__, dev->name, offset);
+	clrbits_le64(gpio->baseaddr + GPIO_BIT_CFG(offset),
+		     (0x3ffUL << 16) | 4UL | 2UL | 1UL);
+	return 0;
+}
+
+static int octeontx_gpio_dir_output(struct udevice *dev, unsigned int offset,
+				    int value)
+{
+	struct octeontx_gpio *gpio = dev_get_priv(dev);
+
+	debug("%s(%s, %u, %d)\n", __func__, dev->name, offset, value);
+	writeq(GPIO_BIT(offset), gpio->baseaddr + GPIO_TX_REG(offset, value));
+
+	clrsetbits_le64(gpio->baseaddr + GPIO_BIT_CFG(offset),
+			((0x3ffUL << 16) | 4UL), 1UL);
+	return 0;
+}
+
+static int octeontx_gpio_get_value(struct udevice *dev,
+				   unsigned int offset)
+{
+	struct octeontx_gpio *gpio = dev_get_priv(dev);
+	u64 reg = readq(gpio->baseaddr + GPIO_RX_DAT_REG(offset));
+
+	debug("%s(%s, %u): value: %d\n", __func__, dev->name, offset,
+	      !!(reg & GPIO_BIT(offset)));
+
+	return !!(reg & GPIO_BIT(offset));
+}
+
+static int octeontx_gpio_set_value(struct udevice *dev,
+				   unsigned int offset, int value)
+{
+	struct octeontx_gpio *gpio = dev_get_priv(dev);
+
+	debug("%s(%s, %u, %d)\n", __func__, dev->name, offset, value);
+	writeq(GPIO_BIT(offset), gpio->baseaddr + GPIO_TX_REG(offset, value));
+
+	return 0;
+}
+
+static int octeontx_gpio_get_function(struct udevice *dev,
+				      unsigned int offset)
+{
+	struct octeontx_gpio *gpio = dev_get_priv(dev);
+	u64 pinsel = readl(gpio->baseaddr + GPIO_BIT_CFG(offset));
+
+	debug("%s(%s, %u): pinsel: 0x%llx\n", __func__, dev->name, offset,
+	      pinsel);
+	if (GPIO_BIT_CFG_FN(pinsel))
+		return GPIOF_FUNC;
+	else if (GPIO_BIT_CFG_TX_OE(pinsel))
+		return GPIOF_OUTPUT;
+	else
+		return GPIOF_INPUT;
+}
+
+static int octeontx_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
+			       struct ofnode_phandle_args *args)
+{
+	if (args->args_count < 1)
+		return -EINVAL;
+
+	desc->offset = args->args[0];
+	desc->flags = 0;
+	if (args->args_count > 1) {
+		if (args->args[1] & GPIO_ACTIVE_LOW)
+			desc->flags |= GPIOD_ACTIVE_LOW;
+		/* In the future add tri-state flag support */
+	}
+	return 0;
+}
+
+static const struct dm_gpio_ops octeontx_gpio_ops = {
+	.direction_input	= octeontx_gpio_dir_input,
+	.direction_output	= octeontx_gpio_dir_output,
+	.get_value		= octeontx_gpio_get_value,
+	.set_value		= octeontx_gpio_set_value,
+	.get_function		= octeontx_gpio_get_function,
+	.xlate			= octeontx_gpio_xlate,
+};
+
+static int octeontx_gpio_probe(struct udevice *dev)
+{
+	pci_dev_t bdf = dm_pci_get_bdf(dev);
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct octeontx_gpio *priv = dev_get_priv(dev);
+	union gpio_const gpio_const;
+	char *end;
+	const char *status;
+
+	status = ofnode_read_string(dev->node, "status");
+
+	if (status && !strncmp(status, "ok", 2)) {
+		debug("%s(%s): GPIO device disabled in device tree\n",
+		      __func__, dev->name);
+		return -1;
+	}
+
+	dev->req_seq = PCI_FUNC(bdf);
+	priv->baseaddr = dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0,
+					PCI_REGION_MEM);
+
+	if (!priv->baseaddr) {
+		debug("%s(%s): Could not get base address\n",
+		      __func__, dev->name);
+		return -1;
+	}
+
+	gpio_const.u = readq(priv->baseaddr + GPIO_CONST);
+
+	debug("%s(%s): base address: %p, of_offset: %ld, pin count: %d\n",
+	      __func__, dev->name, priv->baseaddr, dev->node.of_offset,
+	      gpio_const.s.gpios);
+
+	uc_priv->gpio_count = gpio_const.s.gpios;
+	uc_priv->bank_name  = strdup(dev->name);
+	end = strchr(uc_priv->bank_name, '@');
+	end[0] = 'A' + dev->seq;
+	end[1] = '\0';
+
+	return 0;
+}
+
+static const struct udevice_id octeontx_gpio_ids[] = {
+	{ .compatible = "cavium,thunder-8890-gpio" },
+	{ }
+};
+
+U_BOOT_DRIVER(octeontx_gpio) = {
+	.name	= "octeontx_gpio",
+	.id	= UCLASS_GPIO,
+	.of_match = of_match_ptr(octeontx_gpio_ids),
+	.probe = octeontx_gpio_probe,
+	.priv_auto_alloc_size = sizeof(struct octeontx_gpio),
+	.ops	= &octeontx_gpio_ops,
+	.flags	= DM_FLAG_PRE_RELOC,
+};
+
+static struct pci_device_id octeontx_gpio_supported[] = {
+	{ PCI_VDEVICE(CAVIUM, PCI_DEVICE_ID_OCTEONTX_GPIO) },
+	{ },
+};
+
+U_BOOT_PCI_DEVICE(octeontx_gpio, octeontx_gpio_supported);
-- 
2.23.0

  parent reply	other threads:[~2019-10-29 21:08 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-29 21:07 [U-Boot] [RFC PATCH 00/29] arm: Introduce Marvell/Cavium OcteonTX Suneel Garapati
2019-10-29 21:07 ` [U-Boot] [RFC PATCH 01/29] include: pci_ids: add vendor ID for Cavium Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:07 ` [U-Boot] [RFC PATCH 02/29] include: pci: Increase max pci region limit Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:07 ` [U-Boot] [RFC PATCH 03/29] fdtdec: add API to read pci bus-range property Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:07 ` [U-Boot] [RFC PATCH 04/29] drivers: pci-uclass: fix incorrect argument in map_sysmem Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:07 ` [U-Boot] [RFC PATCH 05/29] drivers: pci-uclass: make DT subnode parse optional Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:07 ` [U-Boot] [RFC PATCH 06/29] drivers: pci-uclass: add multi entry support for pci regions Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:07 ` [U-Boot] [RFC PATCH 07/29] drivers: pci-uclass: add support for Enhanced Allocation in Bridges Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 08/29] drivers: pci-uclass: add support for Single-Root I/O Virtualizaiton Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 09/29] drivers: pci-uclass: add VF map_bar support for Enhanced Allocation Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 10/29] drivers: pci-uclass: Add support for Alternate-RoutingID capability Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 11/29] include: arm: asm: io: add 64bit clrbits and setbits helpers Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 12/29] drivers: rtc: ds1337: add driver model support Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 13/29] arch: include: octeontx: add headers for OcteonTX Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-11-20  5:47     ` [U-Boot] [EXT] " Aaron Williams
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 14/29] arch: include: octeontx2: add headers for OcteonTX2 Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 15/29] drivers: ata: ahci: update max id if it is more than available ports Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 16/29] drivers: ata: ahci: fill upper 32bit buffer address in sg descriptor Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 17/29] drivers: ata: ahci: add BAR index quirk for OcteonTX Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 18/29] drivers: pci: add PCI controller driver " Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` Suneel Garapati [this message]
2019-11-20  3:00   ` [U-Boot] [RFC PATCH 19/29] drivers: gpio: add GPIO " Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 20/29] drivers: i2c: add I2C " Suneel Garapati
2019-11-20  3:00   ` Simon Glass
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 21/29] drivers: spi: add SPI " Suneel Garapati
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 22/29] drivers: mmc: remove static qualifier on mmc_power_init Suneel Garapati
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 23/29] drivers: mmc: add MMC controller driver for OcteonTX Suneel Garapati
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 24/29] drivers: mtd: nand: add NAND " Suneel Garapati
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 25/29] drivers: net: add NIC " Suneel Garapati
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 26/29] drivers: net: add NIC controller driver for OcteonTX2 Suneel Garapati
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 27/29] drivers: watchdog: add reset support for OcteonTX Suneel Garapati
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 28/29] octeontx: Add support for OcteonTX SoC platforms Suneel Garapati
2019-10-29 21:08 ` [U-Boot] [RFC PATCH 29/29] octeontx2: Add support for OcteonTX2 " Suneel Garapati
2019-10-30 17:06 ` [U-Boot] [RFC PATCH 00/29] arm: Introduce Marvell/Cavium OcteonTX Tim Harvey
2019-10-31  0:04   ` [U-Boot] [EXT] " Aaron Williams
2019-10-31 19:12     ` Tim Harvey
2019-10-31 19:22       ` Chandrakala Chavva
2019-11-05  1:09       ` Aaron Williams
2019-11-05 16:07         ` Tim Harvey
2019-10-31 19:46   ` [U-Boot] " Suneel Garapati
2019-10-31 22:14     ` Tim Harvey
2019-10-31 22:40       ` Suneel Garapati
2019-11-01 16:07         ` Tim Harvey
2019-11-19 18:55 ` Tim Harvey
2019-11-20  3:00   ` Simon Glass
2019-11-20 20:41     ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191029210821.1954-20-suneelglinux@gmail.com \
    --to=suneelglinux@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox