Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4299987pxu; Mon, 12 Oct 2020 15:26:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNhdh46XKr89hzzJu09toURzT0NCgt7ljjElkCk8SemO1eSlqg73Ie/yGTm2wRGECDfo9Z X-Received: by 2002:a05:6402:b0e:: with SMTP id bm14mr16615837edb.19.1602541560356; Mon, 12 Oct 2020 15:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602541560; cv=none; d=google.com; s=arc-20160816; b=Clq2ON4UkkJQqEkpad0/haywG7KisHuIfbpqT5W4xcg6GBq3iGPVTxsYp0QNG1Qcbl RHgoVa9f0AKCk3UIUJVYDvuYetQJj4hsUm8w/87Qk9aJREuSGM/EStiE+1Jr99sCzgAT YnJEuRsrnDFA87uY7xefZkXCGrcxa9w6LYZ2OTSIRo/iT563JLpbJMYol+CD3T+a1vjy 42xsYGXZCPbdaI1kGsmBWDqN4mz6w0wW86ItMjsWGXSgwmmQdSJ/+HpUfn2RSHREPVH0 CsoqeiG/+z9Y2nP9+8pbW9d4NzvOkAFvmn33QVjbhv2dy/n3rKBvLnutSuzOvOia9qqA izYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Asee0RJSMVcSkM540VkkW7VhlR86QFChlDLoc4WNUbI=; b=KQFPAauUGi0Idk/kk9vWJS/yljJRzUHAdvN/gXAUu5ycjtbnCxTtiIDWEoO+nyOGgH sWJ5rHqMyH86XMz24qTLb6phuo4pS3LKm1Bu8oXgXMIDVzJg+wRzd8TJ2WDBaFIwwyb0 WAG4+KJCNumnamkbWVrqGRQ0qKobjKyRQnvolcw2VQZolpwCupC4x7pzZiL6YDcvECJP 48FxUa3rdJo5XQaJd6EzB5WvjXaI3tRai1CywMjPiZUNpd9E/VMJA1HOm4jQpxjY1n24 49L8eK6PEYnMjQ2XcPCS2g96xtrIfapXg6uQFpidcESOKoMsAmzcSc03z3NJUgkL96QW KRlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uYzJAMtr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p14si3486538eju.470.2020.10.12.15.25.37; Mon, 12 Oct 2020 15:26:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uYzJAMtr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728801AbgJLNkv (ORCPT + 99 others); Mon, 12 Oct 2020 09:40:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:42708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731311AbgJLNjB (ORCPT ); Mon, 12 Oct 2020 09:39:01 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 09AAA206D9; Mon, 12 Oct 2020 13:38:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602509940; bh=IR3w9cnGCf8ID0rmeiqr6NR5rCMzKtDVMfPQdvg+bgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uYzJAMtraSf28xgqBGMmumPF2P8hMJo/qc4940zVHixSjm7D8pb3UeBWjis48wZWo 0KDtFt9QEFeym+cDAFGOftfaS68EUiEIthFuNjxBnrzZ7cdb+ALK76MKqVv2za1BrK uAi0A25N9AuN3hIMMxXsCQdp/57gftM6b9XP0bgE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolas Belin , Jerome Brunet , Wolfram Sang Subject: [PATCH 4.19 23/49] i2c: meson: fixup rate calculation with filter delay Date: Mon, 12 Oct 2020 15:27:09 +0200 Message-Id: <20201012132630.530478622@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132629.469542486@linuxfoundation.org> References: <20201012132629.469542486@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nicolas Belin commit 1334d3b4e49e35d8912a7c37ffca4c5afb9a0516 upstream. Apparently, 15 cycles of the peripheral clock are used by the controller for sampling and filtering. Because this was not known before, the rate calculation is slightly off. Clean up and fix the calculation taking this filtering delay into account. Fixes: 30021e3707a7 ("i2c: add support for Amlogic Meson I2C controller") Signed-off-by: Nicolas Belin Signed-off-by: Jerome Brunet Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/busses/i2c-meson.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) --- a/drivers/i2c/busses/i2c-meson.c +++ b/drivers/i2c/busses/i2c-meson.c @@ -36,10 +36,8 @@ #define REG_CTRL_ACK_IGNORE BIT(1) #define REG_CTRL_STATUS BIT(2) #define REG_CTRL_ERROR BIT(3) -#define REG_CTRL_CLKDIV_SHIFT 12 -#define REG_CTRL_CLKDIV_MASK GENMASK(21, 12) -#define REG_CTRL_CLKDIVEXT_SHIFT 28 -#define REG_CTRL_CLKDIVEXT_MASK GENMASK(29, 28) +#define REG_CTRL_CLKDIV GENMASK(21, 12) +#define REG_CTRL_CLKDIVEXT GENMASK(29, 28) #define REG_SLV_ADDR GENMASK(7, 0) #define REG_SLV_SDA_FILTER GENMASK(10, 8) @@ -48,6 +46,7 @@ #define REG_SLV_SCL_LOW_EN BIT(28) #define I2C_TIMEOUT_MS 500 +#define FILTER_DELAY 15 enum { TOKEN_END = 0, @@ -142,19 +141,21 @@ static void meson_i2c_set_clk_div(struct unsigned long clk_rate = clk_get_rate(i2c->clk); unsigned int div; - div = DIV_ROUND_UP(clk_rate, freq * i2c->data->div_factor); + div = DIV_ROUND_UP(clk_rate, freq); + div -= FILTER_DELAY; + div = DIV_ROUND_UP(div, i2c->data->div_factor); /* clock divider has 12 bits */ - if (div >= (1 << 12)) { + if (div > GENMASK(11, 0)) { dev_err(i2c->dev, "requested bus frequency too low\n"); - div = (1 << 12) - 1; + div = GENMASK(11, 0); } - meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIV_MASK, - (div & GENMASK(9, 0)) << REG_CTRL_CLKDIV_SHIFT); + meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIV, + FIELD_PREP(REG_CTRL_CLKDIV, div & GENMASK(9, 0))); - meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIVEXT_MASK, - (div >> 10) << REG_CTRL_CLKDIVEXT_SHIFT); + meson_i2c_set_mask(i2c, REG_CTRL, REG_CTRL_CLKDIVEXT, + FIELD_PREP(REG_CTRL_CLKDIVEXT, div >> 10)); /* Disable HIGH/LOW mode */ meson_i2c_set_mask(i2c, REG_SLAVE_ADDR, REG_SLV_SCL_LOW_EN, 0);