Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5034520ybl; Tue, 14 Jan 2020 02:21:09 -0800 (PST) X-Google-Smtp-Source: APXvYqyXgLv8mV6/moLPpIgEIz3IZJvnY3i3kyhHgTpbUSa212HBAuXK4z1/cpVOKYW4uqG19Efd X-Received: by 2002:a9d:3e16:: with SMTP id a22mr17552362otd.259.1578997269880; Tue, 14 Jan 2020 02:21:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578997269; cv=none; d=google.com; s=arc-20160816; b=SGGsrSJeTAlsoWRGK25TlyLLsvHmyHNQu/bgmszaXqXs475Z7GROs8PqCin7nWaMay xW6UPSlpxUhGX6lb0IKWzYpohUwZ2c3/EVtTCu8cVT4c5fUBb4evPY9qYBi4tzpJW7yU ya3lUMBSwcKCB2/QxEOPEizIn2yATBd4BrDUfsi9bInQSbjcp3cVUAq2uLlsPa8pAy+z hBCnJ76Dy46MoD2Fi32CKTyH7UZFDBFRvZuaU2VyDOU1FXg8UQ4JyGgfRw+fDCTEhx4F fZJMPVNnNkSQPLJqIZmdIS2YUkudmYJ0y7OhPyQDqBseo4PdxLWf//xZNda8P0OHdvZL TCNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ShAepHnpDt6LWUbvYc1osJnkdRBTfC1xn3IqwHq2Ivc=; b=UIIrOF+orSePriftLdZkHx+FudpuQAJ1leym4HRjZAVE2nQaSFB0mUhvLYoId59H6X MGKyGLnXmquj0n+Nz5Qaeh3yIyQY9NPnfybnPsyDLlGlgkdM/JS9ZIQv6N+HRHvYTIOY PXUPEgY6n/M86ZtjuMEdtt1MsX7MX/l4O34MxhXPdU7LaYX2udUHoh2q1HD4Z3qsuFw+ MkR58GPb+jWX+aeS7Y8CGtGH2EP+xFMuVbyuz03kp1ltiXkIJyHTRbCxWGjLgouTmYTt W46BMIRK5YDqvvTeN43U8kzSxuBw/vppDuOc9F1tBmxjvrczD1aUblhHOOhE0Gb2Mr51 aUtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mY7SGzJ2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2si7734729oig.255.2020.01.14.02.20.59; Tue, 14 Jan 2020 02:21:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mY7SGzJ2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730157AbgANKG6 (ORCPT + 99 others); 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);