Message ID | 20230224192021.22591-1-asmaa@nvidia.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1106174wrd; Fri, 24 Feb 2023 11:38:15 -0800 (PST) X-Google-Smtp-Source: AK7set/BWwm48BJcWpMvDZZJSX6/f9GYiBWHnIJxGRu8r5VDvsgzYNQPQI+P8iX1f4FooVd9LKtV X-Received: by 2002:a17:907:3e26:b0:8e7:7da:421b with SMTP id hp38-20020a1709073e2600b008e707da421bmr1057562ejc.6.1677267494982; Fri, 24 Feb 2023 11:38:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1677267494; cv=pass; d=google.com; s=arc-20160816; b=dH3YxqZe8ZkXOz7etYQeeA2vH563t6w60XMbhN5wjzcIyAfA24l110fNif3AQ27eta OqXKnrv71bg2rY0yanzspU5nKmXd4ZiFLmw2rYXyqwPl1X6k9I3+ZR4q/oc8JP52YWwJ XxoR2TezUqS43Zzhi9/CVOJn2TUWNDBfDpw8VVIPT85V0nR4IhlG7O6HK1GlNZ2Mf1Cv 33DEgSsTIQTF3/csSpzU4MhgqZlEdjrzHCJ1fWBSWXtCCGPg3ptByMHeQVT2G0FQPRXE VrjbCwgnL4yyuHPTiT/KXWPZ55xOfvxmRm6ikc8/M5fDyMkmKVHNDNwlfFDZXR+5IH10 Tjfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9HYmUjtadAdO2hXTJllHHg25Wljp1srnA0w9FCDso4g=; b=pzwszMBmmB4ANYOVjVWE732z07IptyTMj9zxq4S908RSVnNoWC9mSIwwwdt6F5wCGR WOkPSnHKAFpRXBTcGz/d/ZLS6q68g482gxDLlF1g22nGeD4Jf8v0PEKd/pAuMNYqNK2I TLskakOKhd2sN0FkK4ethWQaapOYVH/p8nybxUz1eYxaeJet1q7brqhQ45eHE/oJbCNM INcBf/QkxJWXA55rwkzVz0umWXWIP2YgrMt4W7mcPYpiZz/aTtJOBGf9AkeyhunoITxa 7Br2POO+BHZ4GEzLP21jpQnZjZu3UHjUSzLHYr1z2uN1/vKZNj2k/FnvQ8sNsB77joLP 5KPA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=cBZP1j6M; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); 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=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n9-20020a17090673c900b008e416a5f368si12354102ejl.349.2023.02.24.11.37.50; Fri, 24 Feb 2023 11:38:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=cBZP1j6M; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); 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=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbjBXTUo (ORCPT <rfc822;jeff.pang.chn@gmail.com> + 99 others); Fri, 24 Feb 2023 14:20:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbjBXTUl (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 24 Feb 2023 14:20:41 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11hn2245.outbound.protection.outlook.com [52.100.172.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EE5363DDA; Fri, 24 Feb 2023 11:20:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lLqNRE93R9QUOzgROc4IojZVb5I3OBrRhp7WURUDRk9dl3FKLBKNmEkfpo5eKM6bh9hG78YzU/GgcBERPos1zOOqmKjEH17+/bHJcc0BJN9l8fcXqDeQqZWSoqaTieHN/XjFPblHq60CrKaJWpAvn54WCjMKe54VXFq/U69Hw4/Cqk7ePyitehCjHQ1h3AH4sS0D3F8AUzLfSh+ccVvuDLXhm3POGXvNvE0muabhzPYB+MeTKCfJZ3lI/tBcwS9cyEgS5TaCeL7DLpi++k8oe9PQWd+aNbYmmCVmuZ6fnYSr4j8u7k4Ij6f/ksuNLTTXy7Ca/iZSqiGMULrt+Bi+Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9HYmUjtadAdO2hXTJllHHg25Wljp1srnA0w9FCDso4g=; b=Cvr7FKt0BSzaE2y0TyXQl9Jqub1ua0BW+H7w+lV0tEW20RVpZDxBfnJ2HbOkHZugK8ed27FsgTy5SF+Lge8GhNZlN+xW+QxPoKGF26yg7vgq/9dxab+hJBllBk3ym388YVwVLnFXP9u6mK8Hzq47qlW4NN9p6AusVg8CKGfg3m5rpFxXk1ctLyo7dw0OjSqTJCTEgxjEQaDqyVsIHMsPPbvASGHNK0OPYXc413GtxfcC14h8Qid/5NXFJ45eMEFVnm05FORcvVi5EUPOpN3FAoo9wQgoSWkLJzxN+TR0riDz0Yk2X52MxQshinFsA5KD/KDsVB5Jr7TTkvWv9mI/dw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=gmail.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9HYmUjtadAdO2hXTJllHHg25Wljp1srnA0w9FCDso4g=; b=cBZP1j6MgLydTFfaa9DYiuUGtNEOKZd5a8hyg/hhN3YvZKrGFVtAF+WNGyWiwnKEX+MnusrtzmHGm3prkS3xG8M32Ugf+dxi6J48uTgcBJvx73A8jfnnuzyPDaIdGlyYpRbbff6Cwy5jttb2eEhT319w8HEjhwHEpJXiKN3T96AQQxLX5cTmnN9+D8ZrFdzUS1KDbQDtFSyQRJCQfH2/8ZpiW8FpeSk1i1nIfA11j4sRtRkwL7Cu5dUzeCJv/qJDi6V3TiqG7WeuPm34wn58ZbS5MJovujNpuBI718DLOVCoYoQ7GbqMSE62tAm03y/Tpedpu4DasnbQGSCFsQld8A== Received: from DM6PR03CA0010.namprd03.prod.outlook.com (2603:10b6:5:40::23) by BN9PR12MB5337.namprd12.prod.outlook.com (2603:10b6:408:102::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.24; Fri, 24 Feb 2023 19:20:34 +0000 Received: from DM6NAM11FT108.eop-nam11.prod.protection.outlook.com (2603:10b6:5:40:cafe::46) by DM6PR03CA0010.outlook.office365.com (2603:10b6:5:40::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.24 via Frontend Transport; Fri, 24 Feb 2023 19:20:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by DM6NAM11FT108.mail.protection.outlook.com (10.13.172.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.24 via Frontend Transport; Fri, 24 Feb 2023 19:20:33 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Fri, 24 Feb 2023 11:20:25 -0800 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Fri, 24 Feb 2023 11:20:24 -0800 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.36 via Frontend Transport; Fri, 24 Feb 2023 11:20:23 -0800 From: Asmaa Mnebhi <asmaa@nvidia.com> To: <andy.shevchenko@gmail.com>, <linus.walleij@linaro.org>, <linux-gpio@vger.kernel.org>, <linux-kernel@vger.kernel.org> CC: Asmaa Mnebhi <asmaa@nvidia.com> Subject: [PATCH v2] gpio: mmio: handle "ngpios" properly in bgpio_init() Date: Fri, 24 Feb 2023 14:20:21 -0500 Message-ID: <20230224192021.22591-1-asmaa@nvidia.com> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT108:EE_|BN9PR12MB5337:EE_ X-MS-Office365-Filtering-Correlation-Id: d908838a-c322-44e5-6b41-08db169c337f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: atrnj6Z+TzTn0X3W8k5bucD8MVB/UodaKcaeuEPbju17CAVqyvxaFbMV8OSQpXeqOjxYKjdjN8osWnj60ccMSSgSOC80feZtJ+eunbW28URCDnneUmwWJDOvVpBCooKiEJSRrcXDOKuE8WTZoN9WOwoCKUAclp14h5AIpgczuMseKOntW4lsFfp9Q5XkGsClfEuCg4iYIQrRbXZI9U/x1yaILCccIOHxrAWL/iTzhvIihu6yl/UFY84qVlXxFrLFrwVJtPFMhE73zraD66aF0yQV2d9U5dwN5Yeygx5cD7OZHM9m3PCpBEc4Lymo464tBUjXCIv58IMZLXx1uXm5WXB4oBfyuBcgwOM+bgpQ8tMTHRNlX7Y1+JpLc1HdBAqPjHvqt5wo7z0A631SBiRhouXWhfg+TXZUvKcio63fiNHTlv99aAfgQim3SM13ChbpNkUGEEp37Qbz8jN2zgPCEYejuZJtajxt/j2NCG7M1ZyEfDjvXdoxtHb8vOJCOgevwO7RmxhStreNzzEDrIcvA47kPxS34mSo7rDUpZ8VfdQ6j5PARzmLovn+gf4b6+hJp+X6po+UbdgcJ9bH5Mj1A5jPuCex/6/DdDigJ0jEKaQytxOFwU+YQPrk52bwPmhnknswZdF1yNAswutgo0acupYgszPrpBCFeIhos30dOJmQ/PSXDraewUuam0xRh2ch0pc+Zpzrsb6BPfRZ6L5DqsCcRke0TYmsibTFpm1fECYzRWKhQTESe8eApEvUt16Tz54UcNnhtDZ3UQnLC0FP3w== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230025)(4636009)(136003)(39860400002)(346002)(376002)(396003)(5400799012)(451199018)(36840700001)(46966006)(40470700004)(4744005)(86362001)(36756003)(8936002)(41300700001)(5660300002)(2906002)(34020700004)(82740400003)(83380400001)(36860700001)(7636003)(356005)(110136005)(478600001)(70586007)(70206006)(7696005)(40480700001)(186003)(40460700003)(26005)(82310400005)(8676002)(336012)(2616005)(316002)(4326008)(1076003)(107886003)(47076005)(426003)(2101003)(12100799015);DIR:OUT;SFP:1501; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2023 19:20:33.6348 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d908838a-c322-44e5-6b41-08db169c337f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT108.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5337 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758742440956165534?= X-GMAIL-MSGID: =?utf-8?q?1758742440956165534?= |
Series |
[v2] gpio: mmio: handle "ngpios" properly in bgpio_init()
|
|
Commit Message
Asmaa Mnebhi
Feb. 24, 2023, 7:20 p.m. UTC
bgpio_init() uses "sz" argument to populate ngpio, which is not
accurate. Instead, read the "ngpios" property from the DT and if it
doesn't exist, use the "sz" argument. With this change, drivers no
longer need to overwrite the ngpio variable after calling bgpio_init.
Signed-off-by: Asmaa Mnebhi <asmaa@nvidia.com>
---
drivers/gpio/gpio-mmio.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Comments
On Fri, Feb 24, 2023 at 9:20 PM Asmaa Mnebhi <asmaa@nvidia.com> wrote: > > bgpio_init() uses "sz" argument to populate ngpio, which is not > accurate. Instead, read the "ngpios" property from the DT and if it > doesn't exist, use the "sz" argument. With this change, drivers no > longer need to overwrite the ngpio variable after calling bgpio_init. ... > + ret = device_property_present(dev, "ngpios"); > + if (!ret) ret is not of the correct type for this call. Why not simply if (!device_property_present(dev, "ngpios")) > + gc->ngpio = gc->bgpio_bits; ... The problem with this change is that you need to provide bgpio_bits. So, if there is a property when bgpio_bits will be updated? That's said what you need is something like this: 1) split "ngpios" handling code (lines ~718-744 in gpiolib.c) into a helper function that is available inside drivers/gpio; 2) use it in bgpio_init() by overriding bgpio_bits. ret = new_helper(); if (ret) gc->bgpio_bits = sz * 8; else ... = gc->ngpio;
> > bgpio_init() uses "sz" argument to populate ngpio, which is not > > accurate. Instead, read the "ngpios" property from the DT and if it > > doesn't exist, use the "sz" argument. With this change, drivers no > > longer need to overwrite the ngpio variable after calling bgpio_init. > > ... > > > + ret = device_property_present(dev, "ngpios"); > > + if (!ret) > > ret is not of the correct type for this call. > > Why not simply > > if (!device_property_present(dev, "ngpios")) > > > + gc->ngpio = gc->bgpio_bits; > > ... > > The problem with this change is that you need to provide bgpio_bits. > > So, if there is a property when bgpio_bits will be updated? > > That's said what you need is something like this: > 1) split "ngpios" handling code (lines ~718-744 in gpiolib.c) into a helper > function that is available inside drivers/gpio; > 2) use it in bgpio_init() by overriding bgpio_bits. > > ret = new_helper(); > if (ret) > gc->bgpio_bits = sz * 8; > else > ... = gc->ngpio; So this new_helper() which reads the ngpios property, would be called from bgpio_init() and From gpiochip_add_data_with_key() correct? Since there are some drivers that don’t use bgpio_init(). Also, shouldn't "gc->bgpio_bits = = sz * 8;" be independent of new_helper() function? "bgpio_bits" is described as "number of register bits used for a generic GPIO i.e. <register width> * 8" which seems different from "ngpio" described as "the number of GPIOs handled by this controller"
Fri, Feb 24, 2023 at 09:31:23PM +0000, Asmaa Mnebhi kirjoitti: ... > > The problem with this change is that you need to provide bgpio_bits. > > > > So, if there is a property when bgpio_bits will be updated? > > > > That's said what you need is something like this: > > 1) split "ngpios" handling code (lines ~718-744 in gpiolib.c) into a helper > > function that is available inside drivers/gpio; > > 2) use it in bgpio_init() by overriding bgpio_bits. > > > > ret = new_helper(); > > if (ret) > > gc->bgpio_bits = sz * 8; > > else > > ... = gc->ngpio; > > So this new_helper() which reads the ngpios property, would be called from > bgpio_init() and From gpiochip_add_data_with_key() correct? Since there are > some drivers that don’t use bgpio_init(). Correct. > Also, shouldn't "gc->bgpio_bits = = sz * 8;" be independent of new_helper() Nope. You need to link them anyway. > function? "bgpio_bits" is described as "number of register bits used for a > generic GPIO i.e. <register width> * 8" which seems different from "ngpio" > described as "the number of GPIOs handled by this controller" But you are right, this should be = round_up(gc->ngpio, 8); to match the logic with sz.
diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c index d9dff3dc92ae..448fefc4468c 100644 --- a/drivers/gpio/gpio-mmio.c +++ b/drivers/gpio/gpio-mmio.c @@ -614,10 +614,13 @@ int bgpio_init(struct gpio_chip *gc, struct device *dev, gc->parent = dev; gc->label = dev_name(dev); gc->base = -1; - gc->ngpio = gc->bgpio_bits; gc->request = bgpio_request; gc->be_bits = !!(flags & BGPIOF_BIG_ENDIAN); + ret = device_property_present(dev, "ngpios"); + if (!ret) + gc->ngpio = gc->bgpio_bits; + ret = bgpio_setup_io(gc, dat, set, clr, flags); if (ret) return ret;