Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: calc_bittiming: make can_calc_tdco() FD agnostic

can_calc_tdco() uses the CAN_CTRLMODE_FD_TDC_MASK and
CAN_CTRLMODE_TDC_AUTO macros making it specific to CAN FD. Add the tdc
mask to the function parameter list. The value of the tdc auto flag
can then be derived from that mask and stored in a local variable.
This way, the function becomes CAN FD agnostic and can be reused later
on for the CAN XL TDC.

Signed-off-by: Vincent Mailhol <mailhol@kernel.org>
Link: https://patch.msgid.link/20250923-canxl-netlink-prep-v4-18-e720d28f66fe@kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Vincent Mailhol and committed by
Marc Kleine-Budde
6ffc1230 e72f1ba7

+9 -7
+6 -4
drivers/net/can/dev/calc_bittiming.c
··· 173 173 174 174 void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const, 175 175 const struct can_bittiming *dbt, 176 - u32 *ctrlmode, u32 ctrlmode_supported) 176 + u32 tdc_mask, u32 *ctrlmode, u32 ctrlmode_supported) 177 177 178 178 { 179 - if (!tdc_const || !(ctrlmode_supported & CAN_CTRLMODE_TDC_AUTO)) 179 + u32 tdc_auto = tdc_mask & CAN_CTRLMODE_TDC_AUTO_MASK; 180 + 181 + if (!tdc_const || !(ctrlmode_supported & tdc_auto)) 180 182 return; 181 183 182 - *ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK; 184 + *ctrlmode &= ~tdc_mask; 183 185 184 186 /* As specified in ISO 11898-1 section 11.3.3 "Transmitter 185 187 * delay compensation" (TDC) is only applicable if data BRP is ··· 195 193 if (sample_point_in_tc < tdc_const->tdco_min) 196 194 return; 197 195 tdc->tdco = min(sample_point_in_tc, tdc_const->tdco_max); 198 - *ctrlmode |= CAN_CTRLMODE_TDC_AUTO; 196 + *ctrlmode |= tdc_auto; 199 197 } 200 198 }
+1 -1
drivers/net/can/dev/netlink.c
··· 341 341 * do calculation 342 342 */ 343 343 can_calc_tdco(&dbt_params->tdc, dbt_params->tdc_const, &dbt, 344 - &priv->ctrlmode, priv->ctrlmode_supported); 344 + tdc_mask, &priv->ctrlmode, priv->ctrlmode_supported); 345 345 } /* else: both CAN_CTRLMODE_TDC_{AUTO,MANUAL} are explicitly 346 346 * turned off. TDC is disabled: do nothing 347 347 */
+2 -2
include/linux/can/bittiming.h
··· 135 135 136 136 void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const, 137 137 const struct can_bittiming *dbt, 138 - u32 *ctrlmode, u32 ctrlmode_supported); 138 + u32 tdc_mask, u32 *ctrlmode, u32 ctrlmode_supported); 139 139 #else /* !CONFIG_CAN_CALC_BITTIMING */ 140 140 static inline int 141 141 can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt, ··· 148 148 static inline void 149 149 can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const, 150 150 const struct can_bittiming *dbt, 151 - u32 *ctrlmode, u32 ctrlmode_supported) 151 + u32 tdc_mask, u32 *ctrlmode, u32 ctrlmode_supported) 152 152 { 153 153 } 154 154 #endif /* CONFIG_CAN_CALC_BITTIMING */