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 9669F1DED57; Mon, 6 Jan 2025 15:49:39 +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=1736178579; cv=none; b=EiM6nSG1+ZzcdOgOVq3Re7SBSpqryKujGE+xT1LMnO3CPajrBKugqzHMmZzYT78Y081cqUtzeIzAsofdt8P0xT8Yp1/2auM99paSWPGnVoc4EsbNkkaaDt93k+JMXoDuXEEwNBAOezNUp2RDjAVtg9us0SlxSvytZn83EKhFMK4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736178579; c=relaxed/simple; bh=MV8t8FWpLPU8UzzWWIqW1THBHpe4etqf9q5hpRVNqyE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mb8R6zBwPg0ZZ79ju+qyz0MnsNzMxdDKIUpzV1NnRcKNXWUa1STzwhIS2DshfJlvUKlfkSQj1i7YKIKt1uxwlBTTgP1MSxYzicXvr22P1yeQflROrxi1J7TOXKkwZBZYJKdSASrjIXtEHGmzLC5Pf8we6A2we2NgLfAd3n0TJMw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NMaPePsy; 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="NMaPePsy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C651C4CED2; Mon, 6 Jan 2025 15:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1736178579; bh=MV8t8FWpLPU8UzzWWIqW1THBHpe4etqf9q5hpRVNqyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NMaPePsy3xc/yo45aVQa04VG77wobST+HjAHgK5kVeosd1jTyio0DBjUdTe3P2DDB IOrxSCEWKkss8NfQlhjEd2j74WJfTcWhndRrmILkU9dxST5oLJVZkbzc/FmCfbDP2w PmmvU2Qd95/zYJjvzceQB+LvFWw7v/bv+qWQ/+pA= 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.15 026/168] i2c: riic: Always round-up when calculating bus period Date: Mon, 6 Jan 2025 16:15:34 +0100 Message-ID: <20250106151139.450755986@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106151138.451846855@linuxfoundation.org> References: <20250106151138.451846855@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-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 @@ -330,7 +330,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; }