Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1718992pxb; Wed, 2 Feb 2022 10:57:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzE2wRKTx3axrm4ahu/bJupm1YOxkLkn4pUm7fBumNTZ+QqrkRz/Yw31tL+ocfrbboJnBfQ X-Received: by 2002:a17:90a:6585:: with SMTP id k5mr9610190pjj.94.1643828228969; Wed, 02 Feb 2022 10:57:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643828228; cv=none; d=google.com; s=arc-20160816; b=rv3gkBkw1GjUSwSWgBdxMwIJk8cVdkAM0sqVRePtzbOvMx4c35Xjnt8C97K/8Lx6p3 fHX87JmCfltmON7EdMqJxSa8d6UADsCmAnMELQLVT6dGYJXgFz0RgSDjj4Hw/8V5Uv+Z oPDx71W4Ir46mltHopm96dwEKnFnLQMjCtsnb/BzQmmB2AngnUupnyCqpDOgHScpuc3I JZFlivDKJr4lgung9HLP8cC2/KjzQ6Bjak0M5u/Yi3EmbFqTPx3GK/T9Ct7mkRi/a9rR K73xoyrqDl/dGxh1MjnIAGiTXqa9zgDNK/y7fP1BGsuZGKf/r0uVK36r20gC6pACFUXE 0vDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Y/kYiRInfsvyElPIDI39Lqck87rYrQWofhDpEmZtPSY=; b=gutz/1bc9ha8vlqtGyhDRd1xPENcGWo5nh99xj3U+huygSjtFN1pCbicndTIQHNFEO PWSfcpmmPDEffNcPaRdH0WuQMZFBzheemJY3fsRrXhvtEZlFaWMwP6qpY4RtlVS5B+Qq Gup4ym6YXXHrLkzPQDJxRO1Ht1DGoUIImayRrR2Gaa8Kg/HfaGI7z/maqapEA/GAZ3vV iVZWhBcegejLKdZaUnRtAPccQweqtrR/UTKD8z0Z+DzIZ9LLrEs7V93+X5Am1SGaxTgR wBEQIiXe7VLvg2US9NF30Kc359AzaFHjVe8DwMT5oF0G0gHMEwOsLdNprNiCQpgKjwGZ Vgpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=n+zSRRWN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q207si19556771pfc.305.2022.02.02.10.56.56; Wed, 02 Feb 2022 10:57:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20210112.gappssmtp.com header.s=20210112 header.b=n+zSRRWN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245414AbiBBJR3 (ORCPT + 99 others); Wed, 2 Feb 2022 04:17:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245406AbiBBJR2 (ORCPT ); Wed, 2 Feb 2022 04:17:28 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5264C06173B for ; Wed, 2 Feb 2022 01:17:27 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id d10so63377209eje.10 for ; Wed, 02 Feb 2022 01:17:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Y/kYiRInfsvyElPIDI39Lqck87rYrQWofhDpEmZtPSY=; b=n+zSRRWNoLDbgRRKBeTh+H1uwEewljSjvlihvbIbFUw3/JNwm4kM38DZanK8Dpg7AI +dj2/gAKUckeWANIRVKUrPXyonam/wV5zyN7FV50rmYde2p97d+Yi3FrrB01iAYR+aXM Gum5F3bCNEE25rxs56m2NlmRQh6eW/jDg7HIV3U0Gu10+6C6J8hl7gbvJaKoexUHnUz3 c+NCfqJ7i2IsQR/J37EPCprXo5Kjx3pE4isRsLZ91uu9bP64VNLyKplBDsypDvjktOHL YApmDzYRqxp0PBbZpj6v1gulDj6jcdVtQnU/slBRlRN3cSzfXC9Pom0j0U2POdrEe2jR JP2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Y/kYiRInfsvyElPIDI39Lqck87rYrQWofhDpEmZtPSY=; b=lU1ekZiJKnvvLzU+zNUIbYQxGrD+7Vl5WbWMjpbNCBtEdKqo7U8ebWnWdxD3J4cnez Nj2GL2lxVz/+R3DzkfRRT6tEK6ibDqBuTbA3X89YqhqjW3v/oat1MzXzG85tV+qPCUm1 pscSpXZff9D+bl6Gh2ZG6AWtdKzQc65zAHlrFW8CbXoR3kGXxUi3kThSQFKyd34Vxi1x jjNqGUnN3WjzaahdtLqhbwfKqOSOzKkS0piDRwPrzyj95DPVwl7iGRIEhHlTIjowiEJ4 V9If3EBtQH4E5XQ9LxvH5qp6Ioy5joOKVurrPIsOHFw2H/xafaZS2sHhcQMxXaqlAMkm 24sQ== X-Gm-Message-State: AOAM5318CkhsRl6qBxZTpZjdw0itQDCAfqOwjK6FOp5Og/FA8ntMG5ss j2JzxD1LNxhTRChiJFhkwSwQ6PqAwmxHJtn0t/ADnQ== X-Received: by 2002:a17:906:eb8a:: with SMTP id mh10mr21471265ejb.492.1643793446481; Wed, 02 Feb 2022 01:17:26 -0800 (PST) MIME-Version: 1.0 References: <20220130145116.88406-1-nbd@nbd.name> <20220130145116.88406-13-nbd@nbd.name> In-Reply-To: <20220130145116.88406-13-nbd@nbd.name> From: Bartosz Golaszewski Date: Wed, 2 Feb 2022 10:17:15 +0100 Message-ID: Subject: Re: [PATCH v9 12/13] gpio: Add support for Airoha EN7523 GPIO controller To: Felix Fietkau Cc: Linus Walleij , soc@kernel.org, "moderated list:ARM/Mediatek SoC..." , Linux ARM , John Crispin , Andy Shevchenko , Linux Kernel Mailing List , "open list:GPIO SUBSYSTEM" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 30, 2022 at 3:54 PM Felix Fietkau wrote: > > From: John Crispin > > Airoha's GPIO controller on their ARM EN7523 SoCs consists of two banks of 32 > GPIOs. Each instance in DT is for a single bank. > > Acked-by: Bartosz Golaszewski > Reviewed-by: Linus Walleij > Reviewed-by: Andy Shevchenko > Signed-off-by: John Crispin > Signed-off-by: Felix Fietkau > --- > drivers/gpio/Kconfig | 10 +++ > drivers/gpio/Makefile | 1 + > drivers/gpio/gpio-en7523.c | 137 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 148 insertions(+) > create mode 100644 drivers/gpio/gpio-en7523.c > > diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig > index 60d9374c72c0..0e9aacbcb4bd 100644 > --- a/drivers/gpio/Kconfig > +++ b/drivers/gpio/Kconfig > @@ -247,6 +247,16 @@ config GPIO_EM > help > Say yes here to support GPIO on Renesas Emma Mobile SoCs. > > +config GPIO_EN7523 > + tristate "Airoha GPIO support" > + depends on ARCH_AIROHA > + default ARCH_AIROHA > + select GPIO_GENERIC > + select GPIOLIB_IRQCHIP > + help > + Say Y or M here to support the GPIO controller block on the > + Airoha EN7523 SoC. It supports two banks of 32 GPIOs. > + > config GPIO_EP93XX > def_bool y > depends on ARCH_EP93XX > diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile > index 71ee9fc2ff83..d2269ee0948e 100644 > --- a/drivers/gpio/Makefile > +++ b/drivers/gpio/Makefile > @@ -56,6 +56,7 @@ obj-$(CONFIG_GPIO_DLN2) += gpio-dln2.o > obj-$(CONFIG_GPIO_DWAPB) += gpio-dwapb.o > obj-$(CONFIG_GPIO_EIC_SPRD) += gpio-eic-sprd.o > obj-$(CONFIG_GPIO_EM) += gpio-em.o > +obj-$(CONFIG_GPIO_EN7523) += gpio-en7523.o > obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o > obj-$(CONFIG_GPIO_EXAR) += gpio-exar.o > obj-$(CONFIG_GPIO_F7188X) += gpio-f7188x.o > diff --git a/drivers/gpio/gpio-en7523.c b/drivers/gpio/gpio-en7523.c > new file mode 100644 > index 000000000000..f836a8db4c1d > --- /dev/null > +++ b/drivers/gpio/gpio-en7523.c > @@ -0,0 +1,137 @@ > +// SPDX-License-Identifier: GPL-2.0-only > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define AIROHA_GPIO_MAX 32 > + > +/** > + * airoha_gpio_ctrl - Airoha GPIO driver data > + * @gc: Associated gpio_chip instance. > + * @data: The data register. > + * @dir0: The direction register for the lower 16 pins. > + * @dir1: The direction register for the higher 16 pins. > + * @output: The output enable register. > + */ > +struct airoha_gpio_ctrl { > + struct gpio_chip gc; > + void __iomem *data; > + void __iomem *dir[2]; > + void __iomem *output; > +}; > + > +static struct airoha_gpio_ctrl *gc_to_ctrl(struct gpio_chip *gc) > +{ > + return container_of(gc, struct airoha_gpio_ctrl, gc); > +} > + > +static int airoha_dir_set(struct gpio_chip *gc, unsigned int gpio, > + int val, int out) > +{ > + struct airoha_gpio_ctrl *ctrl = gc_to_ctrl(gc); > + u32 dir = ioread32(ctrl->dir[gpio / 16]); > + u32 output = ioread32(ctrl->output); > + u32 mask = BIT((gpio % 16) * 2); > + > + if (out) { > + dir |= mask; > + output |= BIT(gpio); > + } else { > + dir &= ~mask; > + output &= ~BIT(gpio); > + } > + > + iowrite32(dir, ctrl->dir[gpio / 16]); > + > + if (out) > + gc->set(gc, gpio, val); > + > + iowrite32(output, ctrl->output); > + > + return 0; > +} > + > +static int airoha_dir_out(struct gpio_chip *gc, unsigned int gpio, > + int val) > +{ > + return airoha_dir_set(gc, gpio, val, 1); > +} > + > +static int airoha_dir_in(struct gpio_chip *gc, unsigned int gpio) > +{ > + return airoha_dir_set(gc, gpio, 0, 0); > +} > + > +static int airoha_get_dir(struct gpio_chip *gc, unsigned int gpio) > +{ > + struct airoha_gpio_ctrl *ctrl = gc_to_ctrl(gc); > + u32 dir = ioread32(ctrl->dir[gpio / 16]); > + u32 mask = BIT((gpio % 16) * 2); > + > + return (dir & mask) ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN; > +} > + > +static int airoha_gpio_probe(struct platform_device *pdev) > +{ > + struct device *dev = &pdev->dev; > + struct airoha_gpio_ctrl *ctrl; > + int err; > + > + ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); > + if (!ctrl) > + return -ENOMEM; > + > + ctrl->data = devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(ctrl->data)) > + return PTR_ERR(ctrl->data); > + > + ctrl->dir[0] = devm_platform_ioremap_resource(pdev, 1); > + if (IS_ERR(ctrl->dir[0])) > + return PTR_ERR(ctrl->dir[0]); > + > + ctrl->dir[1] = devm_platform_ioremap_resource(pdev, 2); > + if (IS_ERR(ctrl->dir[1])) > + return PTR_ERR(ctrl->dir[1]); > + > + ctrl->output = devm_platform_ioremap_resource(pdev, 3); > + if (IS_ERR(ctrl->output)) > + return PTR_ERR(ctrl->output); > + > + err = bgpio_init(&ctrl->gc, dev, 4, ctrl->data, NULL, > + NULL, NULL, NULL, 0); > + if (err) > + return dev_err_probe(dev, err, "unable to init generic GPIO"); > + > + ctrl->gc.ngpio = AIROHA_GPIO_MAX; > + ctrl->gc.owner = THIS_MODULE; > + ctrl->gc.direction_output = airoha_dir_out; > + ctrl->gc.direction_input = airoha_dir_in; > + ctrl->gc.get_direction = airoha_get_dir; > + > + return devm_gpiochip_add_data(dev, &ctrl->gc, ctrl); > +} > + > +static const struct of_device_id airoha_gpio_of_match[] = { > + { .compatible = "airoha,en7523-gpio" }, > + { } > +}; > +MODULE_DEVICE_TABLE(of, airoha_gpio_of_match); > + > +static struct platform_driver airoha_gpio_driver = { > + .driver = { > + .name = "airoha-gpio", > + .of_match_table = airoha_gpio_of_match, > + }, > + .probe = airoha_gpio_probe, > +}; > +module_platform_driver(airoha_gpio_driver); > + > +MODULE_DESCRIPTION("Airoha GPIO support"); > +MODULE_AUTHOR("John Crispin "); > +MODULE_LICENSE("GPL v2"); > -- > 2.32.0 (Apple Git-132) > Queued for next, thanks! Bart