]> git.ipfire.org Git - thirdparty/linux.git/commit
can: calc_bittiming: add can_calc_sample_point_pwm()
authorVincent Mailhol <mailhol@kernel.org>
Wed, 26 Nov 2025 10:16:15 +0000 (11:16 +0100)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 26 Nov 2025 10:20:44 +0000 (11:20 +0100)
commitf5de373ae455f1db6cf15033d660ac0046bcb0ff
treeef57696ed928b1b7d61c2215981987ebee40cf73
parenta6ddf91a4f9718cec712785904c57b7117f61d6c
can: calc_bittiming: add can_calc_sample_point_pwm()

The optimum sample point value depends on the bit symmetry. The more
asymmetric the bit is, the more the sample point would be located
towards the end of the bit. On the contrary, if the transceiver only
has a small asymmetry, the optimal sample point would be slightly
after the centre of the bit.

For NRZ encoding (used by Classical CAN, CAN FD and CAN XL with TMS
off), the optimum sample points values are above 70% as implemented in
can_calc_sample_point_nrz().

When TMS is on, CAN XL optimum sample points are near to 50% or
60% [1]. Add can_calc_sample_point_pwm() which returns a sample point
which is suitable for PWM encoding. We crafted the formula to make it
return the same values as below table (source: table 3 of [1]).

       Bit rate (Mbits/s) Sample point
       -------------------------------------
         2.0  51.3%
         5.0  53.1%
         8.0  55.0%
        10.0  56.3%
        12.3  53.8%
        13.3  58.3%
        14.5  54.5%
        16.0  60.0%
        17.7  55.6%
        20.0  62.5%

The calculation simply consists of setting a slightly too high sample
point and then letting can_update_sample_point() correct the values.

For now, it is just a formula up our sleeves which matches the
empirical observations of [1]. Once CiA recommendations become
available, can_calc_sample_point_pwm() should be updated accordingly.

[1] CAN XL system design: Clock tolerances and edge deviations edge
    deviations
Link: https://www.can-cia.org/fileadmin/cia/documents/publications/cnlm/december_2024/cnlm_24-4_p18_can_xl_system_design_clock_tolerances_and_edge_deviations_dr_arthur_mutter_bosch.pdf
Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20251126-canxl-v8-14-e7e3eb74f889@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
drivers/net/can/dev/calc_bittiming.c