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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4696FC76196 for ; Wed, 22 Mar 2023 19:11:09 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2094B85D98; Wed, 22 Mar 2023 20:11:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="bt0qlHGf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1E59285D80; Wed, 22 Mar 2023 20:11:03 +0100 (CET) Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4A0B385D97 for ; Wed, 22 Mar 2023 20:10:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=14459b5c7f=patrick.delaunay@foss.st.com Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32MGB5Ws012836; Wed, 22 Mar 2023 20:10:53 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=37QHHAUAxVH3WefiMHTP9J15l4EOf9+wGnhW96IHA4o=; b=bt0qlHGf5wXJXmqTHjFJIWIDsQAYBX+ThiR4CDilgVIBn0CFK/ExkBLlVuSA0O9T5Vjv qRu6nZsfhJM54IXICc2t65xOeYpIZo4UM1Sm1bHQXyz91tfL3K9QjVtzGaTRDuedrlRb tIf78NZevGqonwqiEbLXgeStXVUx5beBUdG4YLi+5r4JBwwbWeS4124spefIy96ZM4hV 2+FCsRXpxYwR+t4Xn4m7ygdU9IF8mDL38umhtYxos6IuaT518a/82jaBaG5HUYiDrAnS kgI1a/72qdWd/bv/kXolIIlbh9Rx4ngwR+Zz2AfAMmWg0Yb1bPXlNZzx/4INdya//5CZ 8w== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3pfajsk8wc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 22 Mar 2023 20:10:53 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7E64F10002A; Wed, 22 Mar 2023 20:10:50 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 8069B2207BF; Wed, 22 Mar 2023 20:10:50 +0100 (CET) Received: from [10.48.0.157] (10.48.0.157) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Wed, 22 Mar 2023 20:10:50 +0100 Message-ID: Date: Wed, 22 Mar 2023 20:10:49 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH] gpio: add GPIOD_ACTIVE_LOW into GPIOD_MASK_DIR Content-Language: en-US To: , , , , , , , CC: , References: <20230322112604.33232-1-haibo.chen@nxp.com> From: Patrick DELAUNAY In-Reply-To: <20230322112604.33232-1-haibo.chen@nxp.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.48.0.157] X-ClientProxiedBy: SHFCAS1NODE1.st.com (10.75.129.72) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-22_15,2023-03-22_01,2023-02-09_01 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Hi On 3/22/23 12:26, haibo.chen@nxp.com wrote: > From: Haibo Chen > > dm_gpio_set_dir_flags() will clear GPIOD_MASK_DIR and set new flags. > But there are cases like i2c_deblock_gpio_loop() will do like this: > > -first conifg GPIO(SDA) output with GPIOD_ACTIVE_LOW > dm_gpio_set_dir_flags(pin, GPIOD_IS_OUT | > GPIOD_ACTIVE_LOW | > GPIOD_IS_OUT_ACTIVE); > > -then config GPIO input > dm_gpio_set_dir_flags(pin, GPIOD_IS_IN); > > -then get the GPIO input value: > dm_gpio_get_value(pin); > > When config the GPIO input, only set GPIOD_IS_IN, but unfortunately > since the previous GPIOD_ACTIVE_LOW is not cleared, still keep in > flags, make the value from dm_gpio_get_value() not logic correct. > > So add GPIOD_ACTIVE_LOW into GPIOD_MASK_DIR to avoid this issue. > > Signed-off-by: Haibo Chen > --- > include/asm-generic/gpio.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h > index dd0bdf2315..903b237aac 100644 > --- a/include/asm-generic/gpio.h > +++ b/include/asm-generic/gpio.h > @@ -131,7 +131,7 @@ struct gpio_desc { > > /* Flags for updating the above */ > #define GPIOD_MASK_DIR (GPIOD_IS_OUT | GPIOD_IS_IN | \ > - GPIOD_IS_OUT_ACTIVE) > + GPIOD_IS_OUT_ACTIVE | GPIOD_ACTIVE_LOW) > #define GPIOD_MASK_DSTYPE (GPIOD_OPEN_DRAIN | GPIOD_OPEN_SOURCE) > #define GPIOD_MASK_PULL (GPIOD_PULL_UP | GPIOD_PULL_DOWN) > I think you are breaking the management of GPIOD_ACTIVE_LOW, provided by device tree in the GPIO uclass: because the modified GPIOD_MASK_DIR is used in other location.... normally GPIOD_ACTIVE_LOW is saved in desc->flags it is the "desciptor flags" and must be not cleary by normal API see gpio_xlate_offs_flags() => gpio_flags_xlate() For example inĀ  gpio_request_tail(), in the line: /* Keep any direction flags provided by the devicetree */ ret = dm_gpio_set_dir_flags(desc, flags | (desc->flags& GPIOD_MASK_DIR)); With your patch the descriptor flags is cleared / so DT information is lost. For me GPIOD_ACTIVE_LOW must be managed carefully to avoid side effect. and if you inverse the PIN logical in device tree (GPIOD_ACTIVE_LOW) it is normal to inverse it for INPUT and OUTPUT it is managed in GPIO U-Class => dm_gpio_set_dir_flagsshould not cleared this flag GPIOD_ACTIVE_LOW you can change the caller ? static void i2c_gpio_set_pin(struct gpio_desc *pin, int bit) { if (bit) dm_gpio_set_dir_flags(pin, GPIOD_IS_IN); else dm_gpio_set_dir_flags(pin, GPIOD_IS_OUT | GPIOD_ACTIVE_LOW | GPIOD_IS_OUT_ACTIVE); } => static void i2c_gpio_set_pin(struct gpio_desc *pin, int bit) { if (bit) dm_gpio_set_dir_flags(pin, GPIOD_IS_IN); else dm_gpio_set_dir_flags(pin, GPIOD_IS_OUT); } The output value is the same => GPIOD_ACTIVE_LOW and GPIOD_IS_OUT_ACTIVE not active but you don't need to modify GPIOD_ACTIVE_LOW outside the GPIO uclass. Patrick