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 C3E68C7EE29 for ; Tue, 13 Jun 2023 04:50:58 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D1D3A861EB; Tue, 13 Jun 2023 06:50:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (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=1686631856; bh=O21p7CGneoI0+ksAlubeQI81WTPW7qYsuGOpaFvEmGI=; 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=IXbW3uCjlIbd0r2lO8QncNee3o8/w/Tma/HcfsOc8PRhz+uVIc6lRB1G1QcwrS9xK B1WdMNnD4WwtFYfLOUL7xtcU/ZJWKFfp482pJ1e8Qb9fVYZbA8bWQeqakUpHrcinvm cgHBzxsYiIrW/9oIlPm8uRhXtaRmylxkTjgnKU0k86zy5PoQAxXhsbXbaz8q0k8VU/ lLG4qQdXaCs8qwoaZy10wJiM+BdqnePiHTgW2LXXjEYL1XKRv4Ia2Ms/aG7HwQCbQ2 WiKjbCjluEXFnTQwELa3qrqWp67yNIkhIOua5D143DVMBQwwvBiPpDzYow172UV1Vf LS0Q715r4y7bw== Received: from [192.168.1.107] (91-82-26-47.pool.digikabel.hu [91.82.26.47]) (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 D57C980375; Tue, 13 Jun 2023 06:50:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1686631854; bh=O21p7CGneoI0+ksAlubeQI81WTPW7qYsuGOpaFvEmGI=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=XLp4oh1UaZyW3yntSvHFI7JIFJkJFVaYDK37iIE4SnS03J+T0NF4CXQ62TDGQgGxd n8AaAkGyVU5mu2E4+vxda2lORiByueaQ7szLGYQJZdP9BQxLp+HVWlsc6FjAyvZrA7 KluFdnbvXVwXhW+lOJcJG932qTW+y4prLGJZWoC4piKK1qbaXMAU8kzBEVPgDBuqvz F+56Q5wuWJI7cqYbJmZ7G5Mgdq3uYqN44QbVnoER6Ty7i5f4wYjtdGgb0A3rL90Vk1 sQdIyLumlronxzQTnsfBm5JqCYK9ZAMeXUApueaMnj152KmrtNRgqsIAi1pIW9Gp/Q n7G9AVOa+Ev/g== Subject: Re: [RFC PATCH] i2c: mvtwsi: reinitialize controller to clear bus errors To: Sam Edwards , u-boot@lists.denx.de Cc: Stefan Roese References: <20230610061500.119123-1-CFSworks@gmail.com> <1bf44310-1d33-79fd-a116-578c8b5c47ce@denx.de> From: Heiko Schocher Message-ID: Date: Tue, 13 Jun 2023 06:50:52 +0200 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=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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 Hello Sam, On 12.06.23 22:16, Sam Edwards wrote: > Hey there Heiko, > > On 6/12/23 06:35, Heiko Schocher wrote: >> I have not the deep knowledge of this specific i2c driver, but may >> also an option is to set >> >> int (*deblock)(struct udevice *bus); >> >> in >> >> static const struct dm_i2c_ops mvtwsi_i2c_ops = { >> >> for this driver and do there the stuff needed to deblock the bus, >> as you have done in twsi_i2c_reinit() in your patch? > > I'm not sure that this is a good fit. The comment explaining deblock says this is for situations > where "Resetting the I2C master does not help. The only way is to force the bus through a series of > transitions to make sure that all slaves are done with the transaction." > > Which reads to me like it's for situations where some slave is holding down SDA (making it > impossible for us to send a start/stop) and several SCL pulses are required in order to shake it loose. Yes. > In this case, the *bus* is okay and the *master* is upset (ironically, I think, because the Realtek > just did its own "deblock" equivalent), so a master reset is really all that's required here. We > also know the specific state that it runs off to, so it's easy to detect this situation and resolve it. Hm, okay, than I misunderstood the subject line ;-) Just looked into linux code, but have to less knowledge to give you some good hints ... just looked in linux there is in drivers/i2c/busses/i2c-mv64xxx.c mv64xxx_i2c_fsm() default: dev_err(&drv_data->adapter.dev, "mv64xxx_i2c_fsm: Ctlr Error -- state: 0x%x, " "status: 0x%x, addr: 0x%x, flags: 0x%x\n", drv_data->state, status, drv_data->msg->addr, drv_data->msg->flags); drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP; mv64xxx_i2c_hw_init(drv_data); i2c_recover_bus(&drv_data->adapter); drv_data->rc = -EAGAIN; } (No idea how i2c_recover_bus() looks like for your case, as it comes from core code...) But it seems this is for status register reads, which have unknown values... so his part should be called in case status == 0 too... linux driver does also a hw_init in this case and calls deblock ... So similiiar what you planned (beside no deblock) ... May it makes sense to extend your approach (as it is so in linux too) to do this for all "unknown status register values? May its worth if you take some time, to look into linux driver? (If you not already did!) >> Currently this deblock function is only used from i2c core in >> i2c command, but may it makes sense to add in dm_i2c_xfer function in >> >> drivers/i2c/i2c-uclass.c >> >> a call to i2c_deblock() in case bus is blocked? > > I wouldn't object to such a change, but since deblock is an "active" operation that might have side > effects, this probably needs a bigger discussion (beyond what I'm trying to do here) since other > users might be unhappy about this happening without their explicit say-so. Yes, such a patch would have more impact, but may it makes sense, as it would be good if U-Boot self heal a blocked i2c bus, but yes, this needs extensive testing... bye, Heiko -- 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