Skip to content

Commit 6ffc123

Browse files
vincent-mailholmarckleinebudde
authored andcommitted
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 <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent e72f1ba commit 6ffc123

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

drivers/net/can/dev/calc_bittiming.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,15 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,
173173

174174
void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const,
175175
const struct can_bittiming *dbt,
176-
u32 *ctrlmode, u32 ctrlmode_supported)
176+
u32 tdc_mask, u32 *ctrlmode, u32 ctrlmode_supported)
177177

178178
{
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))
180182
return;
181183

182-
*ctrlmode &= ~CAN_CTRLMODE_FD_TDC_MASK;
184+
*ctrlmode &= ~tdc_mask;
183185

184186
/* As specified in ISO 11898-1 section 11.3.3 "Transmitter
185187
* delay compensation" (TDC) is only applicable if data BRP is
@@ -193,6 +195,6 @@ void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const,
193195
if (sample_point_in_tc < tdc_const->tdco_min)
194196
return;
195197
tdc->tdco = min(sample_point_in_tc, tdc_const->tdco_max);
196-
*ctrlmode |= CAN_CTRLMODE_TDC_AUTO;
198+
*ctrlmode |= tdc_auto;
197199
}
198200
}

drivers/net/can/dev/netlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ static int can_dbt_changelink(struct net_device *dev, struct nlattr *data[],
341341
* do calculation
342342
*/
343343
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);
345345
} /* else: both CAN_CTRLMODE_TDC_{AUTO,MANUAL} are explicitly
346346
* turned off. TDC is disabled: do nothing
347347
*/

include/linux/can/bittiming.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,
135135

136136
void can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const,
137137
const struct can_bittiming *dbt,
138-
u32 *ctrlmode, u32 ctrlmode_supported);
138+
u32 tdc_mask, u32 *ctrlmode, u32 ctrlmode_supported);
139139
#else /* !CONFIG_CAN_CALC_BITTIMING */
140140
static inline int
141141
can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,
@@ -148,7 +148,7 @@ can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,
148148
static inline void
149149
can_calc_tdco(struct can_tdc *tdc, const struct can_tdc_const *tdc_const,
150150
const struct can_bittiming *dbt,
151-
u32 *ctrlmode, u32 ctrlmode_supported)
151+
u32 tdc_mask, u32 *ctrlmode, u32 ctrlmode_supported)
152152
{
153153
}
154154
#endif /* CONFIG_CAN_CALC_BITTIMING */

0 commit comments

Comments
 (0)