Skip to content

Commit

Permalink
can: bittiming(): replace open coded variants of can_bit_time()
Browse files Browse the repository at this point in the history
Commit 1c47fa6 ("can: dev: add a helper function to calculate the
duration of one bit") added the helper function can_bit_time().

Replace open coded variants of can_bit_time() by the helper function.

Link: https://lore.kernel.org/all/20230202110854.2318594-2-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  • Loading branch information
Marc Kleine-Budde committed Feb 6, 2023
1 parent 36207c3 commit 89cfa63
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions drivers/net/can/dev/bittiming.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static int can_fixup_bittiming(const struct net_device *dev, struct can_bittimin
const struct can_bittiming_const *btc)
{
const struct can_priv *priv = netdev_priv(dev);
unsigned int tseg1, alltseg;
unsigned int tseg1;
u64 brp64;

tseg1 = bt->prop_seg + bt->phase_seg1;
Expand All @@ -38,9 +38,8 @@ static int can_fixup_bittiming(const struct net_device *dev, struct can_bittimin
if (bt->brp < btc->brp_min || bt->brp > btc->brp_max)
return -EINVAL;

alltseg = bt->prop_seg + bt->phase_seg1 + bt->phase_seg2 + 1;
bt->bitrate = priv->clock.freq / (bt->brp * alltseg);
bt->sample_point = ((tseg1 + 1) * 1000) / alltseg;
bt->bitrate = priv->clock.freq / (bt->brp * can_bit_time(bt));
bt->sample_point = ((tseg1 + 1) * 1000) / can_bit_time(bt);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/can/dev/calc_bittiming.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,

/* real bitrate */
bt->bitrate = priv->clock.freq /
(bt->brp * (CAN_SYNC_SEG + tseg1 + tseg2));
(bt->brp * can_bit_time(bt));

return 0;
}
Expand Down

0 comments on commit 89cfa63

Please sign in to comment.