[RFC PATCH v3] phy: qcom-mipi-csi2: round the requested settle interval up
Jizhou Tong
fqwqf at fqwqf.xyz
Mon Oct 19 08:47:03 PDT 2026
The settling counter represents the requested interval in timer ticks,
with the existing six-tick hardware offset. Truncating the division
programs fewer ticks than requested when the interval is not an exact
multiple of the timer period.
Rounding the final division alone is insufficient: the earlier unit
interval calculation already rounds down before multiplying by six.
At a 599.9 MHz link frequency and a 100 MHz timer, the exact requested
interval is approximately 90000.833 ps. The truncated unit interval
produces 89998 ps, so even a rounded-up final division programs nine
ticks (90000 ps) instead of the required ten.
Compute the complete six-unit-interval term as 3 / link_freq and round
it up to picoseconds with a 64-bit divisor. Then round up the conversion
to timer ticks. Retain the timer-period calculation, minimum counter
handling and six-tick hardware offset.
Link: https://lore.kernel.org/all/sashiko-outbox-166399@kernel.org/
Signed-off-by: Jizhou Tong <fqwqf at fqwqf.xyz>
---
Changes in v3:
- Base directly on media-next d7e7bca71698, which contains the PHY
driver, and remove the old prerequisite patch IDs.
- No source changes from v2.
The v2 CI report lists only the two prerequisite patches and names the
PHY driver addition as its branch head. This revision supplies just the
rounding fix on media-next, without asking b4 to reconstruct that series.
v2:
https://lore.kernel.org/all/010601a1332f343c-b1381230-9344-4bef-a709-99e07b18d513-000000@ap-northeast-1.amazonses.com/
CI report:
https://linux-media.pages.freedesktop.org/-/users/patchwork/-/jobs/112510220/artifacts/report.htm
Validation: ARM64 W=1 driver-object build on the stated base, and
128482 ASan/UBSan cases using the actual helper against independent
rational bounds. The baseline fails the rounding tests. The source
file after applying this patch is byte-identical to v2.
The timer-period convention and zero-count rejection are unchanged.
Zero is also rejected by the base driver; whether hardware permits it
is a separate question for the PHY maintainer. This remains an RFC for
the rounding policy and six-tick offset. No new hardware test is claimed.
.../phy/qualcomm/phy-qcom-mipi-csi2-3ph-dphy.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/phy/qualcomm/phy-qcom-mipi-csi2-3ph-dphy.c b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-3ph-dphy.c
index 966d79c98f9b21e1a235b8397c4c84b25d869427..f07699ba1fde63536b4d63cc4008ff936f78cc7d 100644
--- a/drivers/phy/qualcomm/phy-qcom-mipi-csi2-3ph-dphy.c
+++ b/drivers/phy/qualcomm/phy-qcom-mipi-csi2-3ph-dphy.c
@@ -9,6 +9,7 @@
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/io.h>
+#include <linux/math64.h>
#include <linux/time64.h>
#include "phy-qcom-mipi-csi2.h"
@@ -220,23 +221,19 @@ static void phy_qcom_mipi_csi2_reset(struct mipi_csi2phy_device *csi2phy)
*/
static u8 phy_qcom_mipi_csi2_settle_cnt_calc(s64 link_freq, u32 timer_clk_rate)
{
- u32 t_hs_prepare_max_ps;
u32 timer_period_ps;
- u32 t_hs_settle_ps;
+ u64 t_hs_settle_ps;
u8 settle_cnt;
- u32 ui_ps;
- ui_ps = div64_u64(PSEC_PER_SEC, link_freq);
- ui_ps /= 2;
- t_hs_prepare_max_ps = 85000 + 6 * ui_ps;
- t_hs_settle_ps = t_hs_prepare_max_ps;
+ /* Round the complete 6 * UI term up, avoiding an intermediate truncation. */
+ t_hs_settle_ps = 85000 + DIV64_U64_ROUND_UP(3 * PSEC_PER_SEC, link_freq);
timer_period_ps = div_u64(PSEC_PER_SEC, timer_clk_rate);
- if ((t_hs_settle_ps / timer_period_ps) < 6)
+ if (div_u64(t_hs_settle_ps, timer_period_ps) < 6)
return 0;
- settle_cnt = t_hs_settle_ps / timer_period_ps - 6;
+ settle_cnt = DIV_U64_ROUND_UP(t_hs_settle_ps, timer_period_ps) - 6;
return settle_cnt;
}
base-commit: d7e7bca7169873b46e857c025c10f3336c1258d8
--
2.53.0
More information about the linux-phy
mailing list