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 27259C6FD1D for ; Mon, 20 Mar 2023 07:44:36 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8966985A62; Mon, 20 Mar 2023 08:44:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1679298273; bh=1PBVha1OX2KIVaERatAUJBh0FK3zt2956ET7jqAmBdg=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Reply-To:From; b=MRZv5GQtzGSdOfGCioZnuzsxL83JkCf1Ue2Maxy9d62ll2pmSJq9NjCv4FRvzT4P0 HArAnftun9JoVQlGXnl983a4oZfNv4vH7Nlk5dg51IbtunsiXzeIUi5RytAoa6KdZE OlztGgJ1pzh2bJR2/28IPM11oVknsBHn5WrQDk3N4aSeUhaNOo3/FjwXt+IJXK20zG 788nztySu35ZXyXYwE5G9x5kH5y+EeQJrJj2Qm83Z9Xl8Yegd3innhAt3yngYCMpqo RoU+zP6yZ1x4V7Iyk0quVLz4CZZ+dDkvXNsNHwJDoHRSVaZBe6HVwX5ToxTa3vLOOz qENWZ1jagroTQ== Received: from [192.168.1.107] (91-82-26-67.pool.digikabel.hu [91.82.26.67]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: hs@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 8D3EE85A5F; Mon, 20 Mar 2023 08:44:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1679298271; bh=1PBVha1OX2KIVaERatAUJBh0FK3zt2956ET7jqAmBdg=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=gh1GcRTNnz3sCyxL5Fq2K6GLlphoDAHgOHqdCDHHIOOHzXJR4w3qE1iW0Uqbt0oG/ FVwh67+UH83cpRsISKgQ+ymQmwsJHKmqCFlL4t3wdHa8sNzhCCLBWl8gjPeCUf+Lv3 X3yp/yfuQSdQyZz3oPq2yB+74PuBczhhPvBRIQBJmWraKOQxhyohQXFM7GkMeiDkSm /qe21rcSKGc52OqNXwvhgoxICfXbWB5ggVkQ5A2UBcoTXTuEkfgymXl7lPDS2GbgZC +B5GcXnU1YdOOxkVdaHrzUOF8hn77OdDoSxM+oP9aRnz/e2pbh/DRa66K2MlvNmnv7 KnbHhYruwWdvQ== Subject: Re: [PATCH] i2c: correct I2C deblock logic To: Bough Chen , "al.kochet@gmail.com" , "marex@denx.de" Cc: "u-boot@lists.denx.de" , dl-uboot-imx , "xypron.glpk@gmx.de" , Simon Glass References: <20230210092718.1699222-1-haibo.chen@nxp.com> From: Heiko Schocher Message-ID: <86707c02-d9fb-ed67-5734-9724df15464f@denx.de> Date: Mon, 20 Mar 2023 08:44:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=gbk Content-Language: en-US Content-Transfer-Encoding: 8bit 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: , Reply-To: hs@denx.de 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 13.03.23 03:55, Bough Chen wrote: >> -----Original Message----- >> From: Bough Chen >> Sent: 2023Äê2ÔÂ10ÈÕ 17:27 >> To: hs@denx.de; al.kochet@gmail.com; marex@denx.de >> Cc: u-boot@lists.denx.de; dl-uboot-imx ; >> xypron.glpk@gmx.de; Bough Chen >> Subject: [PATCH] i2c: correct I2C deblock logic >> >> From: Haibo Chen >> >> Current code use dm_gpio_get_value() to get SDA and SCL value, and the value >> depends on the flag GPIOD_ACTIVE_LOW. When toggle SCL to wait slave >> release SDA, the SDA are config as GPIOD_IS_IN, and whether contain the >> GPIOD_ACTIVE_LOW depends on the DTS setting. Usually, for I2C GPIO, we use >> GPIOD_ACTIVE_LOW flag in DTS, so if the SDA is in low level, then >> dm_gpio_get_value() will return 1, current code logic will stop the SCL toggle >> wrongly, cause the I2C deblock not work as expect. >> >> This patch force set the GPIOD_ACTIVE_LOW for both GPIOD_IS_IN and >> GPIOD_IS_OUT, and make the return value of i2c_gpio_get_pin() eaqual to the >> physical voltage logic level. >> > > Hi, > > Any comments for this patch, just a reminder in case you miss it. Indeed, I missed this patch, sorry! Your explanation sounds reasonable to me, but I wonder if nobody tapped into this problem... it would be good to have some test reports from others! Also added Simon, as he did a lot of work in this space. Thanks! bye, Heiko > > Best Regards > Haibo Chen > >> Fixes: aa54192d4a87 ("dm: i2c: implement gpio-based I2C deblock") >> Signed-off-by: Haibo Chen >> --- >> drivers/i2c/i2c-uclass.c | 5 +++-- >> 1 file changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c index >> 8d9a89ed89..4dc707c659 100644 >> --- a/drivers/i2c/i2c-uclass.c >> +++ b/drivers/i2c/i2c-uclass.c >> @@ -505,7 +505,8 @@ uint i2c_get_chip_addr_offset_mask(struct udevice >> *dev) static void i2c_gpio_set_pin(struct gpio_desc *pin, int bit) { >> if (bit) >> - dm_gpio_set_dir_flags(pin, GPIOD_IS_IN); >> + dm_gpio_set_dir_flags(pin, GPIOD_IS_IN | >> + GPIOD_ACTIVE_LOW); >> else >> dm_gpio_set_dir_flags(pin, GPIOD_IS_OUT | >> GPIOD_ACTIVE_LOW | >> @@ -514,7 +515,7 @@ static void i2c_gpio_set_pin(struct gpio_desc *pin, int >> bit) >> >> static int i2c_gpio_get_pin(struct gpio_desc *pin) { >> - return dm_gpio_get_value(pin); >> + return !dm_gpio_get_value(pin); >> } >> >> int i2c_deblock_gpio_loop(struct gpio_desc *sda_pin, >> -- >> 2.34.1 > -- DENX Software Engineering GmbH, Managing Director: Erika Unter HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs@denx.de