From patchwork Tue Jul 25 00:40:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 125245 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2153269vqg; Mon, 24 Jul 2023 18:02:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlG78z8jUIOzOMMJ3xUwZHm5wlv4u0xp2YAUN3LtbRERGs1z++R7j9PVQdsDlPwZt/F/zggS X-Received: by 2002:a05:6a20:1388:b0:137:3803:33c with SMTP id hn8-20020a056a20138800b001373803033cmr8181425pzc.54.1690246957240; Mon, 24 Jul 2023 18:02:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690246957; cv=none; d=google.com; s=arc-20160816; b=p0dyQOftghzP0f1fu3ALt3dwSegk4zdWxDC9hAMbbas8rJ2T29lWw3Lhu0QbAA5Fae +ctio1QWVLAStP2P0lOjsl7dmpJnnhxhclnBBjTT8CzEBadObMH+aepSIfmSQhLk+L6T dgggpSsMA6Uoifm9Y9C8zeIBzVRDJ/Qnr7x8DSxh5141j/teGff9R16N/zuwu93y9Vfx LjnML4l40XY8/9rFeEj/s9ufrIdw23JrpqSITxJ7gyMTpooiMtyuTj0PZoaT+Eh+kROk 5dLG1lqGmxKgfJ+wMqNzWgYGDO078AVFA1UUZ2QFboFEWBSkWqRuiLuTu3x/CRVs54bF dLqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=whF81jM7MxzV+FT+tijidotVjimKPtD8G7YJMe5VYT8=; fh=7Iv+nmknwq0vzuxY/p9xeluMk1WnPOovtl66aotocHY=; b=mRvp05UNFbvbh9jB+z3CqqclHq6YK+kW4lobAInGcjxr3JoHW2rChe+vgm8JEYV2vd aTOkuZ9+FCpVIHwSmCMtZJtupIyiQyD9F3H96Hn+4bo8N2O5BiXgTtd0Y9mdV2u3LTir lJa/DrWka1rUnTB47/K22JWZhLjIrYL40RnnLetVMZ+i3+wOR416TIeamFoDOzrHBvO2 z6Jtw/HuczNIpmMrnAs92kr5ygm2L96COVqGLjOJ47NP1KwY/52z6IwTG6N8dRAvf0kL sbOs6hRGi/z7gxHXcZreu0tFD6dXnD912ZZtHkYYw9QDT1zNLG5RY6WQftQTl+7/1WOx YAlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=Y7GUiu94; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q13-20020a056a00084d00b0068104e45e1csi10780937pfk.236.2023.07.24.18.02.24; Mon, 24 Jul 2023 18:02:37 -0700 (PDT) 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=@sifive.com header.s=google header.b=Y7GUiu94; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231247AbjGYAku (ORCPT + 99 others); Mon, 24 Jul 2023 20:40:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229922AbjGYAks (ORCPT ); Mon, 24 Jul 2023 20:40:48 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3CCA1728 for ; Mon, 24 Jul 2023 17:40:47 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1b8ad356f03so25294885ad.1 for ; Mon, 24 Jul 2023 17:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1690245647; x=1690850447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=whF81jM7MxzV+FT+tijidotVjimKPtD8G7YJMe5VYT8=; b=Y7GUiu94wEBaKDhmb78iePTU5on4Y8af9I2D4KfrJx0c0JhIJBSRxWayKzgqvjmnOS 5LPHTZAppCbaxsEmtyQSbWzbp6i6vAQT6d8PZRKl4zoDuWsyYwMj5k+/WmvN3iFDIVD5 ENo/xB84IHvM25lxI+DrkCISNIo9ZvSYFA0IfdPDwfFM2/NhkRZMKBMJEM6gTRN2BAqf 8NRSfFyztf8TfsLhhRk2xs8RCtcNKPbbbrffPegyGnI+gmeNU5YkRTIHxdJrCueNvQan K6CXnrRwZfIkIYH9fNB2g0kIXYiXyWjXB8Ha3zgWiqOQG+kb9u9YsM49vOs1+EAH60ab wNAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690245647; x=1690850447; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=whF81jM7MxzV+FT+tijidotVjimKPtD8G7YJMe5VYT8=; b=K+44Rl7zzjnXvv++Q0kxORATot1ui8wdTwkeFSdt5VD4gNT4hzWTIBaszGukzeQSfb Fz6jUUFeYjEJfh2SEF11UtZMd2rtbj9c3gEM3W73fvtdtasn+FnzN2Br4si2t1nNBXjU 9wSJWeAfl/bb5W3tfbxy8QA1jzabzUugCvEdCQ42x0+333X0krhfYzC88EY6Pyiwx5Mv Z90BlRFHyKgO/2AAhxoaVC/t+zqiuO+MO2SkLO2vFvODASbrvtLu71xRSFvSx+Un2p7M WamPZq3dCxh+7ZDr3/1kcOmfEGAiBSlPvk7bh3sRLpJQuPFLH/ps8kiDuIUKGjKrCkN5 HbjQ== X-Gm-Message-State: ABy/qLZ/RKyYM97alI2Xl1TF0nObuSqRCBHOa4pAEUv9UEyWnFAeC2tN 60+3S3U72G6EfW1CT79NO7Iaww== X-Received: by 2002:a17:903:41cc:b0:1b8:9044:9ede with SMTP id u12-20020a17090341cc00b001b890449edemr10398291ple.62.1690245647479; Mon, 24 Jul 2023 17:40:47 -0700 (PDT) Received: from sw06.internal.sifive.com ([64.62.193.194]) by smtp.gmail.com with ESMTPSA id be11-20020a170902aa0b00b001b8a3e2c241sm9528297plb.14.2023.07.24.17.40.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 17:40:47 -0700 (PDT) From: Samuel Holland To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Cc: Emil Renner Berthing , Rob Herring , Frank Rowand , Samuel Holland , Palmer Dabbelt , Paul Walmsley , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v3 1/4] gpio: sifive: Directly use the device's fwnode Date: Mon, 24 Jul 2023 17:40:39 -0700 Message-Id: <20230725004043.381573-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230725004043.381573-1-samuel.holland@sifive.com> References: <20230725004043.381573-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772352393455830399 X-GMAIL-MSGID: 1772352393455830399 There is no need to convert dev->of_node back to a fwnode_handle. Signed-off-by: Samuel Holland --- Changes in v3: - Use dev_fwnode() instead of member access Changes in v2: - New patch for v2 drivers/gpio/gpio-sifive.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c index 745e5f67254e..db480cd7271a 100644 --- a/drivers/gpio/gpio-sifive.c +++ b/drivers/gpio/gpio-sifive.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -254,7 +255,7 @@ static int sifive_gpio_probe(struct platform_device *pdev) chip->gc.owner = THIS_MODULE; girq = &chip->gc.irq; gpio_irq_chip_set_chip(girq, &sifive_gpio_irqchip); - girq->fwnode = of_node_to_fwnode(node); + girq->fwnode = dev_fwnode(dev); girq->parent_domain = parent; girq->child_to_parent_hwirq = sifive_gpio_child_to_parent_hwirq; girq->handler = handle_bad_irq; From patchwork Tue Jul 25 00:40:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 125243 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2152672vqg; Mon, 24 Jul 2023 18:01:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlGi4Ve+nXeazFT4jkDzgPvEGh2uDaerejE9At/4wTASIpk2eH9f5Mj6a8geFmYS+L+keNeO X-Received: by 2002:a50:ee8d:0:b0:51d:f7b2:e95b with SMTP id f13-20020a50ee8d000000b0051df7b2e95bmr10445616edr.34.1690246887452; Mon, 24 Jul 2023 18:01:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690246887; cv=none; d=google.com; s=arc-20160816; b=SQPv9avhnti6RU5GroWKO4voYrV21GT9wEHYIqE5ik9avc/ytjIt1Ex5O1A0CaTQMw WV27lpdIBJf9UjpbZmR7Zm6QwdKWcsUAOMoQVIjaAtLBK2NpHjULyiLxujzgCoCJgPYY ndY7tHPwMTmm1IauqA8gDLauHAscNDgaeeAnwYGvvzcUmjQawgOo4BQgHcci/krVEJdE bkhxe5+J9VPBb82tO6RV9bAQaq2iZ1TK7g+iwRhCmmpluV7XJUb0tuYkF3IUHIKyi8OK R6LLU5LIux3Ti93r2AuzYEh8ZsC9CBpfOsneBURHPsoQ4Z/6kfp271F+mFQZXl9aUhpV q9qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gBxigjkHLT26fx4MKMtaVEtMyHCitliLAz5UQAux20w=; fh=7Iv+nmknwq0vzuxY/p9xeluMk1WnPOovtl66aotocHY=; b=d2zj5dfiyqv7Kj3nJiFDkpjTXWG3aJR3gL/BUqzOd42KY9ioEDhdqoztBuzLw5D/u7 9noQ1g7nLcNjxMfTdoVwdcCf72a/k4fQfp5+x8PDQBCaSHRtxUjOCUDET8uoZldwh8Vh pcQ117HKsTnc1u27anJYiaPJu3bgiMvwxvU5HFQODPBFvveYt7kK5/TjuWwignyNXPSV bDysETcOzaOkAeuIujDUhb+c1q3lLhwG8rj4oRcgI4rXnFtjvlhi4GmJSOZNTXmrUHI7 5klz1AZfyAgVg4MDap/fg2U6MXFOHuEM+P/kZEKKcXUMLuLh7lP869DnykFhloNESN8M MZmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=WZLiqvPp; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y14-20020aa7c24e000000b005221fc36675si3834180edo.78.2023.07.24.18.01.03; Mon, 24 Jul 2023 18:01:27 -0700 (PDT) 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=@sifive.com header.s=google header.b=WZLiqvPp; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231253AbjGYAkz (ORCPT + 99 others); Mon, 24 Jul 2023 20:40:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjGYAku (ORCPT ); Mon, 24 Jul 2023 20:40:50 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 327A6171E for ; Mon, 24 Jul 2023 17:40:49 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1b8ad356f03so25294935ad.1 for ; Mon, 24 Jul 2023 17:40:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1690245648; x=1690850448; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gBxigjkHLT26fx4MKMtaVEtMyHCitliLAz5UQAux20w=; b=WZLiqvPphZp2WlZ1ZnEhvYWQlvYox6mkBzRwKNXSEaEcIBtHZmJOqFz3y5ctV+C9Ja ydG8XHMTHzmxDUulcxrZZZ9vN9aAnJZklNgcDsZ12J3q1hrbRubisRAecjEQMajFYQ1H +rMSI1HuUkJERk1ObD9d6InI9b/9wU5tBI9fW054Tp5uVJwTILezeGr/0dUBkd8OXEar A8xOEAeazmyF7M1Su2kHHUT9XCm5jJFwMtlxtKyIE+q9ykxKIv3OjgSPulZEm0w7Xf0F ECf4CyJzqU5PtGO2XL/g8PjosqYEZdLlyE48bhYBOAqfzoLESAwcXXk0Npq53qdb/pkH bXRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690245648; x=1690850448; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gBxigjkHLT26fx4MKMtaVEtMyHCitliLAz5UQAux20w=; b=JUhnjVdgAY6wX1Xnd/mDHaUbHEMHHn3SNwRYwlGnImlNMV5nJGiJFphtx5fD8Hfdpr 0MJD4tMwX8xiGzMt5ymhR7GSu7nuWkGPBK14whUp2pC2ANV5R8AmTzXYmPYM8t0AgR+V 4sgD2cIa/TbVndFGsJjXvnpO4MMK/f5LQJzR8jf/vnzeu3A1DHrlUd1EZDYNXWX8gx3D FMfpnrvOhcBQfi4DEmOZRTkcNLP1qElnMmxX/UuQBbRSPREJeME8QT7lwN51L7SRcRei NZx7ks5LMVZ0tnwzrbngZg5sinkes27GIhlVgkO4PCNd17+1iM+WBIoHcS1dSijsi/lL 13oA== X-Gm-Message-State: ABy/qLa3NcVVgILfu6EZcJ407+d5j/Moeyn5qvIUTruJjP5lENbHgDB0 Db2NtHURqkzuPyXr+hQoE7HnnQ== X-Received: by 2002:a17:903:1245:b0:1bb:b855:db3c with SMTP id u5-20020a170903124500b001bbb855db3cmr1053335plh.41.1690245648721; Mon, 24 Jul 2023 17:40:48 -0700 (PDT) Received: from sw06.internal.sifive.com ([64.62.193.194]) by smtp.gmail.com with ESMTPSA id be11-20020a170902aa0b00b001b8a3e2c241sm9528297plb.14.2023.07.24.17.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 17:40:48 -0700 (PDT) From: Samuel Holland To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Cc: Emil Renner Berthing , Rob Herring , Frank Rowand , Samuel Holland , Palmer Dabbelt , Paul Walmsley , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v3 2/4] gpio: sifive: Look up IRQs only once during probe Date: Mon, 24 Jul 2023 17:40:40 -0700 Message-Id: <20230725004043.381573-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230725004043.381573-1-samuel.holland@sifive.com> References: <20230725004043.381573-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772352320758637023 X-GMAIL-MSGID: 1772352320758637023 of_irq_count(), or eqivalently platform_irq_count(), simply looks up successively-numbered IRQs until that fails. Since this driver needs to look up each IRQ anyway to get its virq number, use that existing loop to count the IRQs at the same time. The check against SIFIVE_GPIO_MAX functioned as a bounds check for chip->irq_number. That is now handled by the loop condition. Signed-off-by: Samuel Holland --- Changes in v3: - Mention the SIFIVE_GPIO_MAX check in the commit message Changes in v2: - New patch for v2 drivers/gpio/gpio-sifive.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c index db480cd7271a..e96829ac731d 100644 --- a/drivers/gpio/gpio-sifive.c +++ b/drivers/gpio/gpio-sifive.c @@ -186,7 +186,7 @@ static int sifive_gpio_probe(struct platform_device *pdev) struct irq_domain *parent; struct gpio_irq_chip *girq; struct sifive_gpio *chip; - int ret, ngpio, i; + int ret, ngpio; chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); if (!chip) @@ -203,13 +203,6 @@ static int sifive_gpio_probe(struct platform_device *pdev) if (IS_ERR(chip->regs)) return PTR_ERR(chip->regs); - ngpio = of_irq_count(node); - if (ngpio > SIFIVE_GPIO_MAX) { - dev_err(dev, "Too many GPIO interrupts (max=%d)\n", - SIFIVE_GPIO_MAX); - return -ENXIO; - } - irq_parent = of_irq_find_parent(node); if (!irq_parent) { dev_err(dev, "no IRQ parent node\n"); @@ -222,11 +215,11 @@ static int sifive_gpio_probe(struct platform_device *pdev) return -ENODEV; } - for (i = 0; i < ngpio; i++) { - ret = platform_get_irq(pdev, i); + for (ngpio = 0; ngpio < SIFIVE_GPIO_MAX; ngpio++) { + ret = platform_get_irq_optional(pdev, ngpio); if (ret < 0) - return ret; - chip->irq_number[i] = ret; + break; + chip->irq_number[ngpio] = ret; } ret = bgpio_init(&chip->gc, dev, 4, From patchwork Tue Jul 25 00:40:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 125239 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2150262vqg; Mon, 24 Jul 2023 17:55:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlFdpiB++MUIA9M95fP4pkhZIJcYrfa5SgLh0BF6iR43rptPrplS4DdTfdPojpfZGNOyzflO X-Received: by 2002:a17:903:1c7:b0:1b8:28f6:20e6 with SMTP id e7-20020a17090301c700b001b828f620e6mr11375947plh.34.1690246515420; Mon, 24 Jul 2023 17:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690246515; cv=none; d=google.com; s=arc-20160816; b=CCTf8iqcAEGbvnu/0GLhGIQPmUZB3zB6J69MuTXO/rXdV15mx7e5UNF83dbpmkxQD8 uONwor6FCt0qh1iIsEmFAfF6lhwvw6lH1k4YQNevDcettMfkA0JXMM45spSGW9mSwS4/ DutBeufOFHPyXWzZzNTEpOndjkm1s8kKEejMLrFHIKpoP4w+0w4v4bs6DaEeK688Ao3u FrzOgi81YRGliWskA5DLWG3UJocq+CpPWEv+lGT2Rk96yPhMSRELvOFk9kS++3ASt035 W1FficyqpVz4hdrf8wL3wiFPaPI7XM2RbPdfi9e5k2jtjsNupuy+2ddkkAaV9wcyQn6U HXQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AJ4si2ANa5XEPPWMZ9PO8V5jNsPRui14yTgaPNCpuo4=; fh=7Iv+nmknwq0vzuxY/p9xeluMk1WnPOovtl66aotocHY=; b=jYXuQ6ocvrar71FrmVDgAIIxzmA6+T4L2hPq+NdtRBnZ2nqa2779E/DuRd1vPnuUXf OW3PmV+VyU88vMXg7GzO9i5EjKIjiCDzEyM3brnWHPMfMgFoQZyGuEwDmkNUbeeIHDXD CQDh0AOMYMz6ImO1m1lVYP2bHZcXBWhxCNCuOV7vLGGlbmKwgsSnlmUQnD23GsiMXyYD 1wkN1zmjajfyLrtCrUH6zDoCpsSjteSEhR2wDWXh2+nrB3SnXJef+cM0d/eX9+06AIQr aSxsgnFqVQ9DOII05iUP+tdiY/cWbUnzJgfaLrZMzKPp7tOeMf5I7egoTN9W9jS52SZm Ktcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=l4ktA2eQ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kr4-20020a170903080400b001b85a47d2b7si9201304plb.422.2023.07.24.17.55.02; Mon, 24 Jul 2023 17:55:15 -0700 (PDT) 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=@sifive.com header.s=google header.b=l4ktA2eQ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231261AbjGYAk5 (ORCPT + 99 others); Mon, 24 Jul 2023 20:40:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231250AbjGYAkv (ORCPT ); Mon, 24 Jul 2023 20:40:51 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D9D4171E for ; Mon, 24 Jul 2023 17:40:50 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1b8a462e0b0so27916375ad.3 for ; Mon, 24 Jul 2023 17:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1690245650; x=1690850450; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AJ4si2ANa5XEPPWMZ9PO8V5jNsPRui14yTgaPNCpuo4=; b=l4ktA2eQh99fN+gk7I24zvtI+5PZYFbVckqw44nSX4ED6yEtC9WPgWj5ibE5ZKyUpd 5outgAZ4AGtaHnx8CUSLGFBgija0550Es4ZHdCs8hEoL/irxd0ZRYV621oTzrCKiH4bE 2fnRPF9IbVCTjwm4SE6r9zv3iF5VsUOk8IWaBpkPsg0DJw3t+Ge6qZT9QUpQg6FvUPUe reo2RCg7Ig3GbXwa2n6VYb536XSRo4s439LWR8PQECFlFqXZA7XQjQ07atUv8KNXIs0R E3u5LOjPl534zqDpW38rL4wtQgIYV0cqlwZUvUUzWK6R25wjiD0CvPYlIZ7eMADOKDqT XMqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690245650; x=1690850450; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AJ4si2ANa5XEPPWMZ9PO8V5jNsPRui14yTgaPNCpuo4=; b=HG8P+AM0fFlJtyfw41J71sITgzDXfXDMQClHJckbnal4Oscy9NA0OZNTAsxeeW/PJ8 wibOzi0+CfxEhdocTRI4wDr0sHupi8tXRwFTGsx2VjC1IiFjn5cU2pBnvMWHcJ6ZlmBY IeGlyZgFuMni4Gc1wyqVWmw50/BiPv8khJLWtU8zoLKwPo4J6KoVYPBS5SnieI16Kg1Z /QXyniFCVF0hSD/GkdDRSeBOXDuv6XXMYGyzp3aBJ4B8+JOL9MN7bquC9OjpiXbdqdxO HPxlPpMvWb9J0br2JYRBVLR4BY4Hsl/aeEoho1wTioMy+N25gfQDoMGIRB4QV0MvGTaZ +sBQ== X-Gm-Message-State: ABy/qLZL4D5XvdVI9ah0LlcF+hhBMmLye/bR8qfstuz1RuNE8jaCpEUo gkWhFOhToA/334PVS1ox8IAK3A== X-Received: by 2002:a17:902:b083:b0:1b1:9d43:ad4c with SMTP id p3-20020a170902b08300b001b19d43ad4cmr8706634plr.40.1690245649916; Mon, 24 Jul 2023 17:40:49 -0700 (PDT) Received: from sw06.internal.sifive.com ([64.62.193.194]) by smtp.gmail.com with ESMTPSA id be11-20020a170902aa0b00b001b8a3e2c241sm9528297plb.14.2023.07.24.17.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 17:40:49 -0700 (PDT) From: Samuel Holland To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Cc: Emil Renner Berthing , Rob Herring , Frank Rowand , Samuel Holland , Palmer Dabbelt , Paul Walmsley , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v3 3/4] gpio: sifive: Get the parent IRQ's domain from its irq_data Date: Mon, 24 Jul 2023 17:40:41 -0700 Message-Id: <20230725004043.381573-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230725004043.381573-1-samuel.holland@sifive.com> References: <20230725004043.381573-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772351930361959909 X-GMAIL-MSGID: 1772351930361959909 Do not parse the devicetree again when the data is already available from the IRQ subsystem. This follows the example of the ThunderX and X-Gene GPIO drivers. The ngpio check is needed to avoid a possible out-of-bounds read. Signed-off-by: Samuel Holland --- Changes in v3: - Keep the variable for the parent IRQ domain - Add a comment explaining why the IRQ data lookup will succeed Changes in v2: - New patch for v2 drivers/gpio/gpio-sifive.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c index e96829ac731d..3545bc0fad13 100644 --- a/drivers/gpio/gpio-sifive.c +++ b/drivers/gpio/gpio-sifive.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -181,8 +180,6 @@ static const struct regmap_config sifive_gpio_regmap_config = { static int sifive_gpio_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *node = pdev->dev.of_node; - struct device_node *irq_parent; struct irq_domain *parent; struct gpio_irq_chip *girq; struct sifive_gpio *chip; @@ -203,24 +200,22 @@ static int sifive_gpio_probe(struct platform_device *pdev) if (IS_ERR(chip->regs)) return PTR_ERR(chip->regs); - irq_parent = of_irq_find_parent(node); - if (!irq_parent) { - dev_err(dev, "no IRQ parent node\n"); - return -ENODEV; - } - parent = irq_find_host(irq_parent); - of_node_put(irq_parent); - if (!parent) { - dev_err(dev, "no IRQ parent domain\n"); - return -ENODEV; - } - for (ngpio = 0; ngpio < SIFIVE_GPIO_MAX; ngpio++) { ret = platform_get_irq_optional(pdev, ngpio); if (ret < 0) break; chip->irq_number[ngpio] = ret; } + if (!ngpio) { + dev_err(dev, "no IRQ found\n"); + return -ENODEV; + } + + /* + * The check above ensures at least one parent IRQ is valid. + * Assume all parent IRQs belong to the same domain. + */ + parent = irq_get_irq_data(chip->irq_number[0])->domain; ret = bgpio_init(&chip->gc, dev, 4, chip->base + SIFIVE_GPIO_INPUT_VAL, From patchwork Tue Jul 25 00:40:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 125241 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2152519vqg; Mon, 24 Jul 2023 18:01:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlHgXDF7Pj0djPbBUutHjkn0cEJVN6Ebyc9Inp1f0PFODChIrS7j6OTf0nyMCwgYWhvPYOa5 X-Received: by 2002:a17:906:73c1:b0:993:f4cd:34b5 with SMTP id n1-20020a17090673c100b00993f4cd34b5mr11960270ejl.29.1690246872797; Mon, 24 Jul 2023 18:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690246872; cv=none; d=google.com; s=arc-20160816; b=QFXUqQPtb/UKsITPQuw/VdnAQzGu4wNmCt1VVFhlRqygMN7fd/juGKxWziz9UbLh0k +RWT5/aPffJrZXcsfVNgwDjGPrJSlt8MvsFL9iRjodAb+FyxsjPwfuSXCT0+1X0TgLKf mySJhdQi3PKtwsS/IAn2IAS1IgyDKAJMPsmHYy3UZy76yeshSrpwCynJOnchNCIm6TDY iwjYsf+g22m8V4XyL0PFa/nhDMNP00EEO4DhHrkXqUdwGwwgf9vz0fi0+HB95wcfYqlv AHweJg0viw6V20ZLz1bHWzZZ+a+J7Tqhe0DnqL0dbvUfdbjZNc2a9g/3PjwC23lwJGv3 N6bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=d/7J7W9/s0ktyQK4BY9a6mNX04p7bPwNQDg3KLPOfkM=; fh=Y7he24FywPYpaChzO4XlUZSBnpHzoZzgBuTepmA0ePs=; b=mD4Pu3531sN1lkrYTNnaMcnZBG478beTXGJyLMy92l5hF54ag070PnKHfzIK9PBrDe rEXLKLrc2OHKW4wdq+Dufyts0ZY245o+qj/6JaQ4bnQ4cnkTqazgaLO6PTKNadsogT4S L+A5gvUyVYxZOR+FI61JKuzRUfGcNShxqN+FUCaH9FfA3KJIW63/SWluIaIBsc6qTXq3 K9w7cp9QtHXM0xtKgPr+WdJeWVANpVne8zsaB+IxV0Ecwp1MOMdqs/qWywvSAfANTAZq 5T4kRSY16uuASZy0LoRmc39D/OcAfGt3xMgCL3nZwF1RLxKYSbJnnWd+/Di3BBCUtDIb T/kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=P5bkF8Z6; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id op3-20020a170906bce300b00993166137f5si6971476ejb.140.2023.07.24.18.00.48; Mon, 24 Jul 2023 18:01:12 -0700 (PDT) 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=@sifive.com header.s=google header.b=P5bkF8Z6; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231262AbjGYAlB (ORCPT + 99 others); Mon, 24 Jul 2023 20:41:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231260AbjGYAkx (ORCPT ); Mon, 24 Jul 2023 20:40:53 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EC3F1728 for ; Mon, 24 Jul 2023 17:40:51 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-553ad54d3c6so2450595a12.1 for ; Mon, 24 Jul 2023 17:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1690245651; x=1690850451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d/7J7W9/s0ktyQK4BY9a6mNX04p7bPwNQDg3KLPOfkM=; b=P5bkF8Z6mF9jk7ij0sXr0gmtxntUZIEPfvXkrIF5IsH4hLgRx7uXgVHGdw5At7g9qd EENZq1PvE3GQ3V7NfQaS0zxIPvN8X8ucMSct1aL1gpKJdet4RL1Di4ZgSgUPId7oBV9H 2q8aiXT314DQjnF0Fp32oaIGuTNVoR4SOdxUQsSjNcmCqNb+LYM+L099s9dMFdO6FnCS NblA5iwYPRSHpSu4CuxDq/BJR/twkmJM8N00cQr4K87FOhR9jLffcoUTfc237osg2sqQ JvvfkMyM4pB0FOC1Z38yOrvxbqlqzoH/8xa7xdzUZjPxlQeQfZQtfmFs5GvK3j+7AInY WUuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690245651; x=1690850451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d/7J7W9/s0ktyQK4BY9a6mNX04p7bPwNQDg3KLPOfkM=; b=ChiovZFCDZt0t9kWc6f3d4YncbmEwZCn3G14TjHerWvMP1USeJlSL/0Js+GS18CcWn aH4ypGe8b/qjmYf35kvJB6b2jEZnVMKRAyLwHc98IvPvccyOjCwLjxKPDR3ylILtRf5K qgTCRHfFQbA80u0K0l51aYhchBFJWHF4Dq84wItnnwMD6jRF1qHB/JTGmzlxG+n8/+9x Sh3EsX+24bZi07jzkvQ/DTol7pDWRqFpOKUkAkQTYDvpI1vQk5TvsUCzB85Ce3grc62k M+/Bxvli2xLLPhgFleFuB3sHAhglTWceDNDfzUhtIMehziTnzn/RY07jIHDYLUJQ9saA oQHA== X-Gm-Message-State: ABy/qLZ1YgLItmOYe2aTy6k49g29nwHcqD+ZNPWG3uGNUJrk0kFQ3nhi pJo/kdE7F6Jn2bYuYQSkWw9ALw== X-Received: by 2002:a05:6a20:7d86:b0:137:9622:17d0 with SMTP id v6-20020a056a207d8600b00137962217d0mr10548315pzj.58.1690245651000; Mon, 24 Jul 2023 17:40:51 -0700 (PDT) Received: from sw06.internal.sifive.com ([64.62.193.194]) by smtp.gmail.com with ESMTPSA id be11-20020a170902aa0b00b001b8a3e2c241sm9528297plb.14.2023.07.24.17.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 17:40:50 -0700 (PDT) From: Samuel Holland To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko Cc: Emil Renner Berthing , Rob Herring , Frank Rowand , Samuel Holland , Palmer Dabbelt , Palmer Dabbelt , Paul Walmsley , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v3 4/4] gpio: sifive: Allow building the driver as a module Date: Mon, 24 Jul 2023 17:40:42 -0700 Message-Id: <20230725004043.381573-5-samuel.holland@sifive.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230725004043.381573-1-samuel.holland@sifive.com> References: <20230725004043.381573-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772352304867470335 X-GMAIL-MSGID: 1772352304867470335 This can reduce the kernel image size in multiplatform configurations. Acked-by: Palmer Dabbelt Reviewed-by: Andy Shevchenko Signed-off-by: Samuel Holland --- (no changes since v2) Changes in v2: - Add MODULE_AUTHOR and MODULE_DESCRIPTION drivers/gpio/Kconfig | 2 +- drivers/gpio/gpio-sifive.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index e382dfebad7c..1a8e8a8c85d6 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -564,7 +564,7 @@ config GPIO_SAMA5D2_PIOBU maintain their value during backup/self-refresh. config GPIO_SIFIVE - bool "SiFive GPIO support" + tristate "SiFive GPIO support" depends on OF_GPIO select IRQ_DOMAIN_HIERARCHY select GPIO_GENERIC diff --git a/drivers/gpio/gpio-sifive.c b/drivers/gpio/gpio-sifive.c index 3545bc0fad13..bbc58ef0b6de 100644 --- a/drivers/gpio/gpio-sifive.c +++ b/drivers/gpio/gpio-sifive.c @@ -266,4 +266,8 @@ static struct platform_driver sifive_gpio_driver = { .of_match_table = sifive_gpio_match, }, }; -builtin_platform_driver(sifive_gpio_driver) +module_platform_driver(sifive_gpio_driver) + +MODULE_AUTHOR("Yash Shah "); +MODULE_DESCRIPTION("SiFive GPIO driver"); +MODULE_LICENSE("GPL");