From patchwork Thu May 23 05:07:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inochi Amaoto X-Patchwork-Id: 1938171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=3mqAuXYJ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=outlook.com header.i=@outlook.com header.a=rsa-sha256 header.s=selector1 header.b=iDHXa4MZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlGPf2Gskz1ydW for ; Thu, 23 May 2024 15:07:18 +1000 (AEST) 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: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:In-Reply-To:References: List-Owner; bh=bshjUUDp6eNoiP47T4GcVAboeTAQlWfCuG0CCGm+ecI=; b=3mqAuXYJhDqLvn mgug9ZL5uwAPHoweDziEqTDO0S9yJekfYch4tSQfvy8Yq8+3OeMqKflaxz/W+YgGNqMjB6aCGTQJp PEBmRVT/4mzMbgygv/QyETBh0RrlDbknwm20ULvW3XYlOyNswNWlfstSWUyHi/i3aIwLlyQsXo3+5 1oEzgAo576LFGpHn+uo4UNsTgFDAyafH+H8jrgQnJH5cn8kSFBzrkaW0oarVkQozC2eIqomasE46z 91PLrsOxfgd3qSu9dPnd1J0Ks5fsG9Phc4HP3u38AZFJk++xb9QGfyAA058S9iKmEAeTZh3GNuuJs E7ui7VK/6/Dvw0UClKkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA0fW-000000054cE-1fTC; Thu, 23 May 2024 05:07:10 +0000 Received: from mail-dm6nam10olkn2082a.outbound.protection.outlook.com ([2a01:111:f400:7e88::82a] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sA0fT-000000054bG-2C9M for opensbi@lists.infradead.org; Thu, 23 May 2024 05:07:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a/hSsXQWWa5nIOFEzwDp+lxs6ArSSANzUj7mJucVcQ+NeBPMIHB41No26yaIIrSTUsMaK/07AEjbqmxAe0lDa3XQT4YVKLKbOk1FdF/L8lnnemFGNg/9ZMN0604iHAZwp1cwaLfrCUkWehwtstHprQgzuEhxAAdcm//gB3zc6AX6npkRFMcY7hwCMFR1W9vZ43ivopJD0hUyd/PR5lBJWlCcxv8iczLWYTsRVSghebsv4AiZWXR4dB0qJMeAEy1yctti8NXBBHOmO1REMP4uMz/jdDHd17PFhcRP/pbY9qqtXjeHtdrhyN/CU0zIPPaXsiGj120a3CbLfaU3HqBWbQ== 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=eamx8YtDv0N3ZJUEP0YUfQGZC0kAEn2d2WwBbtymJHk=; b=AUABfSGNt/xQwQDcKSMfTkyygqANzk5K5mm3n6Jk79u5/zR7azuGoyMK6sOutGuK8RJWUKLGIP9UCTMA8vyfAJF8qjSYYMY/x3YT36f3HwmjHE1YOChB9lBpEj1KomPsFiUdZ+s9t80CJ3N+5N2NbaB6jyQhvlqBLr9zWFJA49hjahk5CRBEuArejP6VBm3iRs3ylqSxZbN5V6XibEpRFbqCVpGo4Z+0KSwS6BJudo4d/GJIOfObncs0OsZCFhcXGbKd5csnltindBp8g3nkki5+d28nMfOfH58Yh5PX2Cq0rcAJP03DscH8/eWPhEQtma6p9YilQvvUrRdtuSB+Rw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eamx8YtDv0N3ZJUEP0YUfQGZC0kAEn2d2WwBbtymJHk=; b=iDHXa4MZOkNwHxNVCtrAB7gt5xeCROc846GhAsxnVXn2HHU5LdCSwbPv3VMcOGPASZi7o4ucw4rVOyl9b26sHVaoBm6h8zyCRofHgYHez5JAKN1SSAshmg6siMTi6mVjaoDh3WL0k/QrTF/BLRnCTgd/8fvoopZgoadJcecwI/jqFThCJaBgLz2E29C5vTCyjDvmrxYTAPtXc5FxinUNILsQvj/de2cXVyWphW3HDpqrTvRLnaXnTSjZfsvmSD3BuGrUvqudUmuYGvOhEUMVQ4sx1eXSDQ0ULGtgWCf6iG9icFKD8bhNeEWNa2Oq1q93CnroafUAVmsn2M8W/GqNsg== Received: from IA1PR20MB4953.namprd20.prod.outlook.com (2603:10b6:208:3af::19) by PH0PR20MB6206.namprd20.prod.outlook.com (2603:10b6:510:29a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.22; Thu, 23 May 2024 05:07:00 +0000 Received: from IA1PR20MB4953.namprd20.prod.outlook.com ([fe80::182f:841b:6e76:b819]) by IA1PR20MB4953.namprd20.prod.outlook.com ([fe80::182f:841b:6e76:b819%2]) with mapi id 15.20.7587.037; Thu, 23 May 2024 05:07:00 +0000 From: Inochi Amaoto To: Anup Patel , opensbi@lists.infradead.org Cc: Inochi Amaoto Subject: [PATCH v2] lib: utils/gpio: respect flag GPIO_FLAG_ACTIVE_LOW Date: Thu, 23 May 2024 13:07:45 +0800 Message-ID: X-Mailer: git-send-email 2.45.1 X-TMN: [demGMHWpB5WWY1Uw/AUIm+2ePuGCTTkPu0spFlm7IR0=] X-ClientProxiedBy: TYCP286CA0013.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:26c::20) To IA1PR20MB4953.namprd20.prod.outlook.com (2603:10b6:208:3af::19) X-Microsoft-Original-Message-ID: <20240523050745.532564-1-inochiama@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA1PR20MB4953:EE_|PH0PR20MB6206:EE_ X-MS-Office365-Filtering-Correlation-Id: 0665d5a9-bf85-471d-9c76-08dc7ae62d38 X-Microsoft-Antispam: BCL:0;ARA:14566002|461199019|440099019|3412199016|1710799017; X-Microsoft-Antispam-Message-Info: 6jSB1nWNmwgvrAmqoP98dy23UP9ZSJNLJ5WBwQ5xeyWXLW1bTU2b1PFlejkm+xVk8GwAPYzri2GHCPwdcN2CL7XcKMJzM9c+C5N3bEJQV/xasHXnVD/zTNSOHB8cnpN2PRh0+kSrVBuoTL38xo3tTvU3h9/h2eibhq8uZsq+vFd1OFo2b7XiyxUwm1gIPukPnHIa8LY8LYgMAU6I2PmTVqF/adQr+zhzPQlxXesqacTfthlqgrOA1z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wUF/ms6w2c9L5HjV38x7BxXBgZJ+PA1C8HUY8hve1sNt7koMUBS5vh9Yz946+VfGzL0aAC70flPeMSFrgjJl8+1nUwCsclhnGEkAUYoPT7uyNH9HlOfkC3WMSUcv6Gz2qsfbyU3B4nbaJFxiHzXOEo8d/jGq/FixBOkydrZtXU+HAURqbgG0E+PRHv8ksS6aoIhWG+p9jBUzpQRV6gzuEsMmlL1q/2JcKzaT0+Rtyt2pOv90w0dXhTWGlLw9ffK1wWC3MNDBY2Ma9PVcUnpxvCmuN7SKIDSz2dFPlGQ2Xu+tznQ6XUrKh5IyTb9g+OfWeIRrppXJJxJPQqBgs3jIYsYIZu7r9djearXsR7mm3oprY/cBb6yM6YzEF1K31EPgb0JkWR/ti6HlkdDbmMK9ArnAdLREqkWbbdLgi2xfQ5804sTJZ1ftV6+CNwH9S+s4OMAVoB2L0SdOeScNmts+ET+vR+j4TohmIqyvykuhq/Ch+cNQpMmO7nrcw95YaxWOV9HAynQ0x1f6cYuFxeDIWOpJxk4h9Px+VzVPmQbmHavucy6k1lRlIJ0rBAHdMNbyh4NbistIGWuC1Q8oGEEnrKtqOMJGLHms/prtZS5/J2Fd46o+sHqlG9fUQd8oDibWoAO4V X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0665d5a9-bf85-471d-9c76-08dc7ae62d38 X-MS-Exchange-CrossTenant-AuthSource: IA1PR20MB4953.namprd20.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2024 05:07:00.1660 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR20MB6206 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240522_220707_597539_DFBDC0DA X-CRM114-Status: UNSURE ( 9.57 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: "gpio-poweroff" and "gpio-restart" always set gpio to high to active the function, but some chips need a low signal to active. Fortunately, it can be achieved by setting GPIO_FLAG_ACTIVE_LOW for the g [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 ARC_VALID Message has a valid ARC signature 0.0 ARC_SIGNED Message has a ARC signature -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [inochiama(at)outlook.com] X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org "gpio-poweroff" and "gpio-restart" always set gpio to high to active the function, but some chips need a low signal to active. Fortunately, it can be achieved by setting GPIO_FLAG_ACTIVE_LOW for the gpio. Implement this flag support for the gpio library so the gpio reset can function well. Signed-off-by: Inochi Amaoto Reviewed-by: Anup Patel --- Changed from v1: 1. drop unnecessary braces. 2. fix typo in title. --- lib/utils/gpio/gpio.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) -- 2.45.1 diff --git a/lib/utils/gpio/gpio.c b/lib/utils/gpio/gpio.c index 3a3a6b2..6ffe929 100644 --- a/lib/utils/gpio/gpio.c +++ b/lib/utils/gpio/gpio.c @@ -73,17 +73,26 @@ int gpio_direction_output(struct gpio_pin *gp, int value) if (!gp->chip->direction_output) return SBI_ENOSYS; + if (gp->flags & GPIO_FLAG_ACTIVE_LOW) + value = value == 0 ? 1 : 0; + return gp->chip->direction_output(gp, value); } int gpio_get(struct gpio_pin *gp) { + int value; + if (!gp || !gp->chip || (gp->chip->ngpio <= gp->offset)) return SBI_EINVAL; if (!gp->chip->get) return SBI_ENOSYS; - return gp->chip->get(gp); + value = gp->chip->get(gp); + + if (gp->flags & GPIO_FLAG_ACTIVE_LOW) + value = value == 0 ? 1 : 0; + return value; } int gpio_set(struct gpio_pin *gp, int value) @@ -93,6 +102,9 @@ int gpio_set(struct gpio_pin *gp, int value) if (!gp->chip->set) return SBI_ENOSYS; + if (gp->flags & GPIO_FLAG_ACTIVE_LOW) + value = value == 0 ? 1 : 0; + gp->chip->set(gp, value); return 0; }