All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yao Zi <ziyao@disroot.org>
To: Uros Stajic <uros.stajic@htecgroup.com>,
	"u-boot@lists.denx.de" <u-boot@lists.denx.de>
Cc: Djordje Todorovic <Djordje.Todorovic@htecgroup.com>,
	Chao-ying Fu <cfu@mips.com>
Subject: Re: [PATCH v3 03/12] gpio: Add GPIO driver for Intel EG20T
Date: Fri, 1 Aug 2025 08:51:53 +0000	[thread overview]
Message-ID: <aIyAKbszXgeCfAjv@pie> (raw)
In-Reply-To: <20250729162035.209849-4-uros.stajic@htecgroup.com>

On Tue, Jul 29, 2025 at 04:22:43PM +0000, Uros Stajic wrote:
> From: Chao-ying Fu <cfu@mips.com>
> 
> Add a GPIO driver for the Intel EG20T Platform Controller Hub, which
> exposes a set of 12 GPIOs via PCI MMIO.
> 
> The driver implements basic GPIO operations (input/output direction,
> value read/write, and function query) using the U-Boot driver model
> infrastructure. It maps the required BAR1 region via `dm_pci_map_bar`
> and uses internal registers to control pin state and direction.
> 
> This driver is required for platforms using EG20T, such as P8700-based
> systems, to access GPIOs through the standard U-Boot DM GPIO framework.
> 
> Signed-off-by: Chao-ying Fu <cfu@mips.com>
> Signed-off-by: Uros Stajic <uros.stajic@htecgroup.com>
> ---
>  board/mips/boston-riscv/MAINTAINERS |   1 +
>  drivers/gpio/Kconfig                |   7 ++
>  drivers/gpio/Makefile               |   1 +
>  drivers/gpio/eg20t-gpio.c           | 138 ++++++++++++++++++++++++++++
>  4 files changed, 147 insertions(+)
>  create mode 100644 drivers/gpio/eg20t-gpio.c
> 
> diff --git a/board/mips/boston-riscv/MAINTAINERS b/board/mips/boston-riscv/MAINTAINERS
> index e350121395e..bc59a628c79 100644
> --- a/board/mips/boston-riscv/MAINTAINERS
> +++ b/board/mips/boston-riscv/MAINTAINERS
> @@ -7,3 +7,4 @@ F:  arch/riscv/cpu/p8700/
>  F:  arch/riscv/include/asm/arch-p8700/
>  F:  configs/boston-p8700_defconfig
>  F:  arch/riscv/dts/boston-p8700.dts
> +F:  drivers/gpio/eg20t-gpio.c
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index 58e464106a3..26040947a69 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -726,3 +726,10 @@ config MPFS_GPIO
>  		Enable to support the GPIO driver on Polarfire SoC
>  
>  endif
> +
> +config EG20T_GPIO
> +        bool "Intel EG20T GPIO driver"
> +        depends on DM_GPIO && DM_PCI
> +        help
> +          Enable this to support the GPIO controller found in the Intel EG20T
> +          Platform Controller Hub.
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index 83e10c79b91..e44122cb9aa 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -81,3 +81,4 @@ obj-$(CONFIG_FTGPIO010)		+= ftgpio010.o
>  obj-$(CONFIG_$(PHASE_)ADP5585_GPIO)	+= adp5585_gpio.o
>  obj-$(CONFIG_RZG2L_GPIO)	+= rzg2l-gpio.o
>  obj-$(CONFIG_MPFS_GPIO)	+= mpfs_gpio.o
> +obj-$(CONFIG_EG20T_GPIO)	+= eg20t-gpio.o
> diff --git a/drivers/gpio/eg20t-gpio.c b/drivers/gpio/eg20t-gpio.c
> new file mode 100644
> index 00000000000..d41ca4bfb17
> --- /dev/null
> +++ b/drivers/gpio/eg20t-gpio.c
> @@ -0,0 +1,138 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2016 Imagination Technologies
> + */
> +
> +#include <dm.h>
> +#include <errno.h>
> +#include <pci.h>
> +#include <asm/io.h>
> +#include <asm/gpio.h>
> +#include <log.h>
> +
> +enum {
> +	REG_IEN		= 0x00,
> +	REG_ISTATUS	= 0x04,
> +	REG_IDISP	= 0x08,
> +	REG_ICLR	= 0x0c,
> +	REG_IMASK	= 0x10,
> +	REG_IMASKCLR	= 0x14,
> +	REG_PO		= 0x18,
> +	REG_PI		= 0x1c,
> +	REG_PM		= 0x20,
> +};
> +
> +struct eg20t_gpio_priv {
> +	void *base;
> +};
> +
> +static int eg20t_gpio_get_value(struct udevice *dev, unsigned int offset)
> +{
> +	struct eg20t_gpio_priv *priv = dev_get_priv(dev);
> +	u32 pm, pval;
> +
> +	pm = readl(priv->base + REG_PM);
> +	if ((pm >> offset) & 0x1)
> +		pval = readl(priv->base + REG_PO);
> +	else
> +		pval = readl(priv->base + REG_PI);
> +
> +	return (pval >> offset) & 0x1;
> +}
> +
> +static int eg20t_gpio_set_value(struct udevice *dev, unsigned int offset,
> +				int value)
> +{
> +	struct eg20t_gpio_priv *priv = dev_get_priv(dev);
> +	u32 po;
> +
> +	po = readl(priv->base + REG_PO);
> +	if (value)
> +		po |= 1 << offset;
> +	else
> +		po &= ~(1 << offset);
> +	writel(po, priv->base + REG_PO);
> +	return 0;
> +}

This file contains inconsistent usage of empty lines between statements
and the final return among functions. I think it's better to keep the
style aligned.

Regards,
Yao Zi

> +
> +static int eg20t_gpio_direction_input(struct udevice *dev, unsigned int offset)
> +{
> +	struct eg20t_gpio_priv *priv = dev_get_priv(dev);
> +	u32 pm;
> +
> +	pm = readl(priv->base + REG_PM);
> +	pm &= ~(1 << offset);
> +	writel(pm, priv->base + REG_PM);
> +	return 0;
> +}
> +
> +static int eg20t_gpio_direction_output(struct udevice *dev, unsigned int offset,
> +				       int value)
> +{
> +	struct eg20t_gpio_priv *priv = dev_get_priv(dev);
> +	u32 pm;
> +
> +	pm = readl(priv->base + REG_PM);
> +	pm |= 1 << offset;
> +	writel(pm, priv->base + REG_PM);
> +
> +	return eg20t_gpio_set_value(dev, offset, value);
> +}
> +
> +static int eg20t_gpio_get_function(struct udevice *dev, unsigned int offset)
> +{
> +	struct eg20t_gpio_priv *priv = dev_get_priv(dev);
> +	u32 pm;
> +
> +	pm = readl(priv->base + REG_PM);
> +
> +	if ((pm >> offset) & 0x1)
> +		return GPIOF_OUTPUT;
> +
> +	return GPIOF_INPUT;
> +}
> +
> +static const struct dm_gpio_ops eg20t_gpio_ops = {
> +	.direction_input	= eg20t_gpio_direction_input,
> +	.direction_output	= eg20t_gpio_direction_output,
> +	.get_value		= eg20t_gpio_get_value,
> +	.set_value		= eg20t_gpio_set_value,
> +	.get_function		= eg20t_gpio_get_function,
> +};
> +
> +static int eg20t_gpio_probe(struct udevice *dev)
> +{
> +	struct eg20t_gpio_priv *priv = dev_get_priv(dev);
> +	struct gpio_dev_priv *uc_priv = dev->uclass_priv;
> +
> +	priv->base = dm_pci_map_bar(dev, PCI_BASE_ADDRESS_1, PCI_REGION_MEM);
> +	if (!priv->base) {
> +		debug("failed to map GPIO registers\n");
> +		return -EINVAL;
> +	}
> +
> +	uc_priv->gpio_count = 12;
> +	uc_priv->bank_name = "eg20t";
> +	return 0;
> +}
> +
> +static const struct udevice_id eg20t_gpio_ids[] = {
> +	{ .compatible = "intel,eg20t-gpio" },
> +	{ }
> +};
> +
> +U_BOOT_DRIVER(eg20t_gpio) = {
> +	.name	= "eg20t-gpio",
> +	.id	= UCLASS_GPIO,
> +	.of_match = eg20t_gpio_ids,
> +	.probe	= eg20t_gpio_probe,
> +	.priv_auto_alloc_size = sizeof(struct eg20t_gpio_priv),
> +	.ops	= &eg20t_gpio_ops,
> +};
> +
> +static struct pci_device_id eg20t_gpio_supported[] = {
> +	{ PCI_VENDOR_ID_INTEL, 0x8803 },
> +	{ },
> +};
> +
> +U_BOOT_PCI_DEVICE(eg20t_gpio, eg20t_gpio_supported);
> -- 
> 2.34.1

  reply	other threads:[~2025-08-01  8:52 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-29 16:21 [PATCH v3 00/12] riscv: Add support for P8700 platform on Boston board Uros Stajic
2025-07-29 16:22 ` [PATCH v3 01/12] riscv: Add initial support for P8700 SoC Uros Stajic
2025-07-29 16:22 ` [PATCH v3 02/12] board: boston-riscv: Add initial support for P8700 Boston board Uros Stajic
2025-07-29 16:22 ` [PATCH v3 03/12] gpio: Add GPIO driver for Intel EG20T Uros Stajic
2025-08-01  8:51   ` Yao Zi [this message]
2025-07-29 16:23 ` [PATCH v3 04/12] pci: xilinx: Avoid writing memory base/limit for root bridge Uros Stajic
2025-07-29 16:23 ` [PATCH v3 05/12] riscv: Add support for MIPS GIC syscon on RISC-V SoCs Uros Stajic
2025-07-29 16:23 ` [PATCH v3 06/12] net: pch_gbe: Add PHY reset and MAC address fallback for RISC-V Uros Stajic
2025-07-29 16:24 ` [PATCH v3 07/12] libfdt: Allow non-64b aligned memreserve entries Uros Stajic
2025-07-29 16:24 ` [PATCH v3 08/12] riscv: p8700: Add software emulation for AMO* instructions Uros Stajic
2025-08-01  7:54   ` Yao Zi
2025-08-19  7:47     ` Uros Stajic
2025-07-29 16:24 ` [PATCH v3 09/12] riscv: p8700: Add Coherence Manager (CM) and IOCU support Uros Stajic
2025-08-01  8:47   ` Yao Zi
2025-08-19  7:55     ` Uros Stajic
2025-07-29 16:24 ` [PATCH v3 10/12] riscv: boston: Add support for LED character display command Uros Stajic
2025-07-29 16:25 ` [PATCH v3 11/12] cmd: riscv: Add 'startharts' command to start multiple harts Uros Stajic
2025-07-29 16:25 ` [PATCH v3 12/12] timer: p8700: Add support for reading time from memory-mapped mtime Uros Stajic
2025-07-31  5:57   ` Yao Zi
2025-08-19  7:59     ` Uros Stajic

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=aIyAKbszXgeCfAjv@pie \
    --to=ziyao@disroot.org \
    --cc=Djordje.Todorovic@htecgroup.com \
    --cc=cfu@mips.com \
    --cc=u-boot@lists.denx.de \
    --cc=uros.stajic@htecgroup.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.