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: 13325472 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7A25EEB64DD for ; Tue, 25 Jul 2023 00:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3UBQdloAAZZx23Xbu8R0aXFlXgVCoBY3n302M2e2avY=; b=JPPPP8v2ZbIfYi NpPRjegWgh1gRUQg7mbgQRiVvV40YUd1YIVeOpWEwW2aHDEE8DQHc3aERsrgEc3euJn7sCqxfXDsB 4yYTHzzR1eFOnG6UtwkhH0czagHwZ8DeO1ccVXesOMCVVzDvXzq7HceZUr38y5n/phPlcIRW9mCwT CEHSJRnc+Bdwo4gQtPwCrNGNGEV9OMaruJJvtVLKx+mF+uOCj0+A8rv0wOY1+lLbsJ0AjA7QkMnVl gDqNoRvuyHkf7+zzZBq4rFEFAlaPQ3lUzIJDpKph22jkxA9jE3FiH9T1S/S5x9YbgdER2wc5/Qrvd Ap7lwYCxblo3hhYuZobg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qO66g-005kxW-1B; Tue, 25 Jul 2023 00:40:54 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qO66a-005kup-2w for linux-riscv@lists.infradead.org; Tue, 25 Jul 2023 00:40:51 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1b9e9765f2cso25176455ad.3 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=OEdbFG5jiYCmt7TUMMUJ9TCFP/YT5lZWknAcD/jqwRiFl58yaoRat6x/Fw94a0LWbg uOsNeQr3HPAzPEnz3JJXJ6q5fuErQROu6KwT/mqHaDw9A0tQCz7RTwGESOynhtf/iADg G0jyr8juaKMcfvp0Eq3vnsijTa44zPJVUT1gLrDAMVpYW1oEafw1RIT1OPmve2nBNRq/ ++4wcyMJOy1NiqINOIP/CuaA+mh+q1jV2DyHg1cJw3MiuopMi4bqgVGMIvEHM6qovR92 7PmiumlDwO8LebXEYaSDCn69VwDTd7YnvAFLdqbb2AvlLA3kO/nGqE3LjFwSWuDGHDSd PO2Q== X-Gm-Message-State: ABy/qLZp9o/nYWzrtZ9dDyUSraJkqoZgBO4qRrdLrSs9I1btX1v2bd4o QfcKd6m2aoprmg7FRKK9LN9DQw== X-Google-Smtp-Source: APBJJlGtHTO7CDSyW8ZxxmrwBceXzI8CW1XujT4EsoRt4RpIH7jo6YBL5pbDPxWysOIgsa2tw7yuCw== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_174048_947105_820671B4 X-CRM114-Status: GOOD ( 13.02 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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: 13325470 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44D5AEB64DD for ; Tue, 25 Jul 2023 00:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iJQiHIrVfsWdO1M3e4m7hRsBeu57WkkAJALm7Q6/HRk=; b=EQDzWD5X7FFbsi 50Zo+W71SIhTkBbjB8Qh1rlx9AboD3PYqzkquxRQdx/8rz42i2esJ8IMSTY8zHhfhaH1eXHIBtzMg 2HdJfsTGy25UAjaBYYRQs7oeCbIFpH3bYUbMTThvmArbO9YSN68tjyeRuYtIW1ZEu8X3E+aEIHz7t sEcxIgcrxDSQud0HseBro+9WjwX3kNDzGrJYDxRonqDMgdnpU/bC5W3TjC7HnOiHJrBGsx3QyCinw ee5gv7JCHqvPQE5Zf0NKcRYpj/Ae4SDNKRRsBQHmmIoYDiAy+Jk6NKQ8OkSozB6GoQhT4eBdZc3H1 Kou6HDBATQBTPda4YvVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qO66g-005kxk-2u; Tue, 25 Jul 2023 00:40:54 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qO66c-005kvV-0V for linux-riscv@lists.infradead.org; Tue, 25 Jul 2023 00:40:51 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1bb7b8390e8so11992445ad.2 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=ZyJGrD3PntcOWM66NQdMxOWj5ir8owdcfNcg6XNFQvEGi5gd+g44TDvkbguOdH6Ebk be8RPe/HGdjG4MdA/IPaY5Je1y2FTZPQWQiRQohrUpTCAgIvyrvOl09AZmIIb/lxmAYx IwC6lwcnuO1EfCfA/ZJYlPlExWCNAu33pfnhvTcxEu6ix6f/kki6rcyH7lkkuVOiY85L fMSi4JbT3DKHCjbYjNpJizaYwqZLBQhWkmtSkjxPUrJIAaPJ10snYIVUSNr1tjGOPNmr WXMSJKksXBr/5jtZJA5l/bhtBTOkdsDXx+RbwimmJpPgzgDxOm0Vnv8t8tgSZtHLXpPt iS4A== X-Gm-Message-State: ABy/qLbu6TnLf2pJeoQIZoK0HgvqCnMD6pb8g6QTXky51k5sAuNFLSSt 7lVQbw3S8lLB5eWceaAhn1Jg9A== X-Google-Smtp-Source: APBJJlHktQtCw+j1j8iMYY1ICtRykWLvEpnHmtnMYvGbQrb3fXX3CsElOJGtSObCOKk714nx3RADZA== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_174050_199293_1490DB9F X-CRM114-Status: GOOD ( 15.85 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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: 13325471 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CA147C001B0 for ; Tue, 25 Jul 2023 00:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OshJhhT0ZCr7Kwk9v8kQkHmp/4ba9QXcwc+muC+lmXI=; b=ySFc/DYL3Uul6U 4zIgaLxlhDXtdl92tEdefhyRXgfn3TzEl+ErEkpq7z15ctosLl6sastJK8HPErUTTFfWDIBIxwRoL Q41ukumpb94RptFk921/3lxT3ANYfczpumLZgx1d5Gt/cN/3QufAgvh3BO2yD1IcbH/7+Lgo/ufae O76ogZldTNukf29m6GV+iHrb3imbnRdmy0XMbeQ28+xpVtR3dq5COro3R+nq/MT3Wy+ZE8p02an1p Ct23aSavTDZsQpYldJnDrfEG4szWp0ptoXJFunBR+LRGh9sCqSNeuaY4oFJVAU3tQ0z+I6J2WiAka BCE/BJ6JVsB1QufheBzg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qO66h-005kxz-1X; Tue, 25 Jul 2023 00:40:55 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qO66d-005kvy-1G for linux-riscv@lists.infradead.org; Tue, 25 Jul 2023 00:40:53 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1b8b4748fe4so27991695ad.1 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=TcEm0jk1/LxxUeBGvaL+mFDxzjxu3fT8/roCGcB0uzGLF+UNrECgudtK1Ol+q4VhLi DD1oW420Xp2Ho2oX0tpuhCJIq8lFpb6pDi8CLPi0sK49tA234Vn3oGkpNQOGEBAAC+4Z KpDZKSDxDw147oLkaKiNcPLsNfUMLtS8CLAJzd6jOR+NP2ZsOyg+4NysPukU56PmKf0P l06swqfhus2huyhyW/Lg6lX/KNU59r4B4JOoaH4ZxnMPakSGfsdDzc0hSuF5L4d8FAzW 2n4/Z0Qiti2UhkE9okeovUl0SKXy4My/P4nYty+gZt70xJjslAY9yrLvrPBl/FruWxXo 17mg== X-Gm-Message-State: ABy/qLb3wOKV3k+KNhb5tE0buPrLLpMDdtrSyVsqe7U4OrWOmC4lapif 6QKDVwaabnjJjSXDbRwfdRLbkg== X-Google-Smtp-Source: APBJJlF54q1B8nWOxzcZtLj8JrVNRf6Ffas/NcjytDBVLJF5ZOTC1n+Z+6A9MbTuRw17TV2FuLMY9Q== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_174051_427029_0187505A X-CRM114-Status: GOOD ( 17.05 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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: 13325473 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02FD0C001B0 for ; Tue, 25 Jul 2023 00:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TWG1dcx46CtCATFsdl0WL+Hi30JGs+A5YJUJXpRSe9g=; b=gl7eCIJrBrl4KF +PYwr4fSRfDw+7j/GAVKRm3/o+AkthO4tfjZRiV/XEOY4xDwcTxMbeb8fVHSmt8Z4O42Xqq8HovIn g5Wgeu4hxGU06xbukxxfCwk13s/tGHPLvKjRcbbqVn3Muhch/GI5v/AgAAn3cARVELMWe1USgDmDs lYoV8GC+CkMMLBAEghs/yii6CkwrBoIp0aPYV2Hfk+a0lMgCryBpPJW0IcTPHEcvZmGwqU1WLHBcv x+MlrAjGwScqSf57En/oP5Py1SGXiumXOuubx9NiSBHxH9oqL7eUt0IXdyfrQg9LhBkIF36g/z6Ic vHB8bsTD+aA7HeWBDbIw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qO66i-005kyU-07; Tue, 25 Jul 2023 00:40:56 +0000 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qO66e-005kw7-09 for linux-riscv@lists.infradead.org; Tue, 25 Jul 2023 00:40:53 +0000 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-56372a369d3so2335167a12.2 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=Ev4oy9Hmv4aEbHM6ebLxM3JNIzqaAXpOMfICr8uI4U5zN+qGjJfs7dCqqPvfkl8Z4i ygYjxEDyoRv2JATNjBg0BBnPRu9jKFmcD/CCC3+Gc85dHOb2vHcXKS59uhkV6yqm3OC3 0zIUaViU+12EFCSCCXalBQuFFxYXcdzat+nP66agpEQOtTiswaYvNRg76w456Cv0FjNi d51q7Nfgig9jPdo39tEjxavcqJQMBguAajH90rw6I6nyzXXnCfgMEyfcZ/0KmzSzW0Ok 1NZSI50LD+A+elvvKgTaZOiCrhR9FqE9kQ4iCNESi7UN3JVrpZgejt/3FK2cMzsfG+yq aSbQ== X-Gm-Message-State: ABy/qLbmj5zlIKJxO2bmS1yHzUTaI4V6CTXve9blapZf6mIHLmEjZ0E5 Yd7hSqcpTiobx6kz2VS3Ujtyqw== X-Google-Smtp-Source: APBJJlEPq4iZZyiipTRgAqIyXg56eqA2/VJM2xXD73NNrvuCdDF9GyOVyXgg+dj8FpJWzMor2BH8OA== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_174052_088523_E65D90A7 X-CRM114-Status: GOOD ( 12.30 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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");