From: Yixun Lan <dlan@gentoo.org>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Conor Dooley <conor@kernel.org>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>
Cc: Yangyu Chen <cyy@cyyself.name>,
Jisheng Zhang <jszhang@kernel.org>,
Jesse Taube <mr.bossman075@gmail.com>,
Inochi Amaoto <inochiama@outlook.com>,
Icenowy Zheng <uwu@icenowy.me>,
Meng Zhang <zhangmeng.kevin@linux.spacemit.com>,
Emil Renner Berthing <kernel@esmil.dk>,
linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
spacemit@lists.linux.dev
Subject: Re: [PATCH v4 2/4] gpio: spacemit: add support for K1 SoC
Date: Fri, 7 Feb 2025 10:56:17 +0000 [thread overview]
Message-ID: <20250207105617-GYC5367@gentoo> (raw)
In-Reply-To: <20250121-03-k1-gpio-v4-2-4641c95c0194@gentoo.org>
On 11:38 Tue 21 Jan , Yixun Lan wrote:
> Implement GPIO functionality which capable of setting pin as
> input, output. Also, each pin can be used as interrupt which
> support rising, failing, or both edge type trigger.
>
> Signed-off-by: Yixun Lan <dlan@gentoo.org>
> ---
> drivers/gpio/Kconfig | 7 +
> drivers/gpio/Makefile | 1 +
> drivers/gpio/gpio-spacemit-k1.c | 295 ++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 303 insertions(+)
>
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index 56fee58e281e7cac7f287eb04e4c17a17f75ed04..c153f5439649da020ee42c38e88cb8df31a8e307 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -654,6 +654,13 @@ config GPIO_SNPS_CREG
> where only several fields in register belong to GPIO lines and
> each GPIO line owns a field with different length and on/off value.
>
> +config GPIO_SPACEMIT_K1
> + bool "SPACEMIT K1 GPIO support"
> + depends on ARCH_SPACEMIT || COMPILE_TEST
> + select GPIOLIB_IRQCHIP
> + help
> + Say yes here to support the SpacemiT's K1 GPIO device.
> +
> config GPIO_SPEAR_SPICS
> bool "ST SPEAr13xx SPI Chip Select as GPIO support"
> depends on PLAT_SPEAR
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index af3ba4d81b583842893ea69e677fbe2abf31bc7b..6709ce511a0cf10310a94521c85a2d382dcfa696 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -156,6 +156,7 @@ obj-$(CONFIG_GPIO_SIOX) += gpio-siox.o
> obj-$(CONFIG_GPIO_SL28CPLD) += gpio-sl28cpld.o
> obj-$(CONFIG_GPIO_SLOPPY_LOGIC_ANALYZER) += gpio-sloppy-logic-analyzer.o
> obj-$(CONFIG_GPIO_SODAVILLE) += gpio-sodaville.o
> +obj-$(CONFIG_GPIO_SPACEMIT_K1) += gpio-spacemit-k1.o
> obj-$(CONFIG_GPIO_SPEAR_SPICS) += gpio-spear-spics.o
> obj-$(CONFIG_GPIO_SPRD) += gpio-sprd.o
> obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o
> diff --git a/drivers/gpio/gpio-spacemit-k1.c b/drivers/gpio/gpio-spacemit-k1.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..de0491af494c10f528095efee9b3a140bdcc0b0d
> --- /dev/null
> +++ b/drivers/gpio/gpio-spacemit-k1.c
> @@ -0,0 +1,295 @@
> +// SPDX-License-Identifier: GPL-2.0 OR MIT
> +/*
> + * Copyright (C) 2023-2025 SpacemiT (Hangzhou) Technology Co. Ltd
> + * Copyright (c) 2025 Yixun Lan <dlan@gentoo.org>
> + */
> +
omit ..
> +static int spacemit_gpio_get_ports(struct device *dev, struct spacemit_gpio *gpio,
> + void __iomem *regs)
> +{
> + struct spacemit_gpio_port *port;
> + u32 i = 0, offset;
> +
> + gpio->nr_ports = device_get_child_node_count(dev);
> + if (gpio->nr_ports == 0)
> + return -ENODEV;
> +
> + gpio->ports = devm_kcalloc(dev, gpio->nr_ports, sizeof(*gpio->ports), GFP_KERNEL);
> + if (!gpio->ports)
> + return -ENOMEM;
> +
> + device_for_each_child_node_scoped(dev, fwnode) {
> + port = &gpio->ports[i];
> + port->fwnode = fwnode;
> + port->index = i++;
> +
> + if (fwnode_property_read_u32(fwnode, "reg", &offset))
> + return -EINVAL;
> +
> + port->base = regs + offset;
> + port->irq = fwnode_irq_get(fwnode, 0);
> + }
> +
> + return 0;
> +}
> +
> +static int spacemit_gpio_add_port(struct spacemit_gpio *gpio, int index)
> +{
> + struct spacemit_gpio_port *port;
> + struct device *dev = gpio->dev;
> + struct gpio_irq_chip *girq;
> + void __iomem *dat, *set, *clr, *dirin, *dirout;
> + int ret;
> +
> + port = &gpio->ports[index];
> + port->gpio = gpio;
> +
> + dat = port->base + GPLR;
> + set = port->base + GPSR;
> + clr = port->base + GPCR;
> + dirin = port->base + GCDR;
> + dirout = port->base + GSDR;
> +
> + /* This registers 32 GPIO lines per port */
> + ret = bgpio_init(&port->gc, dev, 4, dat, set, clr, dirout, dirin,
> + BGPIOF_UNREADABLE_REG_SET | BGPIOF_UNREADABLE_REG_DIR);
Esmil point out bgpio_init() require a GPIO_GENERIC dependency, will fix it
--
Yixun Lan (dlan)
Gentoo Linux Developer
GPG Key ID AABEFD55
WARNING: multiple messages have this Message-ID (diff)
From: Yixun Lan <dlan@gentoo.org>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Conor Dooley <conor@kernel.org>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>
Cc: devicetree@vger.kernel.org,
Meng Zhang <zhangmeng.kevin@linux.spacemit.com>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Jesse Taube <mr.bossman075@gmail.com>,
Yangyu Chen <cyy@cyyself.name>,
Inochi Amaoto <inochiama@outlook.com>,
Jisheng Zhang <jszhang@kernel.org>,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev,
Emil Renner Berthing <kernel@esmil.dk>
Subject: Re: [PATCH v4 2/4] gpio: spacemit: add support for K1 SoC
Date: Fri, 7 Feb 2025 10:56:17 +0000 [thread overview]
Message-ID: <20250207105617-GYC5367@gentoo> (raw)
In-Reply-To: <20250121-03-k1-gpio-v4-2-4641c95c0194@gentoo.org>
On 11:38 Tue 21 Jan , Yixun Lan wrote:
> Implement GPIO functionality which capable of setting pin as
> input, output. Also, each pin can be used as interrupt which
> support rising, failing, or both edge type trigger.
>
> Signed-off-by: Yixun Lan <dlan@gentoo.org>
> ---
> drivers/gpio/Kconfig | 7 +
> drivers/gpio/Makefile | 1 +
> drivers/gpio/gpio-spacemit-k1.c | 295 ++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 303 insertions(+)
>
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index 56fee58e281e7cac7f287eb04e4c17a17f75ed04..c153f5439649da020ee42c38e88cb8df31a8e307 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -654,6 +654,13 @@ config GPIO_SNPS_CREG
> where only several fields in register belong to GPIO lines and
> each GPIO line owns a field with different length and on/off value.
>
> +config GPIO_SPACEMIT_K1
> + bool "SPACEMIT K1 GPIO support"
> + depends on ARCH_SPACEMIT || COMPILE_TEST
> + select GPIOLIB_IRQCHIP
> + help
> + Say yes here to support the SpacemiT's K1 GPIO device.
> +
> config GPIO_SPEAR_SPICS
> bool "ST SPEAr13xx SPI Chip Select as GPIO support"
> depends on PLAT_SPEAR
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index af3ba4d81b583842893ea69e677fbe2abf31bc7b..6709ce511a0cf10310a94521c85a2d382dcfa696 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -156,6 +156,7 @@ obj-$(CONFIG_GPIO_SIOX) += gpio-siox.o
> obj-$(CONFIG_GPIO_SL28CPLD) += gpio-sl28cpld.o
> obj-$(CONFIG_GPIO_SLOPPY_LOGIC_ANALYZER) += gpio-sloppy-logic-analyzer.o
> obj-$(CONFIG_GPIO_SODAVILLE) += gpio-sodaville.o
> +obj-$(CONFIG_GPIO_SPACEMIT_K1) += gpio-spacemit-k1.o
> obj-$(CONFIG_GPIO_SPEAR_SPICS) += gpio-spear-spics.o
> obj-$(CONFIG_GPIO_SPRD) += gpio-sprd.o
> obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o
> diff --git a/drivers/gpio/gpio-spacemit-k1.c b/drivers/gpio/gpio-spacemit-k1.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..de0491af494c10f528095efee9b3a140bdcc0b0d
> --- /dev/null
> +++ b/drivers/gpio/gpio-spacemit-k1.c
> @@ -0,0 +1,295 @@
> +// SPDX-License-Identifier: GPL-2.0 OR MIT
> +/*
> + * Copyright (C) 2023-2025 SpacemiT (Hangzhou) Technology Co. Ltd
> + * Copyright (c) 2025 Yixun Lan <dlan@gentoo.org>
> + */
> +
omit ..
> +static int spacemit_gpio_get_ports(struct device *dev, struct spacemit_gpio *gpio,
> + void __iomem *regs)
> +{
> + struct spacemit_gpio_port *port;
> + u32 i = 0, offset;
> +
> + gpio->nr_ports = device_get_child_node_count(dev);
> + if (gpio->nr_ports == 0)
> + return -ENODEV;
> +
> + gpio->ports = devm_kcalloc(dev, gpio->nr_ports, sizeof(*gpio->ports), GFP_KERNEL);
> + if (!gpio->ports)
> + return -ENOMEM;
> +
> + device_for_each_child_node_scoped(dev, fwnode) {
> + port = &gpio->ports[i];
> + port->fwnode = fwnode;
> + port->index = i++;
> +
> + if (fwnode_property_read_u32(fwnode, "reg", &offset))
> + return -EINVAL;
> +
> + port->base = regs + offset;
> + port->irq = fwnode_irq_get(fwnode, 0);
> + }
> +
> + return 0;
> +}
> +
> +static int spacemit_gpio_add_port(struct spacemit_gpio *gpio, int index)
> +{
> + struct spacemit_gpio_port *port;
> + struct device *dev = gpio->dev;
> + struct gpio_irq_chip *girq;
> + void __iomem *dat, *set, *clr, *dirin, *dirout;
> + int ret;
> +
> + port = &gpio->ports[index];
> + port->gpio = gpio;
> +
> + dat = port->base + GPLR;
> + set = port->base + GPSR;
> + clr = port->base + GPCR;
> + dirin = port->base + GCDR;
> + dirout = port->base + GSDR;
> +
> + /* This registers 32 GPIO lines per port */
> + ret = bgpio_init(&port->gc, dev, 4, dat, set, clr, dirout, dirin,
> + BGPIOF_UNREADABLE_REG_SET | BGPIOF_UNREADABLE_REG_DIR);
Esmil point out bgpio_init() require a GPIO_GENERIC dependency, will fix it
--
Yixun Lan (dlan)
Gentoo Linux Developer
GPG Key ID AABEFD55
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-02-07 10:56 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-21 3:38 [PATCH v4 0/4] riscv: spacemit: add gpio support for K1 SoC Yixun Lan
2025-01-21 3:38 ` Yixun Lan
2025-01-21 3:38 ` [PATCH v4 1/4] dt-bindings: gpio: spacemit: add " Yixun Lan
2025-01-21 3:38 ` Yixun Lan
2025-01-22 20:03 ` Olof Johansson
2025-01-22 20:03 ` Olof Johansson
2025-01-23 11:30 ` Yixun Lan
2025-01-23 11:30 ` Yixun Lan
2025-01-23 23:19 ` Olof Johansson
2025-01-23 23:19 ` Olof Johansson
2025-01-27 18:17 ` Rob Herring
2025-01-27 18:17 ` Rob Herring
2025-01-28 3:17 ` Yixun Lan
2025-01-28 3:17 ` Yixun Lan
2025-01-28 16:03 ` Linus Walleij
2025-01-28 16:03 ` Linus Walleij
2025-01-28 16:58 ` Rob Herring
2025-01-28 16:58 ` Rob Herring
2025-01-28 18:50 ` Samuel Holland
2025-01-28 18:50 ` Samuel Holland
2025-02-06 9:18 ` Linus Walleij
2025-02-06 9:18 ` Linus Walleij
2025-02-06 10:39 ` Yixun Lan
2025-02-06 10:39 ` Yixun Lan
2025-02-06 13:31 ` Yixun Lan
2025-02-06 13:31 ` Yixun Lan
2025-02-13 13:07 ` Linus Walleij
2025-02-13 13:07 ` Linus Walleij
2025-02-14 11:54 ` Yixun Lan
2025-02-14 11:54 ` Yixun Lan
2025-02-14 13:08 ` Yixun Lan
2025-02-14 13:08 ` Yixun Lan
2025-02-18 9:44 ` Linus Walleij
2025-02-18 9:44 ` Linus Walleij
2025-02-18 9:55 ` Yixun Lan
2025-02-18 9:55 ` Yixun Lan
2025-02-18 10:17 ` Linus Walleij
2025-02-18 10:17 ` Linus Walleij
2025-02-18 10:59 ` Yixun Lan
2025-02-18 10:59 ` Yixun Lan
2025-01-28 15:47 ` Linus Walleij
2025-01-28 15:47 ` Linus Walleij
2025-01-21 3:38 ` [PATCH v4 2/4] " Yixun Lan
2025-01-21 3:38 ` Yixun Lan
2025-02-07 10:56 ` Yixun Lan [this message]
2025-02-07 10:56 ` Yixun Lan
2025-02-15 21:11 ` Alex Elder
2025-02-15 21:11 ` Alex Elder
2025-02-16 12:56 ` Yixun Lan
2025-02-16 12:56 ` Yixun Lan
2025-01-21 3:38 ` [PATCH v4 3/4] riscv: dts: spacemit: add gpio " Yixun Lan
2025-01-21 3:38 ` Yixun Lan
2025-01-21 3:38 ` [PATCH v4 4/4] riscv: dts: spacemit: add gpio LED for system heartbeat Yixun Lan
2025-01-21 3:38 ` Yixun Lan
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=20250207105617-GYC5367@gentoo \
--to=dlan@gentoo.org \
--cc=brgl@bgdev.pl \
--cc=conor+dt@kernel.org \
--cc=conor@kernel.org \
--cc=cyy@cyyself.name \
--cc=devicetree@vger.kernel.org \
--cc=inochiama@outlook.com \
--cc=jszhang@kernel.org \
--cc=kernel@esmil.dk \
--cc=krzk+dt@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mr.bossman075@gmail.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robh@kernel.org \
--cc=spacemit@lists.linux.dev \
--cc=uwu@icenowy.me \
--cc=zhangmeng.kevin@linux.spacemit.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.