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 269B7C6FD1C for ; Thu, 23 Mar 2023 08:43:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AFDBF85925; Thu, 23 Mar 2023 09:43:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="PiEeDVz2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 848E685925; Thu, 23 Mar 2023 09:43:17 +0100 (CET) Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id F389E85925 for ; Thu, 23 Mar 2023 09:43:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=al.kochet@gmail.com Received: by mail-lf1-x129.google.com with SMTP id k37so13770134lfv.0 for ; Thu, 23 Mar 2023 01:43:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679560994; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=wgX6LjIJEAsTb+13VjFGENL6P0LFbqykWjePOKUUPJ8=; b=PiEeDVz2FvYdphoh2b8rCBlAZwrur3u0K3YP5jBkkTyMQs7Mcw13XwzPqekZq5RGH5 aY9+KRIWw0AWPC7pf1ZAoGDvbBSDkkGjGtN+csnIMTOyvpLN9+lpJpKx0/qU1jlQqmkF t7pVpeC79rgobFtnyftgvk5gIzEkoXkS1CouCnEuHN95WWA7p6RAva5cAQXxBZbJlpjL oJEY2QSVCFHrLioUUhPR4cbcqI9RBDuW5kNYmZm4xNuJ/6tIawP98nHelR+DA7OJWl6P 8oY1yfJvJTM/FM5/XzqsaE3S748OY6Kt9OWFSzwBvDOYCeZGasrDvw8GtEHerqeJ6FAK +PKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679560994; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wgX6LjIJEAsTb+13VjFGENL6P0LFbqykWjePOKUUPJ8=; b=29Mdgnkezrp/Mgg1IkR/LdPkk/xCcuRl/JY1gqnajcspBoO/hsx4K/4ROcsXsq1IoW g1tsY1I9pcVhREVsaFy+diBV9dxNCt0VrRstY2OXrAlFBdIKX1A1B0vEZq+Wc6rHd08k G/hA7gf5cY19PUHVjC3bfR892cN21w3+iZHJSJpR9MX2sm453KIvMiZUnbSdDcIJfuNu +pvFEsUPXdl7rvaSdXDkVwKqez8CLfvs42DrPGycBLBAJCZnwuaAQ8VZcgxS/GD5D4aw UwXS2A7c4V/9sTzlgTjl82012xiFpdjvlJm4tDSQAEjnD1Wiolsq41dfUsDBqwTLwRf1 ozNg== X-Gm-Message-State: AO0yUKUjbEemB9ewZ7BW9si5E2sabNvGviPSTLKIbcVC3/mMRC+HHIlt JrkGinNt/IjRGdLUZd9wPCU= X-Google-Smtp-Source: AK7set/E3YJDiDTFHPZpH+MNdrtRyQUQAKUqfgkD0Vv4n6YudBxoYp7XybT9hMfbqk/JhMx7Gd3ZtQ== X-Received: by 2002:a05:6512:401:b0:4ea:e2f8:5edf with SMTP id u1-20020a056512040100b004eae2f85edfmr2876163lfk.33.1679560993889; Thu, 23 Mar 2023 01:43:13 -0700 (PDT) Received: from smtpclient.apple ([80.87.144.137]) by smtp.gmail.com with ESMTPSA id q4-20020ac25104000000b004cb23904bd9sm2847847lfb.144.2023.03.23.01.43.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Mar 2023 01:43:13 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) Subject: Re: [PATCH] i2c: correct I2C deblock logic From: Alexander Kochetkov In-Reply-To: <20230210092718.1699222-1-haibo.chen@nxp.com> Date: Thu, 23 Mar 2023 11:43:01 +0300 Cc: hs@denx.de, marex@denx.de, u-boot@lists.denx.de, dl-uboot-imx , xypron.glpk@gmx.de Content-Transfer-Encoding: quoted-printable Message-Id: References: <20230210092718.1699222-1-haibo.chen@nxp.com> To: Bough Chen X-Mailer: Apple Mail (2.3731.400.51.1.1) 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 Hello Haibo Chen! Setting GPIOD_ACTIVE_LOW has no effect. It filtered out by = dm_gpio_set_dir_flags(). >=20 >=20 > if (bit) > - dm_gpio_set_dir_flags(pin, GPIOD_IS_IN); > + dm_gpio_set_dir_flags(pin, GPIOD_IS_IN | > + GPIOD_ACTIVE_LOW); Here in original code GPIOD_ACTIVE_LOW has not effect. else dm_gpio_set_dir_flags(pin, GPIOD_IS_OUT | GPIOD_ACTIVE_LOW | GPIOD_IS_OUT_ACTIVE); This code actually fix problem with your DTS-settings: > + return !dm_gpio_get_value(pin); Can you debug and check using oscilloscope the code like this: static void i2c_gpio_set_pin(struct gpio_desc *pin, int bit) { ulong flags; ulong active; if (bit) { dm_gpio_set_dir_flags(pin, GPIOD_IS_IN); } else { dm_gpio_get_flags(pin, &flags); active =3D (flags & GPIOD_ACTIVE_LOW) ? GPIOD_IS_OUT_ACTIVE : 0; dm_gpio_set_dir_flags(pin, GPIOD_IS_OUT | active); } } static int i2c_gpio_get_pin(struct gpio_desc *pin) { ulong flags; int value; value =3D dm_gpio_get_value(pin); return (flags & GPIOD_ACTIVE_LOW) ? !value : value; } > 10 =D1=84=D0=B5=D0=B2=D1=80. 2023 =D0=B3., =D0=B2 12:27, = haibo.chen@nxp.com =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0): >=20 > From: Haibo Chen >=20 > 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. >=20 > 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. >=20 > 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(-) >=20 > 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) >=20 > static int i2c_gpio_get_pin(struct gpio_desc *pin) > { > - return dm_gpio_get_value(pin); > + return !dm_gpio_get_value(pin); > } >=20 > int i2c_deblock_gpio_loop(struct gpio_desc *sda_pin, > --=20 > 2.34.1 >=20