[RFC PATCH v2] phy: qcom-mipi-csi2: round the requested settle interval up
Jizhou Tong
fqwqf at fqwqf.xyz
Mon Oct 12 19:54:54 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 v2:
- Round the complete 6 * UI term up instead of truncating UI first.
- Use 64-bit division for the link-frequency denominator and interval.
- Add the 599.9 MHz counterexample and rational-boundary regression tests.
v1: https://lore.kernel.org/all/010601a1251fbfb9-9afc4070-5194-4714-86b1-5358791e7770-000000@ap-northeast-1.amazonses.com/
Review: https://lore.kernel.org/all/sashiko-outbox-166399@kernel.org/
Rechecked against media-next d7e7bca71698 on 12 October 2026, which
contains the v18 CSI2 PHY driver and still truncates this calculation.
The base/prerequisite metadata also permits applying this increment
on Linux 7.3-rc5 plus the original v18 PHY changes.
Validation: ARM64 W=1 driver-object build and 128482 ASan/UBSan test
cases using the actual C function against independent rational bounds.
The v1 calculation fails 410 cases, including 599.9 MHz / 100 MHz.
This remains an RFC for confirmation of the hardware counter's rounding
policy and existing six-tick offset. The timer-period convention is
unchanged. The v2 arithmetic has software/build coverage; it has not
yet been isolated in a new SL7 hardware test.
.../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: 72d3fcf802c45d00b300f25b848a93c3a2bd7c7e
prerequisite-patch-id: ab0db8f40ef87320e67543686702109ac045784f
prerequisite-patch-id: d6b3dab26f8a95822465a176f691280a5610c22e
--
2.53.0
More information about the linux-phy
mailing list