Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp970378iob; Fri, 13 May 2022 18:06:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsPgfVgAgarnIPUhhIo6rqMIaNP2yKmPVczJe5bUiLOxy4++4TEZCQzapTt8Whk+0UxpGo X-Received: by 2002:adf:f90d:0:b0:20c:de32:4d35 with SMTP id b13-20020adff90d000000b0020cde324d35mr5846274wrr.583.1652490386730; Fri, 13 May 2022 18:06:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652490386; cv=none; d=google.com; s=arc-20160816; b=jjXxWBSA4KUm1pNaWO4wl+au8DSnUq5l+GV3hLJTyYZPK/oBrAyL1E5b0DFMErLJwe rcTs8jcMfoH1yFrJ48bqq5nn4qIlyiwrILdFwS32q6CBHfNw718ByqA5IIZrFR6NVcNx 1lTeM8GtocQt7NlbWDSsCf64yBBM7nievugC31W2FdxCJPj2BA4f7zZFjo6My3/mQN7D phPpX6wxKcdae37x/T8nACExpiTzvUrI8AtfBQ3KPEkFu3Fdy1unGuJ98nJu3QJtT0kw znZTqM0udJq95RcjpwQDh9dpkBzFsAbdXqi7Le3dtamIuHzZ13L/77G5xnQHq8Hl+3ZX 7urg== 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; bh=TlyaiZrjtX5woP3pqoSBYqz9u7xvXibpoxkFFDDRP/k=; b=KZLxYX+HDgUoBFOwzEBGQO63cU3uqsGM+sG1DwkZu3FkVcK9HdYz92zv0EIwtPaH7m a8py4LzKsaD7etd/yTVhdc+2FSpJx2CmCWoC/AK8gIDW3kwQs90YSTGqb0BpPh11jGfp Ivqy/pxPdsCOZiA9A/EFEuId7COPN2ic+zJLx67OLfMhu3Xjx6KM5FRcsMcxcNHqSK0i nZT9G6nBK5HiF6MT0CwAK9Hy4h0tel98o7e4y1Enhn2nVRy4qPjpsGLRq2Wmuo9J3tjX GbRtny5UohHPy9a4nWqlMhAPegJPLrq08r8lJTTnR+IxAQZAq+ietfE3odgkxIjAKndd nafw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n16-20020a1c7210000000b0038e7864dfc6si3597905wmc.126.2022.05.13.18.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:06:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 98A8837F0CF; Fri, 13 May 2022 16:38:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377495AbiEMGyC (ORCPT + 99 others); Fri, 13 May 2022 02:54:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377471AbiEMGx4 (ORCPT ); Fri, 13 May 2022 02:53:56 -0400 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 423E6266E25; Thu, 12 May 2022 23:53:52 -0700 (PDT) Received: by mail-qt1-f175.google.com with SMTP id u35so6167199qtc.13; Thu, 12 May 2022 23:53:52 -0700 (PDT) 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=TlyaiZrjtX5woP3pqoSBYqz9u7xvXibpoxkFFDDRP/k=; b=e8/RL3tw31RmCecjC4uPP4vO6GUXIih3uvIkmOXGLVLi9DTfn0U4axeGnjgVj6BhnI JG1AaQ/BvRTyXW9+w6gi8/Yi2EIz0edSxc7hCbRk0SvhkQLB897rcjm8z5afwBptxpuo cV12c2VP2gecbzRI/A/fY3Ahdq2PSeqPHbu4cWYb2wN0QMZznbxboP+2vxq77AW93YPo /TJCUVNLsRuXJ9zF3j9dwF4z1JzG33p9hHQLbBe5Iekw1+UMZnn6dsV15AUbkJV5eNn1 LKfjvvJJnYXvqyOMqHtfvMwil9Y2MOE0FTaZN1b9KDMEe+xfrRkUXidhxCdObgd2+TIw hE4w== X-Gm-Message-State: AOAM531/qWf4Jm1h48L1lGmuHOYdgn2LMfZGgXVTWf+G3D+ZmsCdf8iT VpaUeHShTK3eANygz1qpYrdMzvhzKY16NA== X-Received: by 2002:a05:622a:8d:b0:2f3:ba67:a0ba with SMTP id o13-20020a05622a008d00b002f3ba67a0bamr3191852qtw.129.1652424831242; Thu, 12 May 2022 23:53:51 -0700 (PDT) Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com. [209.85.219.178]) by smtp.gmail.com with ESMTPSA id i19-20020ac84f53000000b002f3ca56e6edsm1078611qtw.8.2022.05.12.23.53.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 May 2022 23:53:50 -0700 (PDT) Received: by mail-yb1-f178.google.com with SMTP id x74so1068432ybe.4; Thu, 12 May 2022 23:53:49 -0700 (PDT) X-Received: by 2002:a25:c0d5:0:b0:64a:c6dd:1a00 with SMTP id c204-20020a25c0d5000000b0064ac6dd1a00mr3118805ybf.365.1652424829627; Thu, 12 May 2022 23:53:49 -0700 (PDT) MIME-Version: 1.0 References: <20220511183210.5248-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20220511183210.5248-6-prabhakar.mahadev-lad.rj@bp.renesas.com> In-Reply-To: From: Geert Uytterhoeven Date: Fri, 13 May 2022 08:53:38 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 5/5] pinctrl: renesas: pinctrl-rzg2l: Add IRQ domain to handle GPIO interrupt To: "Lad, Prabhakar" Cc: Lad Prabhakar , Linus Walleij , Thomas Gleixner , Marc Zyngier , Rob Herring , Krzysztof Kozlowski , Bartosz Golaszewski , Philipp Zabel , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Linux-Renesas , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Phil Edworthy , Biju Das Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Prabhakar, On Thu, May 12, 2022 at 7:36 PM Lad, Prabhakar wrote: > On Thu, May 12, 2022 at 8:39 AM Geert Uytterhoeven wrote: > > On Wed, May 11, 2022 at 8:32 PM Lad Prabhakar > > wrote: > > > Add IRQ domian 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 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 > > > > Thanks for your patch! > > > > > --- a/drivers/pinctrl/renesas/pinctrl-rzg2l.c > > > +++ b/drivers/pinctrl/renesas/pinctrl-rzg2l.c > > > > > static int rzg2l_gpio_register(struct rzg2l_pinctrl *pctrl) > > > { > > > struct device_node *np = pctrl->dev->of_node; > > > struct gpio_chip *chip = &pctrl->gpio_chip; > > > const char *name = 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; > > > > > > + parent_np = of_irq_find_parent(np); > > > + if (!parent_np) > > > + return -ENXIO; > > > + > > > + parent_domain = irq_find_host(parent_np); > > > + of_node_put(parent_np); > > > + if (!parent_domain) > > > + return -EPROBE_DEFER; > > > + > > > ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &of_args); > > > if (ret) { > > > dev_err(pctrl->dev, "Unable to parse gpio-ranges\n"); > > > @@ -1138,6 +1330,15 @@ static int rzg2l_gpio_register(struct rzg2l_pinctrl *pctrl) > > > chip->base = -1; > > > chip->ngpio = of_args.args[2]; > > > > > > + girq = &chip->irq; > > > + girq->chip = &rzg2l_gpio_irqchip; > > > + girq->fwnode = of_node_to_fwnode(np); > > > + girq->parent_domain = parent_domain; > > > + girq->child_to_parent_hwirq = rzg2l_gpio_child_to_parent_hwirq; > > > + girq->populate_parent_alloc_arg = rzg2l_gpio_populate_parent_fwspec; > > > + girq->child_irq_domain_ops.free = rzg2l_gpio_irq_domain_free; > > > + girq->ngirq = RZG2L_TINT_MAX_INTERRUPT; > > > + > > > > I think you need to provide a .init_valid_mask() callback, as > > gpiochip_irqchip_remove() relies on that for destroying interrupts. > Are you suggesting the callback to avoid looping through all the GPIO pins? gpiochip_irqchip_remove() does: /* Remove all IRQ mappings and delete the domain */ if (gc->irq.domain) { unsigned int irq; for (offset = 0; offset < gc->ngpio; offset++) { if (!gpiochip_irqchip_irq_valid(gc, offset)) continue; irq = irq_find_mapping(gc->irq.domain, offset); irq_dispose_mapping(irq); } irq_domain_remove(gc->irq.domain); } The main thing is not about avoiding to loop through all GPIO pins, but to avoid irq_{find,dispose}_mapping() doing the wrong thing. The loop is over all GPIO offsets, while not all of them are mapped to valid interrupts. Does the above work correctly? > > However, the mask will need to be dynamic, as GPIO interrupts can be > > mapped and unmapped to one of the 32 available interrupts dynamically, > > right? > Yep that's correct. > > > I'm not sure if that can be done easily: if gpiochip_irqchip_irq_valid() > > is ever called too early, before the mapping is done, it would fail. > > > The mask initialization is a one time process and that is during > adding the GPIO chip. At this stage we won't be knowing what will be > the valid GPIO pins used as interrupts. Maybe the core needs to > implement a callback which lands in the GPIO controller driver to tell > if the gpio irq line is valid. This way we can handle dynamic > interrupts. Upon closer look, I think the mask is a red herring, and we don't need it. But we do need to handle the (possible) mismatch between GPIO offset (index) and IRQ offset in the above code. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds