From nobody Sun May 19 06:04:51 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C432CCA47F for ; Thu, 7 Jul 2022 18:24:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236063AbiGGSYq (ORCPT ); Thu, 7 Jul 2022 14:24:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235207AbiGGSYn (ORCPT ); Thu, 7 Jul 2022 14:24:43 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76FF52F02E; Thu, 7 Jul 2022 11:24:42 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id a15so21014340pfv.13; Thu, 07 Jul 2022 11:24:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FSl71Hk0BnT10NJnLI+ezCAWxmiJgLAkOV3Buo9ULGk=; b=VzP8hyDh6QNCMC3TKLzAt458raLYFpDYGfyszwQftA212O0NHmyP4ioT00sB2b8S/C 6WV8doEI3U8UUrCW57uTUp7+JoTEhRdolIolfIzKUvZuqyyNXI5oY0vGkijfYqhXOzTK 9f8fccaGB15o2/fRoRWJxpj0SAkQV4vUvodnx9+9syhI2BIa1BgXvwdoTeRwyPIjGj/E liwKTly6yl0DFNZa2rszHTQxwcWnf2RRThNjQUuH1BPoF4lEYkn4rBXQRypDLZw78HSV 3oHLuweaBhoC+UmH0t+YZjTZQdaL+dyvK48NhI6gPtN6lVXEd0LhDjIQ1yA9yNVG+FLy 0Ujw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FSl71Hk0BnT10NJnLI+ezCAWxmiJgLAkOV3Buo9ULGk=; b=wCXujsIKIlhUi/P3d8NUpU5aJY5ru24B4GOzaVrrA5gvCO0Dr7VxKmSFOwO6QEV05T 3thfidDYDGlKGV1hRC+rBFFTKfiFghUJXC9q1yp4Wl64gooRjqeWeCRz5hZPaGAbKtwc neGI6B3HtK3B6RjacZK2C2tXKMIXTqiuz4i+BcBQiI1BiUwdF75yAlyD5PpYBnqIqdok CKhDQnfIqhsnWGHE8SLoQ8YsU8TzPAZjYe2SihXwpdIDS82+LCbJaO2p4bD/qctWXRui nR8DRW8FtTi5+it3D29BV/UXM578fihTfIWakIGVBNsBPondQ4rZl2XM7t5o13BsDVhS 59vg== X-Gm-Message-State: AJIora/MS0aX7lW1pw6mwDax15+Gqk3bpPT3Zyv31bh1/FhAjsx/h3yv oDexDu6I7flw6MKH3lTuynk= X-Google-Smtp-Source: AGRyM1tPzGVr0Gv2TzaayGf6N5V5wiN70w72ancH39Az0FN3B4wMyUwrCwa2Au+ek10FwXP1szP/9g== X-Received: by 2002:a63:f405:0:b0:40d:48c1:e32d with SMTP id g5-20020a63f405000000b0040d48c1e32dmr38803677pgi.25.1657218281959; Thu, 07 Jul 2022 11:24:41 -0700 (PDT) Received: from prasmi.domain.name ([103.219.60.85]) by smtp.gmail.com with ESMTPSA id o12-20020a170902d4cc00b0016a3f9e4865sm28589279plg.148.2022.07.07.11.24.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 11:24:41 -0700 (PDT) From: prabhakar.csengg@gmail.com X-Google-Original-From: prabhakar.mahadev-lad.rj@bp.renesas.com To: Marc Zyngier , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Geert Uytterhoeven , Linus Walleij , Bartosz Golaszewski , Philipp Zabel , devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Prabhakar , Biju Das , Daniel Palmer , Romain Perier , Thierry Reding , Jonathan Hunter , Robert Richter , Nobuhiro Iwamatsu , Andy Gross , Bjorn Andersson Subject: [PATCH v8 1/6] gpio: Remove dynamic allocation from populate_parent_alloc_arg() Date: Thu, 7 Jul 2022 19:23:09 +0100 Message-Id: <20220707182314.66610-2-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Marc Zyngier The gpiolib is unique in the way it uses intermediate fwspecs when feeding an interrupt specifier to the parent domain, as it relies on the populate_parent_alloc_arg() callback to perform a dynamic allocation. This is pretty inefficient (we free the structure almost immediately), and the only reason this isn't a stack allocation is that our ThunderX friend uses MSIs rather than a FW-constructed structure. Let's solve it by providing a new type composed of the union of a struct irq_fwspec and a msi_info_t, which satisfies both requirements. This allows us to use a stack allocation, and we can move the handful of users to this new scheme. Also perform some additional cleanup, such as getting rid of the stub versions of the irq_domain_translate_*cell helpers, which are never used when CONFIG_IRQ_DOMAIN_HIERARCHY isn't selected. Tested on a Tegra186. Reviewed-by: Linus Walleij Signed-off-by: Marc Zyngier Cc: Daniel Palmer Cc: Romain Perier Cc: Bartosz Golaszewski Cc: Thierry Reding Cc: Jonathan Hunter Cc: Robert Richter Cc: Nobuhiro Iwamatsu Cc: Andy Gross Cc: Bjorn Andersson Acked-by: Bartosz Golaszewski --- drivers/gpio/gpio-msc313.c | 15 ++++----- drivers/gpio/gpio-tegra.c | 15 ++++----- drivers/gpio/gpio-tegra186.c | 15 ++++----- drivers/gpio/gpio-thunderx.c | 15 ++++----- drivers/gpio/gpio-visconti.c | 15 ++++----- drivers/gpio/gpiolib.c | 42 ++++++++++-------------- drivers/pinctrl/qcom/pinctrl-spmi-gpio.c | 15 ++++----- include/linux/gpio/driver.h | 42 +++++++++++------------- 8 files changed, 73 insertions(+), 101 deletions(-) diff --git a/drivers/gpio/gpio-msc313.c b/drivers/gpio/gpio-msc313.c index b2c90bdd39d0..52d7b8d99170 100644 --- a/drivers/gpio/gpio-msc313.c +++ b/drivers/gpio/gpio-msc313.c @@ -550,15 +550,12 @@ static struct irq_chip msc313_gpio_irqchip =3D { * so we need to provide the fwspec. Essentially gpiochip_populate_parent_= fwspec_twocell * that puts GIC_SPI into the first cell. */ -static void *msc313_gpio_populate_parent_fwspec(struct gpio_chip *gc, - unsigned int parent_hwirq, - unsigned int parent_type) +static int msc313_gpio_populate_parent_fwspec(struct gpio_chip *gc, + union gpio_irq_fwspec *gfwspec, + unsigned int parent_hwirq, + unsigned int parent_type) { - struct irq_fwspec *fwspec; - - fwspec =3D kmalloc(sizeof(*fwspec), GFP_KERNEL); - if (!fwspec) - return NULL; + struct irq_fwspec *fwspec =3D &gfwspec->fwspec; =20 fwspec->fwnode =3D gc->irq.parent_domain->fwnode; fwspec->param_count =3D 3; @@ -566,7 +563,7 @@ static void *msc313_gpio_populate_parent_fwspec(struct = gpio_chip *gc, fwspec->param[1] =3D parent_hwirq; fwspec->param[2] =3D parent_type; =20 - return fwspec; + return 0; } =20 static int msc313e_gpio_child_to_parent_hwirq(struct gpio_chip *chip, diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c index ff2d2a1f9c73..e4fb4cb38a0f 100644 --- a/drivers/gpio/gpio-tegra.c +++ b/drivers/gpio/gpio-tegra.c @@ -443,15 +443,12 @@ static int tegra_gpio_child_to_parent_hwirq(struct gp= io_chip *chip, return 0; } =20 -static void *tegra_gpio_populate_parent_fwspec(struct gpio_chip *chip, - unsigned int parent_hwirq, - unsigned int parent_type) +static int tegra_gpio_populate_parent_fwspec(struct gpio_chip *chip, + union gpio_irq_fwspec *gfwspec, + unsigned int parent_hwirq, + unsigned int parent_type) { - struct irq_fwspec *fwspec; - - fwspec =3D kmalloc(sizeof(*fwspec), GFP_KERNEL); - if (!fwspec) - return NULL; + struct irq_fwspec *fwspec =3D &gfwspec->fwspec; =20 fwspec->fwnode =3D chip->irq.parent_domain->fwnode; fwspec->param_count =3D 3; @@ -459,7 +456,7 @@ static void *tegra_gpio_populate_parent_fwspec(struct g= pio_chip *chip, fwspec->param[1] =3D parent_hwirq; fwspec->param[2] =3D parent_type; =20 - return fwspec; + return 0; } =20 #ifdef CONFIG_PM_SLEEP diff --git a/drivers/gpio/gpio-tegra186.c b/drivers/gpio/gpio-tegra186.c index de28a68daea0..54d9fa7da9c1 100644 --- a/drivers/gpio/gpio-tegra186.c +++ b/drivers/gpio/gpio-tegra186.c @@ -621,16 +621,13 @@ static int tegra186_gpio_irq_domain_translate(struct = irq_domain *domain, return 0; } =20 -static void *tegra186_gpio_populate_parent_fwspec(struct gpio_chip *chip, - unsigned int parent_hwirq, - unsigned int parent_type) +static int tegra186_gpio_populate_parent_fwspec(struct gpio_chip *chip, + union gpio_irq_fwspec *gfwspec, + unsigned int parent_hwirq, + unsigned int parent_type) { struct tegra_gpio *gpio =3D gpiochip_get_data(chip); - struct irq_fwspec *fwspec; - - fwspec =3D kmalloc(sizeof(*fwspec), GFP_KERNEL); - if (!fwspec) - return NULL; + struct irq_fwspec *fwspec =3D &gfwspec->fwspec; =20 fwspec->fwnode =3D chip->irq.parent_domain->fwnode; fwspec->param_count =3D 3; @@ -638,7 +635,7 @@ static void *tegra186_gpio_populate_parent_fwspec(struc= t gpio_chip *chip, fwspec->param[1] =3D parent_hwirq; fwspec->param[2] =3D parent_type; =20 - return fwspec; + return 0; } =20 static int tegra186_gpio_child_to_parent_hwirq(struct gpio_chip *chip, diff --git a/drivers/gpio/gpio-thunderx.c b/drivers/gpio/gpio-thunderx.c index 9f66deab46ea..e1dedbca0c85 100644 --- a/drivers/gpio/gpio-thunderx.c +++ b/drivers/gpio/gpio-thunderx.c @@ -408,18 +408,15 @@ static int thunderx_gpio_child_to_parent_hwirq(struct= gpio_chip *gc, return 0; } =20 -static void *thunderx_gpio_populate_parent_alloc_info(struct gpio_chip *ch= ip, - unsigned int parent_hwirq, - unsigned int parent_type) +static int thunderx_gpio_populate_parent_alloc_info(struct gpio_chip *chip, + union gpio_irq_fwspec *gfwspec, + unsigned int parent_hwirq, + unsigned int parent_type) { - msi_alloc_info_t *info; - - info =3D kmalloc(sizeof(*info), GFP_KERNEL); - if (!info) - return NULL; + msi_alloc_info_t *info =3D &gfwspec->msiinfo; =20 info->hwirq =3D parent_hwirq; - return info; + return 0; } =20 static int thunderx_gpio_probe(struct pci_dev *pdev, diff --git a/drivers/gpio/gpio-visconti.c b/drivers/gpio/gpio-visconti.c index e6534ea1eaa7..5e108ba9956a 100644 --- a/drivers/gpio/gpio-visconti.c +++ b/drivers/gpio/gpio-visconti.c @@ -103,15 +103,12 @@ static int visconti_gpio_child_to_parent_hwirq(struct= gpio_chip *gc, return -EINVAL; } =20 -static void *visconti_gpio_populate_parent_fwspec(struct gpio_chip *chip, - unsigned int parent_hwirq, - unsigned int parent_type) +static int visconti_gpio_populate_parent_fwspec(struct gpio_chip *chip, + union gpio_irq_fwspec *gfwspec, + unsigned int parent_hwirq, + unsigned int parent_type) { - struct irq_fwspec *fwspec; - - fwspec =3D kmalloc(sizeof(*fwspec), GFP_KERNEL); - if (!fwspec) - return NULL; + struct irq_fwspec *fwspec =3D &gfwspec->fwspec; =20 fwspec->fwnode =3D chip->irq.parent_domain->fwnode; fwspec->param_count =3D 3; @@ -119,7 +116,7 @@ static void *visconti_gpio_populate_parent_fwspec(struc= t gpio_chip *chip, fwspec->param[1] =3D parent_hwirq; fwspec->param[2] =3D parent_type; =20 - return fwspec; + return 0; } =20 static int visconti_gpio_probe(struct platform_device *pdev) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9535f48e18d1..bfde94243752 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1107,7 +1107,7 @@ static int gpiochip_hierarchy_irq_domain_alloc(struct= irq_domain *d, irq_hw_number_t hwirq; unsigned int type =3D IRQ_TYPE_NONE; struct irq_fwspec *fwspec =3D data; - void *parent_arg; + union gpio_irq_fwspec gpio_parent_fwspec =3D {}; unsigned int parent_hwirq; unsigned int parent_type; struct gpio_irq_chip *girq =3D &gc->irq; @@ -1147,14 +1147,15 @@ static int gpiochip_hierarchy_irq_domain_alloc(stru= ct irq_domain *d, irq_set_probe(irq); =20 /* This parent only handles asserted level IRQs */ - parent_arg =3D girq->populate_parent_alloc_arg(gc, parent_hwirq, parent_t= ype); - if (!parent_arg) - return -ENOMEM; + ret =3D girq->populate_parent_alloc_arg(gc, &gpio_parent_fwspec, + parent_hwirq, parent_type); + if (ret) + return ret; =20 chip_dbg(gc, "alloc_irqs_parent for %d parent hwirq %d\n", irq, parent_hwirq); irq_set_lockdep_class(irq, gc->irq.lock_key, gc->irq.request_key); - ret =3D irq_domain_alloc_irqs_parent(d, irq, 1, parent_arg); + ret =3D irq_domain_alloc_irqs_parent(d, irq, 1, &gpio_parent_fwspec); /* * If the parent irqdomain is msi, the interrupts have already * been allocated, so the EEXIST is good. @@ -1166,7 +1167,6 @@ static int gpiochip_hierarchy_irq_domain_alloc(struct= irq_domain *d, "failed to allocate parent hwirq %d for hwirq %lu\n", parent_hwirq, hwirq); =20 - kfree(parent_arg); return ret; } =20 @@ -1230,34 +1230,28 @@ static bool gpiochip_hierarchy_is_hierarchical(stru= ct gpio_chip *gc) return !!gc->irq.parent_domain; } =20 -void *gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc, - unsigned int parent_hwirq, - unsigned int parent_type) +int gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc, + union gpio_irq_fwspec *gfwspec, + unsigned int parent_hwirq, + unsigned int parent_type) { - struct irq_fwspec *fwspec; - - fwspec =3D kmalloc(sizeof(*fwspec), GFP_KERNEL); - if (!fwspec) - return NULL; + struct irq_fwspec *fwspec =3D &gfwspec->fwspec; =20 fwspec->fwnode =3D gc->irq.parent_domain->fwnode; fwspec->param_count =3D 2; fwspec->param[0] =3D parent_hwirq; fwspec->param[1] =3D parent_type; =20 - return fwspec; + return 0; } EXPORT_SYMBOL_GPL(gpiochip_populate_parent_fwspec_twocell); =20 -void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc, - unsigned int parent_hwirq, - unsigned int parent_type) +int gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc, + union gpio_irq_fwspec *gfwspec, + unsigned int parent_hwirq, + unsigned int parent_type) { - struct irq_fwspec *fwspec; - - fwspec =3D kmalloc(sizeof(*fwspec), GFP_KERNEL); - if (!fwspec) - return NULL; + struct irq_fwspec *fwspec =3D &gfwspec->fwspec; =20 fwspec->fwnode =3D gc->irq.parent_domain->fwnode; fwspec->param_count =3D 4; @@ -1266,7 +1260,7 @@ void *gpiochip_populate_parent_fwspec_fourcell(struct= gpio_chip *gc, fwspec->param[2] =3D 0; fwspec->param[3] =3D parent_type; =20 - return fwspec; + return 0; } EXPORT_SYMBOL_GPL(gpiochip_populate_parent_fwspec_fourcell); =20 diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c b/drivers/pinctrl/qco= m/pinctrl-spmi-gpio.c index fd5fff9adff0..3be2a08ae3a6 100644 --- a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c +++ b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c @@ -966,16 +966,13 @@ static int pmic_gpio_child_to_parent_hwirq(struct gpi= o_chip *chip, return 0; } =20 -static void *pmic_gpio_populate_parent_fwspec(struct gpio_chip *chip, - unsigned int parent_hwirq, - unsigned int parent_type) +static int pmic_gpio_populate_parent_fwspec(struct gpio_chip *chip, + union gpio_irq_fwspec *gfwspec, + unsigned int parent_hwirq, + unsigned int parent_type) { struct pmic_gpio_state *state =3D gpiochip_get_data(chip); - struct irq_fwspec *fwspec; - - fwspec =3D kzalloc(sizeof(*fwspec), GFP_KERNEL); - if (!fwspec) - return NULL; + struct irq_fwspec *fwspec =3D &gfwspec->fwspec; =20 fwspec->fwnode =3D chip->irq.parent_domain->fwnode; =20 @@ -985,7 +982,7 @@ static void *pmic_gpio_populate_parent_fwspec(struct gp= io_chip *chip, /* param[2] must be left as 0 */ fwspec->param[3] =3D parent_type; =20 - return fwspec; + return 0; } =20 static int pmic_gpio_probe(struct platform_device *pdev) diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 54c3c6506503..6aeea1071b1b 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -12,6 +12,8 @@ #include #include =20 +#include + struct gpio_desc; struct of_phandle_args; struct device_node; @@ -23,6 +25,13 @@ enum gpio_lookup_flags; =20 struct gpio_chip; =20 +union gpio_irq_fwspec { + struct irq_fwspec fwspec; +#ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN + msi_alloc_info_t msiinfo; +#endif +}; + #define GPIO_LINE_DIRECTION_IN 1 #define GPIO_LINE_DIRECTION_OUT 0 =20 @@ -103,9 +112,10 @@ struct gpio_irq_chip { * variant named &gpiochip_populate_parent_fwspec_fourcell is also * available. */ - void *(*populate_parent_alloc_arg)(struct gpio_chip *gc, - unsigned int parent_hwirq, - unsigned int parent_type); + int (*populate_parent_alloc_arg)(struct gpio_chip *gc, + union gpio_irq_fwspec *fwspec, + unsigned int parent_hwirq, + unsigned int parent_type); =20 /** * @child_offset_to_irq: @@ -649,28 +659,14 @@ struct bgpio_pdata { =20 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY =20 -void *gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc, +int gpiochip_populate_parent_fwspec_twocell(struct gpio_chip *gc, + union gpio_irq_fwspec *gfwspec, + unsigned int parent_hwirq, + unsigned int parent_type); +int gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc, + union gpio_irq_fwspec *gfwspec, unsigned int parent_hwirq, unsigned int parent_type); -void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_chip *gc, - unsigned int parent_hwirq, - unsigned int parent_type); - -#else - -static inline void *gpiochip_populate_parent_fwspec_twocell(struct gpio_ch= ip *gc, - unsigned int parent_hwirq, - unsigned int parent_type) -{ - return NULL; -} - -static inline void *gpiochip_populate_parent_fwspec_fourcell(struct gpio_c= hip *gc, - unsigned int parent_hwirq, - unsigned int parent_type) -{ - return NULL; -} =20 #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */ =20 --=20 2.25.1 From nobody Sun May 19 06:04:51 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4ECC1CCA47F for ; Thu, 7 Jul 2022 18:24:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236091AbiGGSYy (ORCPT ); Thu, 7 Jul 2022 14:24:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236078AbiGGSYt (ORCPT ); Thu, 7 Jul 2022 14:24:49 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B8AA2F3BF; Thu, 7 Jul 2022 11:24:48 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id s27so19973656pga.13; Thu, 07 Jul 2022 11:24:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6q8+tslNjj42is2Wq3LrKo5qrCaBaAPRJbMXgMdfGjQ=; b=DhBVZphbgje4AIE9scnB/AiBcqQMjgFpJ4KQH4530InyLm0RL1ySwkb6VD5YzvCgJW aMa81fA7aAvpVKSXu7BdCEJurulD5fEjQ6UOyS4A7j1EBS1FHfaermNEBg94BxKa6WBI 7AjbgtWR3wQ25ZaG05LRuktC9lmQOsCJBs8jewhAjURF93yVaAGfmBagrspZWdMFTe+k 8jOPda3rtbpO+tGMwoxZ15L/8AbpRE1/5FQSDRQxFoe0VeFCoCkzSoh1uyA1TdwA0InB +WTOPUWAdKvDjJo5nh4M7A6S3kXXfwFokox9XaLwCL0OZXF7oKsqc040aYzu/xtfF5Ud Ve6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6q8+tslNjj42is2Wq3LrKo5qrCaBaAPRJbMXgMdfGjQ=; b=vzgUvf4kx/Q/rs8pUUtdFyXTHrRRbpxL/MODBGLbPikIr7No2NRRT+SP6pqnA8d0CT Isub4TlaqU1qo8lUDNkz+ZzwgiWXtICjsIUWdYifvuuyHphougP8Cd727p9S4T0Cwvs6 trieuNFHL3oR3i9vfs6PiFk0ZUQ1U22torS9e4ofnykjt+rhFmc/vtkuOalQ9EXAnvAa mLmNiKz2+yM8QG80bcAGSR4/krxM0dwt/HXHMwB818a5Kjr29eCz9w0M8Lcc/da6KTAH zcPPxc3iyXPS77IpLONXytePk0+NQCM4TLkoZUR/lBNhypbby93hMGe3IRagVKQc9aPP kAww== X-Gm-Message-State: AJIora/5m1qUgmqrvl4HQgT2cHQu1bcJZuph7Cik1/pDph+n5jH6uOif TB9kBEJUOlMlK8nafIJJsIg= X-Google-Smtp-Source: AGRyM1uzxWGGMoYwsGhJojNPdBl+m6Z+wxbtxQsV/MrMoA+8ndxIvifQCIF8K4oucXDUtbumwFneHA== X-Received: by 2002:a63:1724:0:b0:412:7bee:fdba with SMTP id x36-20020a631724000000b004127beefdbamr12075693pgl.340.1657218287679; Thu, 07 Jul 2022 11:24:47 -0700 (PDT) Received: from prasmi.domain.name ([103.219.60.85]) by smtp.gmail.com with ESMTPSA id o12-20020a170902d4cc00b0016a3f9e4865sm28589279plg.148.2022.07.07.11.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 11:24:47 -0700 (PDT) From: prabhakar.csengg@gmail.com X-Google-Original-From: prabhakar.mahadev-lad.rj@bp.renesas.com To: Marc Zyngier , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Geert Uytterhoeven , Linus Walleij , Bartosz Golaszewski , Philipp Zabel , devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar , Rob Herring Subject: [PATCH v8 2/6] dt-bindings: interrupt-controller: Add Renesas RZ/G2L Interrupt Controller Date: Thu, 7 Jul 2022 19:23:10 +0100 Message-Id: <20220707182314.66610-3-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar Add DT bindings for the Renesas RZ/G2L Interrupt Controller. Signed-off-by: Lad Prabhakar Reviewed-by: Rob Herring Reviewed-by: Geert Uytterhoeven --- .../renesas,rzg2l-irqc.yaml | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 Documentation/devicetree/bindings/interrupt-controller/= renesas,rzg2l-irqc.yaml diff --git a/Documentation/devicetree/bindings/interrupt-controller/renesas= ,rzg2l-irqc.yaml b/Documentation/devicetree/bindings/interrupt-controller/r= enesas,rzg2l-irqc.yaml new file mode 100644 index 000000000000..ffbb4ab4d9a7 --- /dev/null +++ b/Documentation/devicetree/bindings/interrupt-controller/renesas,rzg2l-= irqc.yaml @@ -0,0 +1,133 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/interrupt-controller/renesas,rzg2l-irqc= .yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Renesas RZ/G2L (and alike SoC's) Interrupt Controller (IA55) + +maintainers: + - Lad Prabhakar + - Geert Uytterhoeven + +description: | + IA55 performs various interrupt controls including synchronization for t= he external + interrupts of NMI, IRQ, and GPIOINT and the interrupts of the built-in p= eripheral + interrupts output by each IP. And it notifies the interrupt to the GIC + - IRQ sense select for 8 external interrupts, mapped to 8 GIC SPI inte= rrupts + - GPIO pins used as external interrupt input pins, mapped to 32 GIC SP= I interrupts + - NMI edge select (NMI is not treated as NMI exception and supports fa= ll edge and + stand-up edge detection interrupts) + +allOf: + - $ref: /schemas/interrupt-controller.yaml# + +properties: + compatible: + items: + - enum: + - renesas,r9a07g044-irqc # RZ/G2L + - const: renesas,rzg2l-irqc + + '#interrupt-cells': + description: The first cell should contain external interrupt number (= IRQ0-7) and the + second cell is used to specify the flag. + const: 2 + + '#address-cells': + const: 0 + + interrupt-controller: true + + reg: + maxItems: 1 + + interrupts: + maxItems: 41 + + clocks: + maxItems: 2 + + clock-names: + items: + - const: clk + - const: pclk + + power-domains: + maxItems: 1 + + resets: + maxItems: 1 + +required: + - compatible + - '#interrupt-cells' + - '#address-cells' + - interrupt-controller + - reg + - interrupts + - clocks + - clock-names + - power-domains + - resets + +unevaluatedProperties: false + +examples: + - | + #include + #include + + irqc: interrupt-controller@110a0000 { + compatible =3D "renesas,r9a07g044-irqc", "renesas,rzg2l-irqc"; + reg =3D <0x110a0000 0x10000>; + #interrupt-cells =3D <2>; + #address-cells =3D <0>; + interrupt-controller; + interrupts =3D , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + clocks =3D <&cpg CPG_MOD R9A07G044_IA55_CLK>, + <&cpg CPG_MOD R9A07G044_IA55_PCLK>; + clock-names =3D "clk", "pclk"; + power-domains =3D <&cpg>; + resets =3D <&cpg R9A07G044_IA55_RESETN>; + }; --=20 2.25.1 From nobody Sun May 19 06:04:51 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3836CCA479 for ; Thu, 7 Jul 2022 18:25:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236221AbiGGSY7 (ORCPT ); Thu, 7 Jul 2022 14:24:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236110AbiGGSYz (ORCPT ); Thu, 7 Jul 2022 14:24:55 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF2A02F02E; Thu, 7 Jul 2022 11:24:53 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id l124so10659542pfl.8; Thu, 07 Jul 2022 11:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j8zoTK2o91ZMCk6hcFjmZTEI+A9jS08y5YBmvRmHYto=; b=T/Za3bMHI27xv+B7Sdkr4NYsEv9kUUr6v8teLyF+9tWRTbk/EEwcSjLnMp8lVSXl1Y oePmDEv8yFk+rYrEBsjt74V+YQ2BJeMWiqO5WxFd7bOuDspf/OiPT44/5Whzur3e6WKV qzXmu6m+iRXGmmzM/Aj16NMA3EOe/qhdoV0l7+OAyKBjRqq/Qn+9buZUITDZ7le6WCIe K4MChJHq46k5TF0Nd6jINZQmSQ76aBX6EecjQgFwPHpL0q1/MHW989XehqeP0StE7+2F fN3/Ekpz15cmKLeTK/RUW1E3PAXq0c1oiw5y06WwB8AcDy3K2EqH8cL4aoBtm5Pyxk8x 0lUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j8zoTK2o91ZMCk6hcFjmZTEI+A9jS08y5YBmvRmHYto=; b=dadlILiIm9tqHowCrLFv5RiCrAdLnXF7SMji2CldamkTFarIwd05dTXOJUaS39JlXl BI4cbyctJNdVwnGS7SLElxpOlcatuXUutaJ+NGmbxSHwPVTPNVwVSMXD4BVaZ/Dd2wj/ y+nk03NhKZ2BkmTsQuSk5aUE5fmrPgEd+RMQZ2UfOzVuWvAe718+/SVaLFSP28Vtj4R3 M2gDZD3ZUNK2t7yto3LXjDGy9csGyh0dP/Lh5wp7wq9itVpe9GnzL6r6gHP1T2lWAxEQ hq+J7Jx05aSKce0BgMPXnNGRNlwopmPvuXmdMqSd7VcKZcpVqRBwbGj7rRkfT4rLg1Tu fUfQ== X-Gm-Message-State: AJIora9IpW5+jpUZPOBolV/yIdulV2edP2N4v5wjWceCyv/vcuywtwvm kTL0qcHXb/aT03E1uGggkmU= X-Google-Smtp-Source: AGRyM1u1O7IbGlCSb2W0z07Faoy+qxDC/2bGGhp0//xqfGkDbF6Y0I5dQPL140qQvD8ii2z0+81geQ== X-Received: by 2002:a05:6a00:26cf:b0:4f6:fc52:7b6a with SMTP id p15-20020a056a0026cf00b004f6fc527b6amr53917079pfw.39.1657218293162; Thu, 07 Jul 2022 11:24:53 -0700 (PDT) Received: from prasmi.domain.name ([103.219.60.85]) by smtp.gmail.com with ESMTPSA id o12-20020a170902d4cc00b0016a3f9e4865sm28589279plg.148.2022.07.07.11.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 11:24:52 -0700 (PDT) From: prabhakar.csengg@gmail.com X-Google-Original-From: prabhakar.mahadev-lad.rj@bp.renesas.com To: Marc Zyngier , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Geert Uytterhoeven , Linus Walleij , Bartosz Golaszewski , Philipp Zabel , devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar Subject: [PATCH v8 3/6] irqchip: Add RZ/G2L IA55 Interrupt Controller driver Date: Thu, 7 Jul 2022 19:23:11 +0100 Message-Id: <20220707182314.66610-4-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar Add a driver for the Renesas RZ/G2L Interrupt Controller. This supports external pins being used as interrupts. It supports one line for NMI, 8 external pins and 32 GPIO pins (out of 123) to be used as IRQ lines. Signed-off-by: Lad Prabhakar --- drivers/irqchip/Kconfig | 8 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-renesas-rzg2l.c | 393 ++++++++++++++++++++++++++++ 3 files changed, 402 insertions(+) create mode 100644 drivers/irqchip/irq-renesas-rzg2l.c diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index bbb11cb8b0f7..1fa07004eaf9 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -242,6 +242,14 @@ config RENESAS_RZA1_IRQC Enable support for the Renesas RZ/A1 Interrupt Controller, to use up to 8 external interrupts with configurable sense select. =20 +config RENESAS_RZG2L_IRQC + bool "Renesas RZ/G2L (and alike SoC) IRQC support" if COMPILE_TEST + select GENERIC_IRQ_CHIP + select IRQ_DOMAIN_HIERARCHY + help + Enable support for the Renesas RZ/G2L (and alike SoC) Interrupt Control= ler + for external devices. + config SL28CPLD_INTC bool "Kontron sl28cpld IRQ controller" depends on MFD_SL28CPLD=3Dy || COMPILE_TEST diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index 5b67450a9538..04cb15b647c5 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_RDA_INTC) +=3D irq-rda-intc.o obj-$(CONFIG_RENESAS_INTC_IRQPIN) +=3D irq-renesas-intc-irqpin.o obj-$(CONFIG_RENESAS_IRQC) +=3D irq-renesas-irqc.o obj-$(CONFIG_RENESAS_RZA1_IRQC) +=3D irq-renesas-rza1.o +obj-$(CONFIG_RENESAS_RZG2L_IRQC) +=3D irq-renesas-rzg2l.o obj-$(CONFIG_VERSATILE_FPGA_IRQ) +=3D irq-versatile-fpga.o obj-$(CONFIG_ARCH_NSPIRE) +=3D irq-zevio.o obj-$(CONFIG_ARCH_VT8500) +=3D irq-vt8500.o diff --git a/drivers/irqchip/irq-renesas-rzg2l.c b/drivers/irqchip/irq-rene= sas-rzg2l.c new file mode 100644 index 000000000000..25fd8ee66565 --- /dev/null +++ b/drivers/irqchip/irq-renesas-rzg2l.c @@ -0,0 +1,393 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Renesas RZ/G2L IRQC Driver + * + * Copyright (C) 2022 Renesas Electronics Corporation. + * + * Author: Lad Prabhakar + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define IRQC_IRQ_START 1 +#define IRQC_IRQ_COUNT 8 +#define IRQC_TINT_START (IRQC_IRQ_START + IRQC_IRQ_COUNT) +#define IRQC_TINT_COUNT 32 +#define IRQC_NUM_IRQ (IRQC_TINT_START + IRQC_TINT_COUNT) + +#define ISCR 0x10 +#define IITSR 0x14 +#define TSCR 0x20 +#define TITSR0 0x24 +#define TITSR1 0x28 +#define TITSR0_MAX_INT 16 +#define TITSEL_WIDTH 0x2 +#define TSSR(n) (0x30 + ((n) * 4)) +#define TIEN BIT(7) +#define TSSEL_SHIFT(n) (8 * (n)) +#define TSSEL_MASK GENMASK(7, 0) +#define IRQ_MASK 0x3 + +#define TSSR_OFFSET(n) ((n) % 4) +#define TSSR_INDEX(n) ((n) / 4) + +#define TITSR_TITSEL_EDGE_RISING 0 +#define TITSR_TITSEL_EDGE_FALLING 1 +#define TITSR_TITSEL_LEVEL_HIGH 2 +#define TITSR_TITSEL_LEVEL_LOW 3 + +#define IITSR_IITSEL(n, sense) ((sense) << ((n) * 2)) +#define IITSR_IITSEL_LEVEL_LOW 0 +#define IITSR_IITSEL_EDGE_FALLING 1 +#define IITSR_IITSEL_EDGE_RISING 2 +#define IITSR_IITSEL_EDGE_BOTH 3 +#define IITSR_IITSEL_MASK(n) IITSR_IITSEL((n), 3) + +#define TINT_EXTRACT_HWIRQ(x) FIELD_GET(GENMASK(15, 0), (x)) +#define TINT_EXTRACT_GPIOINT(x) FIELD_GET(GENMASK(31, 16), (x)) + +struct rzg2l_irqc_priv { + void __iomem *base; + struct irq_fwspec fwspec[IRQC_NUM_IRQ]; + raw_spinlock_t lock; +}; + +static struct rzg2l_irqc_priv *irq_data_to_priv(struct irq_data *data) +{ + return data->domain->host_data; +} + +static void rzg2l_irq_eoi(struct irq_data *d) +{ + unsigned int hw_irq =3D irqd_to_hwirq(d) - IRQC_IRQ_START; + struct rzg2l_irqc_priv *priv =3D irq_data_to_priv(d); + u32 bit =3D BIT(hw_irq); + u32 reg; + + reg =3D readl_relaxed(priv->base + ISCR); + if (reg & bit) + writel_relaxed(reg & ~bit, priv->base + ISCR); +} + +static void rzg2l_tint_eoi(struct irq_data *d) +{ + unsigned int hw_irq =3D irqd_to_hwirq(d) - IRQC_TINT_START; + struct rzg2l_irqc_priv *priv =3D irq_data_to_priv(d); + u32 bit =3D BIT(hw_irq); + u32 reg; + + reg =3D readl_relaxed(priv->base + TSCR); + if (reg & bit) + writel_relaxed(reg & ~bit, priv->base + TSCR); +} + +static void rzg2l_irqc_eoi(struct irq_data *d) +{ + struct rzg2l_irqc_priv *priv =3D irq_data_to_priv(d); + unsigned int hw_irq =3D irqd_to_hwirq(d); + + raw_spin_lock(&priv->lock); + if (hw_irq >=3D IRQC_IRQ_START && hw_irq <=3D IRQC_IRQ_COUNT) + rzg2l_irq_eoi(d); + else if (hw_irq >=3D IRQC_TINT_START && hw_irq < IRQC_NUM_IRQ) + rzg2l_tint_eoi(d); + raw_spin_unlock(&priv->lock); + irq_chip_eoi_parent(d); +} + +static void rzg2l_irqc_irq_disable(struct irq_data *d) +{ + unsigned int hw_irq =3D irqd_to_hwirq(d); + + if (hw_irq >=3D IRQC_TINT_START && hw_irq < IRQC_NUM_IRQ) { + struct rzg2l_irqc_priv *priv =3D irq_data_to_priv(d); + u32 offset =3D hw_irq - IRQC_TINT_START; + u32 tssr_offset =3D TSSR_OFFSET(offset); + u8 tssr_index =3D TSSR_INDEX(offset); + u32 reg; + + raw_spin_lock(&priv->lock); + reg =3D readl_relaxed(priv->base + TSSR(tssr_index)); + reg &=3D ~(TSSEL_MASK << tssr_offset); + writel_relaxed(reg, priv->base + TSSR(tssr_index)); + raw_spin_unlock(&priv->lock); + } + irq_chip_disable_parent(d); +} + +static void rzg2l_irqc_irq_enable(struct irq_data *d) +{ + unsigned int hw_irq =3D irqd_to_hwirq(d); + + if (hw_irq >=3D IRQC_TINT_START && hw_irq < IRQC_NUM_IRQ) { + struct rzg2l_irqc_priv *priv =3D irq_data_to_priv(d); + unsigned long tint =3D (uintptr_t)d->chip_data; + u32 offset =3D hw_irq - IRQC_TINT_START; + u32 tssr_offset =3D TSSR_OFFSET(offset); + u8 tssr_index =3D TSSR_INDEX(offset); + u32 reg; + + raw_spin_lock(&priv->lock); + reg =3D readl_relaxed(priv->base + TSSR(tssr_index)); + reg |=3D (TIEN | tint) << TSSEL_SHIFT(tssr_offset); + writel_relaxed(reg, priv->base + TSSR(tssr_index)); + raw_spin_unlock(&priv->lock); + } + irq_chip_enable_parent(d); +} + +static int rzg2l_irq_set_type(struct irq_data *d, unsigned int type) +{ + unsigned int hw_irq =3D irqd_to_hwirq(d) - IRQC_IRQ_START; + struct rzg2l_irqc_priv *priv =3D irq_data_to_priv(d); + u16 sense, tmp; + + switch (type & IRQ_TYPE_SENSE_MASK) { + case IRQ_TYPE_LEVEL_LOW: + sense =3D IITSR_IITSEL_LEVEL_LOW; + break; + + case IRQ_TYPE_EDGE_FALLING: + sense =3D IITSR_IITSEL_EDGE_FALLING; + break; + + case IRQ_TYPE_EDGE_RISING: + sense =3D IITSR_IITSEL_EDGE_RISING; + break; + + case IRQ_TYPE_EDGE_BOTH: + sense =3D IITSR_IITSEL_EDGE_BOTH; + break; + + default: + return -EINVAL; + } + + raw_spin_lock(&priv->lock); + tmp =3D readl_relaxed(priv->base + IITSR); + tmp &=3D ~IITSR_IITSEL_MASK(hw_irq); + tmp |=3D IITSR_IITSEL(hw_irq, sense); + writel_relaxed(tmp, priv->base + IITSR); + raw_spin_unlock(&priv->lock); + + return 0; +} + +static int rzg2l_tint_set_edge(struct irq_data *d, unsigned int type) +{ + struct rzg2l_irqc_priv *priv =3D irq_data_to_priv(d); + unsigned int hwirq =3D irqd_to_hwirq(d); + u32 titseln =3D hwirq - IRQC_TINT_START; + u32 offset; + u8 sense; + u32 reg; + + switch (type & IRQ_TYPE_SENSE_MASK) { + case IRQ_TYPE_EDGE_RISING: + sense =3D TITSR_TITSEL_EDGE_RISING; + break; + + case IRQ_TYPE_EDGE_FALLING: + sense =3D TITSR_TITSEL_EDGE_FALLING; + break; + + default: + return -EINVAL; + } + + offset =3D TITSR0; + if (titseln >=3D TITSR0_MAX_INT) { + titseln -=3D TITSR0_MAX_INT; + offset =3D TITSR1; + } + + raw_spin_lock(&priv->lock); + reg =3D readl_relaxed(priv->base + offset); + reg &=3D ~(IRQ_MASK << (titseln * TITSEL_WIDTH)); + reg |=3D sense << (titseln * TITSEL_WIDTH); + writel_relaxed(reg, priv->base + offset); + raw_spin_unlock(&priv->lock); + + return 0; +} + +static int rzg2l_irqc_set_type(struct irq_data *d, unsigned int type) +{ + unsigned int hw_irq =3D irqd_to_hwirq(d); + int ret =3D -EINVAL; + + if (hw_irq >=3D IRQC_IRQ_START && hw_irq <=3D IRQC_IRQ_COUNT) + ret =3D rzg2l_irq_set_type(d, type); + else if (hw_irq >=3D IRQC_TINT_START && hw_irq < IRQC_NUM_IRQ) + ret =3D rzg2l_tint_set_edge(d, type); + if (ret) + return ret; + + return irq_chip_set_type_parent(d, IRQ_TYPE_LEVEL_HIGH); +} + +static const struct irq_chip irqc_chip =3D { + .name =3D "rzg2l-irqc", + .irq_eoi =3D rzg2l_irqc_eoi, + .irq_mask =3D irq_chip_mask_parent, + .irq_unmask =3D irq_chip_unmask_parent, + .irq_disable =3D rzg2l_irqc_irq_disable, + .irq_enable =3D rzg2l_irqc_irq_enable, + .irq_get_irqchip_state =3D irq_chip_get_parent_state, + .irq_set_irqchip_state =3D irq_chip_set_parent_state, + .irq_retrigger =3D irq_chip_retrigger_hierarchy, + .irq_set_type =3D rzg2l_irqc_set_type, + .flags =3D IRQCHIP_MASK_ON_SUSPEND | + IRQCHIP_SET_TYPE_MASKED | + IRQCHIP_SKIP_SET_WAKE, +}; + +static int rzg2l_irqc_alloc(struct irq_domain *domain, unsigned int virq, + unsigned int nr_irqs, void *arg) +{ + struct rzg2l_irqc_priv *priv =3D domain->host_data; + unsigned long tint =3D 0; + irq_hw_number_t hwirq; + unsigned int type; + int ret; + + ret =3D irq_domain_translate_twocell(domain, arg, &hwirq, &type); + if (ret) + return ret; + + /* + * For TINT interrupts ie where pinctrl driver is child of irqc domain + * the hwirq and TINT are encoded in fwspec->param[0]. + * hwirq for TINT range from 9-40, hwirq is embedded 0-15 bits and TINT + * from 16-31 bits. TINT from the pinctrl driver needs to be programmed + * in IRQC registers to enable a given gpio pin as interrupt. + */ + if (hwirq > IRQC_IRQ_COUNT) { + tint =3D TINT_EXTRACT_GPIOINT(hwirq); + hwirq =3D TINT_EXTRACT_HWIRQ(hwirq); + + if (hwirq < IRQC_TINT_START) + return -EINVAL; + } + + if (hwirq > (IRQC_NUM_IRQ - 1)) + return -EINVAL; + + ret =3D irq_domain_set_hwirq_and_chip(domain, virq, hwirq, &irqc_chip, + (void *)(uintptr_t)tint); + if (ret) + return ret; + + return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &priv->fwspec[= hwirq]); +} + +static const struct irq_domain_ops rzg2l_irqc_domain_ops =3D { + .alloc =3D rzg2l_irqc_alloc, + .free =3D irq_domain_free_irqs_common, + .translate =3D irq_domain_translate_twocell, +}; + +static int rzg2l_irqc_parse_interrupts(struct rzg2l_irqc_priv *priv, + struct device_node *np) +{ + struct of_phandle_args map; + unsigned int i; + int ret; + + for (i =3D 0; i < IRQC_NUM_IRQ; i++) { + ret =3D of_irq_parse_one(np, i, &map); + if (ret) + return ret; + of_phandle_args_to_fwspec(np, map.args, map.args_count, + &priv->fwspec[i]); + } + + return 0; +} + +static int rzg2l_irqc_init(struct device_node *node, struct device_node *p= arent) +{ + struct irq_domain *irq_domain, *parent_domain; + struct platform_device *pdev; + struct reset_control *resetn; + struct rzg2l_irqc_priv *priv; + int ret; + + pdev =3D of_find_device_by_node(node); + if (!pdev) + return -ENODEV; + + parent_domain =3D irq_find_host(parent); + if (!parent_domain) { + dev_err(&pdev->dev, "cannot find parent domain\n"); + return -ENODEV; + } + + priv =3D devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->base =3D devm_of_iomap(&pdev->dev, pdev->dev.of_node, 0, NULL); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + ret =3D rzg2l_irqc_parse_interrupts(priv, node); + if (ret) { + dev_err(&pdev->dev, "cannot parse interrupts: %d\n", ret); + return ret; + } + + resetn =3D devm_reset_control_get_exclusive(&pdev->dev, NULL); + if (IS_ERR(resetn)) + return PTR_ERR(resetn); + + ret =3D reset_control_deassert(resetn); + if (ret) { + dev_err(&pdev->dev, "failed to deassert resetn pin, %d\n", ret); + return ret; + } + + pm_runtime_enable(&pdev->dev); + ret =3D pm_runtime_resume_and_get(&pdev->dev); + if (ret < 0) { + dev_err(&pdev->dev, "pm_runtime_resume_and_get failed: %d\n", ret); + goto pm_disable; + } + + raw_spin_lock_init(&priv->lock); + + irq_domain =3D irq_domain_add_hierarchy(parent_domain, 0, IRQC_NUM_IRQ, + node, &rzg2l_irqc_domain_ops, + priv); + if (!irq_domain) { + dev_err(&pdev->dev, "failed to add irq domain\n"); + ret =3D -ENOMEM; + goto pm_put; + } + + return 0; + +pm_put: + pm_runtime_put(&pdev->dev); +pm_disable: + pm_runtime_disable(&pdev->dev); + reset_control_assert(resetn); + return ret; +} + +IRQCHIP_PLATFORM_DRIVER_BEGIN(rzg2l_irqc) +IRQCHIP_MATCH("renesas,rzg2l-irqc", rzg2l_irqc_init) +IRQCHIP_PLATFORM_DRIVER_END(rzg2l_irqc) +MODULE_AUTHOR("Lad Prabhakar "); +MODULE_DESCRIPTION("Renesas RZ/G2L IRQC Driver"); +MODULE_LICENSE("GPL"); --=20 2.25.1 From nobody Sun May 19 06:04:51 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34A82C433EF for ; Thu, 7 Jul 2022 18:25:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236265AbiGGSZE (ORCPT ); Thu, 7 Jul 2022 14:25:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236236AbiGGSZA (ORCPT ); Thu, 7 Jul 2022 14:25:00 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9B162F65B; Thu, 7 Jul 2022 11:24:58 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d10so7263699pfd.9; Thu, 07 Jul 2022 11:24:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5cMLmJlHSoTnoQ2xIzWJpEHkZ6TyCa/o1NQh7zaJChE=; b=jnOxLHE2q8q5o4UOglWqbsseNhQ1qB+LfzEo71qy2cuhFWf0PTKZFyQLE9Fvq2Ssb7 gp5fxEztoIcgkQ5kLiyK/Ga6dLM6bv6uEFhFefslL2l79JBrbU3AdAx0Xx8lt3kjceup PGo7KMcSSqs5PpbXcvM7rfF21whmLcWMLlbV94yMDieEudRG8khU17Zd8jF2bQp0eL7x ayBPxIBJjVhfLPEGsl61PPQJE1U5ERQluEz4OjzIArCb+PV1GwUtgcEzMku+qgMIr9RT kIExHvIiP/HLn7gfoZ+r/sFRaL8k6kYXnTsPPEWFnXZ75G/HLS8Ci65p0SFG2vV6h6RM ViTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5cMLmJlHSoTnoQ2xIzWJpEHkZ6TyCa/o1NQh7zaJChE=; b=XI0FHlVtRpu6tIsbv3TQ9epWkYbE5OiHGQ0di/epiqzZmtj3p91Q/vqehb1jBniVJJ 6jdrjlerjyg1rnOhfVJtNjpvKXdDy+FnUSdi51/2kfwIp/CLhVsTNePHly8hhYHGt4Hu SRgLt0uEI9jBY6cS623wsoWels3uSNTMoEREcIa25D/Bit+G0Rwo+7L0sQHHyJv7jpok t1Hic1VjAs19uSCxstwZtQ+yQggoe7rnisF3HI2g3RWMSlbuu/dKU5OKYUWC/tjOjdm2 7DVeM5WrFIZuFYRSeFWtzoivOH3jO+Lw1HQcl36TvB4Hi01olKMEZaAvUSIFy6oTsG6Z 6qng== X-Gm-Message-State: AJIora8fyCt3Vsx7nBmMNU0SlzcW0/JjREcQBf9s20GKyu6oL7TCR7JC tcbU2f0mZmUi8WD5FSzfM+I= X-Google-Smtp-Source: AGRyM1uEI6pX7Y121lDDFGHLGbvelHMJJQsxrHdZk6dH44z0BY9RPRIzrgLlsiidz/FlR6r/oy8Tpg== X-Received: by 2002:a05:6a00:cce:b0:525:79b5:588c with SMTP id b14-20020a056a000cce00b0052579b5588cmr54588726pfv.19.1657218298499; Thu, 07 Jul 2022 11:24:58 -0700 (PDT) Received: from prasmi.domain.name ([103.219.60.85]) by smtp.gmail.com with ESMTPSA id o12-20020a170902d4cc00b0016a3f9e4865sm28589279plg.148.2022.07.07.11.24.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 11:24:57 -0700 (PDT) From: prabhakar.csengg@gmail.com X-Google-Original-From: prabhakar.mahadev-lad.rj@bp.renesas.com To: Marc Zyngier , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Geert Uytterhoeven , Linus Walleij , Bartosz Golaszewski , Philipp Zabel , devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar Subject: [PATCH v8 4/6] gpio: gpiolib: Allow free() callback to be overridden Date: Thu, 7 Jul 2022 19:23:12 +0100 Message-Id: <20220707182314.66610-5-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar Allow free() callback to be overridden from irq_domain_ops for hierarchical chips. This allows drivers to free up resources which are allocated during child_to_parent_hwirq()/populate_parent_alloc_arg() callbacks. On Renesas RZ/G2L platform a bitmap is maintained for TINT slots, a slot is allocated in child_to_parent_hwirq() callback which is freed up in free callback hence this override. Signed-off-by: Lad Prabhakar Reviewed-by: Geert Uytterhoeven Acked-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index bfde94243752..68d9f95d7799 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1181,15 +1181,18 @@ static void gpiochip_hierarchy_setup_domain_ops(str= uct irq_domain_ops *ops) ops->activate =3D gpiochip_irq_domain_activate; ops->deactivate =3D gpiochip_irq_domain_deactivate; ops->alloc =3D gpiochip_hierarchy_irq_domain_alloc; - ops->free =3D irq_domain_free_irqs_common; =20 /* - * We only allow overriding the translate() function for + * We only allow overriding the translate() and free() functions for * hierarchical chips, and this should only be done if the user - * really need something other than 1:1 translation. + * really need something other than 1:1 translation for translate() + * callback and free if user wants to free up any resources which + * were allocated during callbacks, for example populate_parent_alloc_arg. */ if (!ops->translate) ops->translate =3D gpiochip_hierarchy_irq_domain_translate; + if (!ops->free) + ops->free =3D irq_domain_free_irqs_common; } =20 static int gpiochip_hierarchy_add_domain(struct gpio_chip *gc) --=20 2.25.1 From nobody Sun May 19 06:04:51 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37F3FCCA479 for ; Thu, 7 Jul 2022 18:25:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236119AbiGGSZP (ORCPT ); Thu, 7 Jul 2022 14:25:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236272AbiGGSZG (ORCPT ); Thu, 7 Jul 2022 14:25:06 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FDF93120C; Thu, 7 Jul 2022 11:25:04 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id q82so12830215pgq.6; Thu, 07 Jul 2022 11:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jWodpiWQQkmXlbhQ6Hum7yJMbf/CRHimuamMgEhZ7AQ=; b=b70THC5Z6MHec4fmPJUFbmYsUEX3pkNt3ZYkut4gnCMU42M/vawk+RGYbkI4xfI1Ux sirXuUcvJxHAbkLsTckkqagXKB5AOoExuVCdb9mdbMRaDyInzBcDcWJsd8enMVKW4ktp qqnlN6YKZTNk/O762Yr50xBoVSisvbHV+bWwdKQCrMpwGYJRm74FrIm8Yc34Zq/TuwvF kHy6o8Bad7KMp463yoxkbNYjF6whZFbAHHDuv3v4oSJ0u/P3PoRmNKFZyC79xO6hXv8M 2Pgv7ztomQ0/jSdC1INsabJQMgiEN1GTXZ38DXR9l9j+s4A7gMT8Xtr7SHwiPvg/tVJy KDBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jWodpiWQQkmXlbhQ6Hum7yJMbf/CRHimuamMgEhZ7AQ=; b=iVm9FNb88wGxvF9BNfBBvNvRuRa8h0Ep/0lCipYw6+8+hVAujAR0jww1dFa/MPoAd5 b8F0EhnEr2y1J416VVijrjNCM85B7FMeOZDC0APkuxXy4gHAHWJQqqkkiBoke7g48KED hsuxuj/9h0GsPQTSvssYOpm9wNbBzdfm6oyjvTDSTbjmN7+rvvCxEqP9me5fkObzWfXc bYLBnkFtSdJzB86eWT+unAmZriObSOR0qXqEltIoEpmg+YLyxIj2goN6JZ+57jq2k4He aNHPJvzZEpNe0RF20aNiGo16PKcnE87ZDMLVYbcsL9dqUBcoclIf3wPilqnQhALnewBh 6cjA== X-Gm-Message-State: AJIora/kvCvW2/SshT0kIZGui9SBhI9om3a/tfM7yfwJ3D01Nb2vI3ZV ubqJIBA3hWCbwWGHYs3GMWs= X-Google-Smtp-Source: AGRyM1v2U5zQROTYH7xRziokWUvcFLZSoYz7ukjiigrTBkvh+tkrk0Eg54cszcr/pTa63y+PkRMvUQ== X-Received: by 2002:a17:902:db0c:b0:16a:4b7e:af5e with SMTP id m12-20020a170902db0c00b0016a4b7eaf5emr54445993plx.145.1657218304145; Thu, 07 Jul 2022 11:25:04 -0700 (PDT) Received: from prasmi.domain.name ([103.219.60.85]) by smtp.gmail.com with ESMTPSA id o12-20020a170902d4cc00b0016a3f9e4865sm28589279plg.148.2022.07.07.11.24.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 11:25:03 -0700 (PDT) From: prabhakar.csengg@gmail.com X-Google-Original-From: prabhakar.mahadev-lad.rj@bp.renesas.com To: Marc Zyngier , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Geert Uytterhoeven , Linus Walleij , Bartosz Golaszewski , Philipp Zabel , devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar , Rob Herring Subject: [PATCH v8 5/6] dt-bindings: pinctrl: renesas,rzg2l-pinctrl: Document the properties to handle GPIO IRQ Date: Thu, 7 Jul 2022 19:23:13 +0100 Message-Id: <20220707182314.66610-6-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar Document the required properties to handle GPIO IRQ. Signed-off-by: Lad Prabhakar Reviewed-by: Geert Uytterhoeven Reviewed-by: Rob Herring Acked-by: Linus Walleij --- .../bindings/pinctrl/renesas,rzg2l-pinctrl.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctr= l.yaml b/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctrl.ya= ml index 52df1b146174..997b74639112 100644 --- a/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctrl.yaml +++ b/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctrl.yaml @@ -47,6 +47,17 @@ properties: gpio-ranges: maxItems: 1 =20 + interrupt-controller: true + + '#interrupt-cells': + const: 2 + description: + The first cell contains the global GPIO port index, constructed usin= g the + RZG2L_GPIO() helper macro in a= nd the + second cell is used to specify the flag. + E.g. "interrupts =3D ;" if = P43_0 is + being used as an interrupt. + clocks: maxItems: 1 =20 @@ -110,6 +121,8 @@ required: - gpio-controller - '#gpio-cells' - gpio-ranges + - interrupt-controller + - '#interrupt-cells' - clocks - power-domains - resets @@ -126,6 +139,8 @@ examples: gpio-controller; #gpio-cells =3D <2>; gpio-ranges =3D <&pinctrl 0 0 392>; + interrupt-controller; + #interrupt-cells =3D <2>; clocks =3D <&cpg CPG_MOD R9A07G044_GPIO_HCLK>; resets =3D <&cpg R9A07G044_GPIO_RSTN>, <&cpg R9A07G044_GPIO_PORT_RESETN>, --=20 2.25.1 From nobody Sun May 19 06:04:51 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8853FC433EF for ; Thu, 7 Jul 2022 18:25:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236290AbiGGSZS (ORCPT ); Thu, 7 Jul 2022 14:25:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236267AbiGGSZL (ORCPT ); Thu, 7 Jul 2022 14:25:11 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 336CD31360; Thu, 7 Jul 2022 11:25:10 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id y141so21036924pfb.7; Thu, 07 Jul 2022 11:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EOi6ye8INiqN8HnncVv3ZVs2L4XvBCNLdv4z2vZ3/Bg=; b=RbSxVCncU5/g6BnOLenM4/4krgK6UUCJru8ihZSKdiNlnCHsbx82/tvGryrUY1X9rp WrytpsnJRFi+eBR/eTvfFubVXjQh5UuWmrJq5wZR5TmtOoXCl+kXsXAE5ISmRQkJ+IQO 6tY6ZbtbdNUedhoawdOz8azsN+8HnzzhDSQDpxUDINwBh5TjLqBTvp3OALcA/tCQqiJU RneUaU7PlVzmBG9wwxSTzMA07DHWat0qVfluJ1ZUmO4DpJpxegGlLGr+CiJYSHQDrIRE pG9lteRbrpvrI0uQ8wjBBtz97oVYrGYfh7w8PUTsVnd5W7h5hLh4G0cFugmssTHXaBg7 pMjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EOi6ye8INiqN8HnncVv3ZVs2L4XvBCNLdv4z2vZ3/Bg=; b=iWAqFOWnq4eltna+/fn0SRiUqRS4r78MsK5d0CsUKXibyXBrs3EERpP11zZLMDzN9t qXSESdYEatCltPNDptcCrgNqKwrmiAfzWjyqdq6Bb3SDjbNJGeQ1piES2l1pIPRc03U+ DLScBGEBGBT2z5PHVYvpxcE2bad4yfMm7f61BSdZHyeDd2QYXjX/NtCkGVl1BpAKD7MI cUAOSH2wnKUIQNPk6sONFTFzOUNTo4EfXdahX83h+tsxn87+2rF8t5o/U8JX3ou6QuqW rHs/iTyQ2HpwmbVbeu1E89wLVhlrBtjj0W6F0IDzSgIZeTXLfvg2NMUMAA/C64/7Qg18 JQaw== X-Gm-Message-State: AJIora/AgyX/C+4VIzc60sB0/SzJNOq84TuzpnaeJmqOatV09YaW4a8M SU8VaY6/ZDMuFTmRRfbJeX0= X-Google-Smtp-Source: AGRyM1sbUq7SSiSBTjb5BtCtgVvuhcz9ba7W4FYTZutXMp1JzJfXn29u+jzNp5ZQIf+r8vHGcIdkzw== X-Received: by 2002:a62:b419:0:b0:529:f06a:973e with SMTP id h25-20020a62b419000000b00529f06a973emr789259pfn.5.1657218309619; Thu, 07 Jul 2022 11:25:09 -0700 (PDT) Received: from prasmi.domain.name ([103.219.60.85]) by smtp.gmail.com with ESMTPSA id o12-20020a170902d4cc00b0016a3f9e4865sm28589279plg.148.2022.07.07.11.25.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 11:25:09 -0700 (PDT) From: prabhakar.csengg@gmail.com X-Google-Original-From: prabhakar.mahadev-lad.rj@bp.renesas.com To: Marc Zyngier , Thomas Gleixner , Rob Herring , Krzysztof Kozlowski , Geert Uytterhoeven , Linus Walleij , Bartosz Golaszewski , Philipp Zabel , devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Prabhakar , Biju Das , Lad Prabhakar Subject: [PATCH v8 6/6] pinctrl: renesas: pinctrl-rzg2l: Add IRQ domain to handle GPIO interrupt Date: Thu, 7 Jul 2022 19:23:14 +0100 Message-Id: <20220707182314.66610-7-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20220707182314.66610-1-prabhakar.mahadev-lad.rj@bp.renesas.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Lad Prabhakar Add IRQ domain to RZ/G2L pinctrl driver to handle GPIO interrupt. GPIO0-GPIO122 pins can be used as IRQ lines but only 32 pins can be used as IRQ lines at a given time. Selection of pins as IRQ lines is handled by IA55 (which is the IRQC block) which sits in between the GPIO and GIC. Signed-off-by: Lad Prabhakar Reviewed-by: Linus Walleij --- drivers/pinctrl/renesas/pinctrl-rzg2l.c | 233 ++++++++++++++++++++++++ 1 file changed, 233 insertions(+) diff --git a/drivers/pinctrl/renesas/pinctrl-rzg2l.c b/drivers/pinctrl/rene= sas/pinctrl-rzg2l.c index c3cdf52b7294..a43824fd9505 100644 --- a/drivers/pinctrl/renesas/pinctrl-rzg2l.c +++ b/drivers/pinctrl/renesas/pinctrl-rzg2l.c @@ -9,8 +9,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -89,6 +91,7 @@ #define PIN(n) (0x0800 + 0x10 + (n)) #define IOLH(n) (0x1000 + (n) * 8) #define IEN(n) (0x1800 + (n) * 8) +#define ISEL(n) (0x2c80 + (n) * 8) #define PWPR (0x3014) #define SD_CH(n) (0x3000 + (n) * 4) #define QSPI (0x3008) @@ -112,6 +115,10 @@ #define RZG2L_PIN_ID_TO_PORT_OFFSET(id) (RZG2L_PIN_ID_TO_PORT(id) + 0x10) #define RZG2L_PIN_ID_TO_PIN(id) ((id) % RZG2L_PINS_PER_PORT) =20 +#define RZG2L_TINT_MAX_INTERRUPT 32 +#define RZG2L_TINT_IRQ_START_INDEX 9 +#define RZG2L_PACK_HWIRQ(t, i) (((t) << 16) | (i)) + struct rzg2l_dedicated_configs { const char *name; u32 config; @@ -137,6 +144,9 @@ struct rzg2l_pinctrl { =20 struct gpio_chip gpio_chip; struct pinctrl_gpio_range gpio_range; + DECLARE_BITMAP(tint_slot, RZG2L_TINT_MAX_INTERRUPT); + spinlock_t bitmap_lock; + unsigned int hwirq[RZG2L_TINT_MAX_INTERRUPT]; =20 spinlock_t lock; }; @@ -885,8 +895,14 @@ static int rzg2l_gpio_get(struct gpio_chip *chip, unsi= gned int offset) =20 static void rzg2l_gpio_free(struct gpio_chip *chip, unsigned int offset) { + unsigned int virq; + pinctrl_gpio_free(chip->base + offset); =20 + virq =3D irq_find_mapping(chip->irq.domain, offset); + if (virq) + irq_dispose_mapping(virq); + /* * Set the GPIO as an input to ensure that the next GPIO request won't * drive the GPIO pin as an output. @@ -1106,14 +1122,221 @@ static struct { } }; =20 +static int rzg2l_gpio_get_gpioint(unsigned int virq) +{ + unsigned int gpioint; + unsigned int i; + u32 port, bit; + + port =3D virq / 8; + bit =3D virq % 8; + + if (port >=3D ARRAY_SIZE(rzg2l_gpio_configs) || + bit >=3D RZG2L_GPIO_PORT_GET_PINCNT(rzg2l_gpio_configs[port])) + return -EINVAL; + + gpioint =3D bit; + for (i =3D 0; i < port; i++) + gpioint +=3D RZG2L_GPIO_PORT_GET_PINCNT(rzg2l_gpio_configs[i]); + + return gpioint; +} + +static void rzg2l_gpio_irq_disable(struct irq_data *d) +{ + struct gpio_chip *gc =3D irq_data_get_irq_chip_data(d); + struct rzg2l_pinctrl *pctrl =3D container_of(gc, struct rzg2l_pinctrl, gp= io_chip); + unsigned int hwirq =3D irqd_to_hwirq(d); + unsigned long flags; + void __iomem *addr; + u32 port; + u8 bit; + + port =3D RZG2L_PIN_ID_TO_PORT(hwirq); + bit =3D RZG2L_PIN_ID_TO_PIN(hwirq); + + addr =3D pctrl->base + ISEL(port); + if (bit >=3D 4) { + bit -=3D 4; + addr +=3D 4; + } + + spin_lock_irqsave(&pctrl->lock, flags); + writel(readl(addr) & ~BIT(bit * 8), addr); + spin_unlock_irqrestore(&pctrl->lock, flags); + + gpiochip_disable_irq(gc, hwirq); + irq_chip_disable_parent(d); +} + +static void rzg2l_gpio_irq_enable(struct irq_data *d) +{ + struct gpio_chip *gc =3D irq_data_get_irq_chip_data(d); + struct rzg2l_pinctrl *pctrl =3D container_of(gc, struct rzg2l_pinctrl, gp= io_chip); + unsigned int hwirq =3D irqd_to_hwirq(d); + unsigned long flags; + void __iomem *addr; + u32 port; + u8 bit; + + gpiochip_enable_irq(gc, hwirq); + + port =3D RZG2L_PIN_ID_TO_PORT(hwirq); + bit =3D RZG2L_PIN_ID_TO_PIN(hwirq); + + addr =3D pctrl->base + ISEL(port); + if (bit >=3D 4) { + bit -=3D 4; + addr +=3D 4; + } + + spin_lock_irqsave(&pctrl->lock, flags); + writel(readl(addr) | BIT(bit * 8), addr); + spin_unlock_irqrestore(&pctrl->lock, flags); + + irq_chip_enable_parent(d); +} + +static int rzg2l_gpio_irq_set_type(struct irq_data *d, unsigned int type) +{ + return irq_chip_set_type_parent(d, type); +} + +static void rzg2l_gpio_irqc_eoi(struct irq_data *d) +{ + irq_chip_eoi_parent(d); +} + +static void rzg2l_gpio_irq_print_chip(struct irq_data *data, struct seq_fi= le *p) +{ + struct gpio_chip *gc =3D irq_data_get_irq_chip_data(data); + + seq_printf(p, dev_name(gc->parent)); +} + +static const struct irq_chip rzg2l_gpio_irqchip =3D { + .name =3D "rzg2l-gpio", + .irq_disable =3D rzg2l_gpio_irq_disable, + .irq_enable =3D rzg2l_gpio_irq_enable, + .irq_mask =3D irq_chip_mask_parent, + .irq_unmask =3D irq_chip_unmask_parent, + .irq_set_type =3D rzg2l_gpio_irq_set_type, + .irq_eoi =3D rzg2l_gpio_irqc_eoi, + .irq_print_chip =3D rzg2l_gpio_irq_print_chip, + .flags =3D IRQCHIP_IMMUTABLE, + GPIOCHIP_IRQ_RESOURCE_HELPERS, +}; + +static int rzg2l_gpio_child_to_parent_hwirq(struct gpio_chip *gc, + unsigned int child, + unsigned int child_type, + unsigned int *parent, + unsigned int *parent_type) +{ + struct rzg2l_pinctrl *pctrl =3D gpiochip_get_data(gc); + unsigned long flags; + int gpioint, irq; + + gpioint =3D rzg2l_gpio_get_gpioint(child); + if (gpioint < 0) + return gpioint; + + spin_lock_irqsave(&pctrl->bitmap_lock, flags); + irq =3D bitmap_find_free_region(pctrl->tint_slot, RZG2L_TINT_MAX_INTERRUP= T, get_order(1)); + spin_unlock_irqrestore(&pctrl->bitmap_lock, flags); + if (irq < 0) + return -ENOSPC; + pctrl->hwirq[irq] =3D child; + irq +=3D RZG2L_TINT_IRQ_START_INDEX; + + /* All these interrupts are level high in the CPU */ + *parent_type =3D IRQ_TYPE_LEVEL_HIGH; + *parent =3D RZG2L_PACK_HWIRQ(gpioint, irq); + return 0; +} + +static int rzg2l_gpio_populate_parent_fwspec(struct gpio_chip *chip, + union gpio_irq_fwspec *gfwspec, + unsigned int parent_hwirq, + unsigned int parent_type) +{ + struct irq_fwspec *fwspec =3D &gfwspec->fwspec; + + fwspec->fwnode =3D chip->irq.parent_domain->fwnode; + fwspec->param_count =3D 2; + fwspec->param[0] =3D parent_hwirq; + fwspec->param[1] =3D parent_type; + + return 0; +} + +static void rzg2l_gpio_irq_domain_free(struct irq_domain *domain, unsigned= int virq, + unsigned int nr_irqs) +{ + struct irq_data *d; + + d =3D irq_domain_get_irq_data(domain, virq); + if (d) { + struct gpio_chip *gc =3D irq_data_get_irq_chip_data(d); + struct rzg2l_pinctrl *pctrl =3D container_of(gc, struct rzg2l_pinctrl, g= pio_chip); + irq_hw_number_t hwirq =3D irqd_to_hwirq(d); + unsigned long flags; + unsigned int i; + + for (i =3D 0; i < RZG2L_TINT_MAX_INTERRUPT; i++) { + if (pctrl->hwirq[i] =3D=3D hwirq) { + spin_lock_irqsave(&pctrl->bitmap_lock, flags); + bitmap_release_region(pctrl->tint_slot, i, get_order(1)); + spin_unlock_irqrestore(&pctrl->bitmap_lock, flags); + pctrl->hwirq[i] =3D 0; + break; + } + } + } + irq_domain_free_irqs_common(domain, virq, nr_irqs); +} + +static void rzg2l_init_irq_valid_mask(struct gpio_chip *gc, + unsigned long *valid_mask, + unsigned int ngpios) +{ + struct rzg2l_pinctrl *pctrl =3D gpiochip_get_data(gc); + struct gpio_chip *chip =3D &pctrl->gpio_chip; + unsigned int offset; + + /* Forbid unused lines to be mapped as IRQs */ + for (offset =3D 0; offset < chip->ngpio; offset++) { + u32 port, bit; + + port =3D offset / 8; + bit =3D offset % 8; + + if (port >=3D ARRAY_SIZE(rzg2l_gpio_configs) || + bit >=3D RZG2L_GPIO_PORT_GET_PINCNT(rzg2l_gpio_configs[port])) + clear_bit(offset, valid_mask); + } +} + static int rzg2l_gpio_register(struct rzg2l_pinctrl *pctrl) { struct device_node *np =3D pctrl->dev->of_node; struct gpio_chip *chip =3D &pctrl->gpio_chip; const char *name =3D dev_name(pctrl->dev); + struct irq_domain *parent_domain; struct of_phandle_args of_args; + struct device_node *parent_np; + struct gpio_irq_chip *girq; int ret; =20 + parent_np =3D of_irq_find_parent(np); + if (!parent_np) + return -ENXIO; + + parent_domain =3D irq_find_host(parent_np); + of_node_put(parent_np); + if (!parent_domain) + return -EPROBE_DEFER; + ret =3D of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &of_arg= s); if (ret) { dev_err(pctrl->dev, "Unable to parse gpio-ranges\n"); @@ -1140,6 +1363,15 @@ static int rzg2l_gpio_register(struct rzg2l_pinctrl = *pctrl) chip->base =3D -1; chip->ngpio =3D of_args.args[2]; =20 + girq =3D &chip->irq; + gpio_irq_chip_set_chip(girq, &rzg2l_gpio_irqchip); + girq->fwnode =3D of_node_to_fwnode(np); + girq->parent_domain =3D parent_domain; + girq->child_to_parent_hwirq =3D rzg2l_gpio_child_to_parent_hwirq; + girq->populate_parent_alloc_arg =3D rzg2l_gpio_populate_parent_fwspec; + girq->child_irq_domain_ops.free =3D rzg2l_gpio_irq_domain_free; + girq->init_valid_mask =3D rzg2l_init_irq_valid_mask; + pctrl->gpio_range.id =3D 0; pctrl->gpio_range.pin_base =3D 0; pctrl->gpio_range.base =3D 0; @@ -1255,6 +1487,7 @@ static int rzg2l_pinctrl_probe(struct platform_device= *pdev) } =20 spin_lock_init(&pctrl->lock); + spin_lock_init(&pctrl->bitmap_lock); =20 platform_set_drvdata(pdev, pctrl); =20 --=20 2.25.1