From patchwork Mon Jan 17 10:25:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ivan T . Ivanov" X-Patchwork-Id: 12715123 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FF84C433EF for ; Mon, 17 Jan 2022 10:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=vGxG+Cjipm5Ss8hRghVBbQiHApwzg6GEjnSNm7W9R/o=; b=obCpXpGXW+cgQf FdxqNvH+phXz4jGHni8G9nwDVGypsdbZSpxUU0drzZUN7lIgvqHIsGC7WTvTFQ1k8YkAk901njtBK D4rv2t3yll0po6HcX/5qJ40PPZbnRKhEx1ZqCCAKghH5RoGyOqcpSfU8f7AzOdPHyWkZBRxWzPKpL So9sCdkS9bX2+7Xk8geAotPez/kElNJisNxGYApN+X80NOrU2CdQLt8oAfq0NNswE4w8PsTif8aCw HAn3iS5ZAutg4KrQOzhn8JdtkEFgSt+FMiUuY2KM61oQ6RmbTa/FnOoDM/fGlsznaycAGJ6bNNOeU L/OajHa1Sg4M0OXm3s7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9PCx-00EU1l-I8; Mon, 17 Jan 2022 10:25:51 +0000 Received: from smtp-out1.suse.de ([195.135.220.28]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9PCj-00ETxO-SS for linux-arm-kernel@lists.infradead.org; Mon, 17 Jan 2022 10:25:39 +0000 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7E03F2177B; Mon, 17 Jan 2022 10:25:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1642415134; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=3ak0hJKN0gmw+ZumAWA6qKa1PEDQAXtprAK1aYmEKf0=; b=JXbvOFJyA6Ghlj8SEBDNWaroVvUhBUFbZarzKUHCh5iwC8LEeiLoCo+TNPf85rfRz5HvPA yc1TQc6Ucg1KbQYyigCJoeYyYiYmDdSerOFx14arsPAgXSDYab9MrK73pefyqQoLWJ9Amw UkIQxCxmHs/o90xuuWV+9LvID7re7Ho= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1642415134; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=3ak0hJKN0gmw+ZumAWA6qKa1PEDQAXtprAK1aYmEKf0=; b=RgJxEmqtu8GKof5f0G2NcUkAETdKUAowOe96xiPBMeTU6i5ajQGBQOrhRKlLhLHkzNhyJ+ wU/hw0USCoySexBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5FE6D13B4E; Mon, 17 Jan 2022 10:25:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0z4OFx5E5WGEVgAAMHmgww (envelope-from ); Mon, 17 Jan 2022 10:25:34 +0000 From: "Ivan T. Ivanov" To: Florian Fainelli , Ray Jui , Scott Branden , Nicolas Saenz Julienne Cc: linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Phil Elwell , "Ivan T . Ivanov" Subject: [PATCH] i2c: bcm2835: Set clock-stretch timeout to 35ms Date: Mon, 17 Jan 2022 11:25:04 +0100 Message-Id: <20220117102504.90585-1-iivanov@suse.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220117_022538_119620_4EFBB660 X-CRM114-Status: GOOD ( 14.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Phil Elwell The BCM2835 I2C blocks have a register to set the clock-stretch timeout - how long the device is allowed to hold SCL low - in bus cycles. The current driver doesn't write to the register, therefore the default value of 64 cycles is being used for all devices. Set the timeout to the value recommended for SMBus - 35ms. See: https://github.com/raspberrypi/linux/issues/3064 Signed-off-by: Phil Elwell [iivanov@suse.de fix small coding style issue] Signed-off-by: Ivan T. Ivanov --- drivers/i2c/busses/i2c-bcm2835.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/i2c/busses/i2c-bcm2835.c b/drivers/i2c/busses/i2c-bcm2835.c index 37443edbf754..9cce0e15da32 100644 --- a/drivers/i2c/busses/i2c-bcm2835.c +++ b/drivers/i2c/busses/i2c-bcm2835.c @@ -106,6 +106,7 @@ static int clk_bcm2835_i2c_set_rate(struct clk_hw *hw, unsigned long rate, { struct clk_bcm2835_i2c *div = to_clk_bcm2835_i2c(hw); u32 redl, fedl; + u32 clk_tout; u32 divider = clk_bcm2835_i2c_calc_divider(rate, parent_rate); if (divider == -EINVAL) @@ -129,6 +130,17 @@ static int clk_bcm2835_i2c_set_rate(struct clk_hw *hw, unsigned long rate, bcm2835_i2c_writel(div->i2c_dev, BCM2835_I2C_DEL, (fedl << BCM2835_I2C_FEDL_SHIFT) | (redl << BCM2835_I2C_REDL_SHIFT)); + + /* + * Set the clock stretch timeout to the SMBUs-recommended 35ms. + */ + if (rate > 0xffff * 1000 / 35) + clk_tout = 0xffff; + else + clk_tout = 35 * rate / 1000; + + bcm2835_i2c_writel(div->i2c_dev, BCM2835_I2C_CLKT, clk_tout); + return 0; }