From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A49CC33CB6 for ; Tue, 14 Jan 2020 10:07:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 10DCF24681 for ; Tue, 14 Jan 2020 10:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578996420; bh=OXyqQH10ZLVxHbYwnykAef1fBUxIFazmjrSJQ9tTu9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=EsUM141E69NQRoVPJNvZRqUHHSGZvVr4PJgNhCpUug4QXHgqi2iR4nT50y8IXi6DW H4IyUAJ0wxdUuqtfdC7kel+N41NWB7dX96euaityRf+dxdDvXqC+31FaN8ATjI4gf1 XQR34I9V1e4dDOpdPCXX7BVyZOgNRkOk042yoBCI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730540AbgANKG6 (ORCPT ); Tue, 14 Jan 2020 05:06:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:36540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729503AbgANKG5 (ORCPT ); Tue, 14 Jan 2020 05:06:57 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 854D124679; Tue, 14 Jan 2020 10:06:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578996417; bh=OXyqQH10ZLVxHbYwnykAef1fBUxIFazmjrSJQ9tTu9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mY7SGzJ2EvH8Ma/rs2tNhZXQDy09+mso+jaCXdWGOkkU498sG7su/RDJqlyzADiWF YD5Kdd6nNjFS0S5sXycNTIZCNWoPks4mXZTF2ZhKJQ7t4of86s+4vCarW6rkBXVAsv p7pdBBXcJEvDVXgKRimUyGcF++x1BqqDqbNNBe1I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Russell King , Wolfram Sang Subject: [PATCH 4.19 02/46] i2c: fix bus recovery stop mode timing Date: Tue, 14 Jan 2020 11:01:19 +0100 Message-Id: <20200114094340.919318891@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114094339.608068818@linuxfoundation.org> References: <20200114094339.608068818@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Russell King commit cf8ce8b80f8bf9669f6ec4e71e16668430febdac upstream. The I2C specification states that tsu:sto for standard mode timing must be at minimum 4us. Pictographically, this is: SCL: ____/~~~~~~~~~ SDA: _________/~~~~ ->| |<- 4us minimum We are currently waiting 2.5us between asserting SCL and SDA, which is in violation of the standard. Adjust the timings to ensure that we meet what is stipulated as the minimum timings to ensure that all devices correctly interpret the STOP bus transition. This is more important than trying to generate a square wave with even duty cycle. Signed-off-by: Russell King Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/i2c-core-base.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -194,10 +194,11 @@ int i2c_generic_scl_recovery(struct i2c_ * If we can set SDA, we will always create a STOP to ensure additional * pulses will do no harm. This is achieved by letting SDA follow SCL * half a cycle later. Check the 'incomplete_write_byte' fault injector - * for details. + * for details. Note that we must honour tsu:sto, 4us, but lets use 5us + * here for simplicity. */ bri->set_scl(adap, scl); - ndelay(RECOVERY_NDELAY / 2); + ndelay(RECOVERY_NDELAY); if (bri->set_sda) bri->set_sda(adap, scl); ndelay(RECOVERY_NDELAY / 2); @@ -219,7 +220,13 @@ int i2c_generic_scl_recovery(struct i2c_ scl = !scl; bri->set_scl(adap, scl); /* Creating STOP again, see above */ - ndelay(RECOVERY_NDELAY / 2); + if (scl) { + /* Honour minimum tsu:sto */ + ndelay(RECOVERY_NDELAY); + } else { + /* Honour minimum tf and thd:dat */ + ndelay(RECOVERY_NDELAY / 2); + } if (bri->set_sda) bri->set_sda(adap, scl); ndelay(RECOVERY_NDELAY / 2);