drivers: can: common: respect the range limits of phase_seg1

Respect the range limits of phase_seg1 when attempting to distribute ts1
between prop_seg and phase_seg1.

Even distribution may not be possible if the allowed ranges of prop_seg and
phase_seg1 are not equal.

Fixes: #55919

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2023-03-17 12:16:10 +01:00 committed by Carles Cufí
commit ffefc6441b

View file

@ -105,9 +105,21 @@ static int update_sampling_pnt(uint32_t ts, uint32_t sp, struct can_timing *res,
}
}
res->phase_seg2 = ts2;
/* Attempt to distribute ts1 evenly between prop_seq and phase_seg1 */
res->prop_seg = CLAMP(ts1 / 2, min->prop_seg, max->prop_seg);
res->phase_seg1 = ts1 - res->prop_seg;
res->phase_seg2 = ts2;
if (res->phase_seg1 > max->phase_seg1) {
/* Even ts1 distribution not possible, decrease phase_seg1 */
res->phase_seg1 = max->phase_seg1;
res->prop_seg = ts1 - res->phase_seg1;
} else if (res->phase_seg1 < min->phase_seg1) {
/* Even ts1 distribution not possible, increase phase_seg1 */
res->phase_seg1 = min->phase_seg1;
res->prop_seg = ts1 - res->phase_seg1;
}
sp_calc = (CAN_SYNC_SEG + ts1) * 1000 / ts;