From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA50F14A617; Mon, 6 Jan 2025 15:44:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178247; cv=none; b=aNrgMaHAhopVy2I5aMtvxM0HxhpM/sCkBMImWyWPu+OMvHHqXyTgO/HMpR9gkEDbUgfSdHHG/xFTNgH8A/nq1W/TvICAR4JPcwoSYbJMZxixe149zxpvhf8E6yuRZkYK6HHbyiHfWzjqzxTByrXSYRbwuLFX+Zoo9Ge2VHPkBbQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178247; c=relaxed/simple; bh=nyhTCd4Fp7rUA9bSDFIzRR+lULjPJGq9TIjRhJ2XLrY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jxjWdONlu/LlQO9/c+8QO639FIHYvMmfOM1T3Rl+EqB8YqLzik8nZhHvyE+T1KL9gpG3NXmvvKU9uTR/FhJn2WgN8R4nO9qBDWo3yLt0e9BXuSSULg14d9NMSArgXwbGZ0Zac6wNzV/dzvLzOdYd0Ckt9kWnMq1EC5H77Un0v+8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0PBhOwTm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="0PBhOwTm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7363BC4CED2; Mon, 6 Jan 2025 15:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1736178246; bh=nyhTCd4Fp7rUA9bSDFIzRR+lULjPJGq9TIjRhJ2XLrY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0PBhOwTmAKHDNf8D6a5baHih42alMe/16aM0yL8nQ30BhyZ5Yaq11deOdLpnKeMJP vd1Bbv1oSU1W0lxW+WL41rL8i0bRucoM3bPFsx9TcaQJ0DGK5o8Zw+xnXgwcS27ynV Gc/Ew/F9BbhDjlrXnWW1v6TIGXBAJmF0mnxh+VG8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Biju Das , Geert Uytterhoeven , Andi Shyti Subject: [PATCH 5.10 023/138] i2c: riic: Always round-up when calculating bus period Date: Mon, 6 Jan 2025 16:15:47 +0100 Message-ID: <20250106151134.097311095@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106151133.209718681@linuxfoundation.org> References: <20250106151133.209718681@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Geert Uytterhoeven commit de6b43798d9043a7c749a0428dbb02d5fff156e5 upstream. Currently, the RIIC driver may run the I2C bus faster than requested, which may cause subtle failures. E.g. Biju reported a measured bus speed of 450 kHz instead of the expected maximum of 400 kHz on RZ/G2L. The initial calculation of the bus period uses DIV_ROUND_UP(), to make sure the actual bus speed never becomes faster than the requested bus speed. However, the subsequent division-by-two steps do not use round-up, which may lead to a too-small period, hence a too-fast and possible out-of-spec bus speed. E.g. on RZ/Five, requesting a bus speed of 100 resp. 400 kHz will yield too-fast target bus speeds of 100806 resp. 403226 Hz instead of 97656 resp. 390625 Hz. Fix this by using DIV_ROUND_UP() in the subsequent divisions, too. Tested on RZ/A1H, RZ/A2M, and RZ/Five. Fixes: d982d66514192cdb ("i2c: riic: remove clock and frequency restrictions") Reported-by: Biju Das Signed-off-by: Geert Uytterhoeven Cc: # v4.15+ Link: https://lore.kernel.org/r/c59aea77998dfea1b4456c4b33b55ab216fcbf5e.1732284746.git.geert+renesas@glider.be Signed-off-by: Andi Shyti Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/busses/i2c-riic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/i2c/busses/i2c-riic.c +++ b/drivers/i2c/busses/i2c-riic.c @@ -323,7 +323,7 @@ static int riic_init_hw(struct riic_dev if (brl <= (0x1F + 3)) break; - total_ticks /= 2; + total_ticks = DIV_ROUND_UP(total_ticks, 2); rate /= 2; }