can-calc-bit-timing: import bit timing calculation algorithm from v3.18
add missing can_fixup_bittiming() Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>pull/372/head
parent
c1f5dc53ec
commit
b777ce2e6d
|
|
@ -36,7 +36,6 @@
|
||||||
* registers of the CAN controller. You can find more information
|
* registers of the CAN controller. You can find more information
|
||||||
* in the header file linux/can/netlink.h.
|
* in the header file linux/can/netlink.h.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int can_update_spt(const struct can_bittiming_const *btc,
|
static int can_update_spt(const struct can_bittiming_const *btc,
|
||||||
int sampl_pt, int tseg, int *tseg1, int *tseg2)
|
int sampl_pt, int tseg, int *tseg1, int *tseg2)
|
||||||
{
|
{
|
||||||
|
|
@ -153,3 +152,43 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checks the validity of the specified bit-timing parameters prop_seg,
|
||||||
|
* phase_seg1, phase_seg2 and sjw and tries to determine the bitrate
|
||||||
|
* prescaler value brp. You can find more information in the header
|
||||||
|
* file linux/can/netlink.h.
|
||||||
|
*/
|
||||||
|
static int can_fixup_bittiming(struct net_device *dev, struct can_bittiming *bt,
|
||||||
|
const struct can_bittiming_const *btc)
|
||||||
|
{
|
||||||
|
struct can_priv *priv = netdev_priv(dev);
|
||||||
|
int tseg1, alltseg;
|
||||||
|
u64 brp64;
|
||||||
|
|
||||||
|
tseg1 = bt->prop_seg + bt->phase_seg1;
|
||||||
|
if (!bt->sjw)
|
||||||
|
bt->sjw = 1;
|
||||||
|
if (bt->sjw > btc->sjw_max ||
|
||||||
|
tseg1 < btc->tseg1_min || tseg1 > btc->tseg1_max ||
|
||||||
|
bt->phase_seg2 < btc->tseg2_min || bt->phase_seg2 > btc->tseg2_max)
|
||||||
|
return -ERANGE;
|
||||||
|
|
||||||
|
brp64 = (u64)priv->clock.freq * (u64)bt->tq;
|
||||||
|
if (btc->brp_inc > 1)
|
||||||
|
do_div(brp64, btc->brp_inc);
|
||||||
|
brp64 += 500000000UL - 1;
|
||||||
|
do_div(brp64, 1000000000UL); /* the practicable BRP */
|
||||||
|
if (btc->brp_inc > 1)
|
||||||
|
brp64 *= btc->brp_inc;
|
||||||
|
bt->brp = (u32)brp64;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1186,9 +1186,11 @@ static const unsigned int common_data_bitrates[] = {
|
||||||
|
|
||||||
#define can_update_spt can_update_spt_v3_18
|
#define can_update_spt can_update_spt_v3_18
|
||||||
#define can_calc_bittiming can_calc_bittiming_v3_18
|
#define can_calc_bittiming can_calc_bittiming_v3_18
|
||||||
|
#define can_fixup_bittiming can_fixup_bittiming_v3_18
|
||||||
#include "can-calc-bit-timing-v3_18.c"
|
#include "can-calc-bit-timing-v3_18.c"
|
||||||
#undef can_update_spt
|
#undef can_update_spt
|
||||||
#undef can_calc_bittiming
|
#undef can_calc_bittiming
|
||||||
|
#undef can_fixup_bittiming
|
||||||
|
|
||||||
#define can_update_sample_point can_update_sample_point_v4_8
|
#define can_update_sample_point can_update_sample_point_v4_8
|
||||||
#define can_calc_bittiming can_calc_bittiming_v4_8
|
#define can_calc_bittiming can_calc_bittiming_v4_8
|
||||||
|
|
@ -1244,7 +1246,7 @@ static const struct alg alg_list[] = {
|
||||||
.name = "v4.8",
|
.name = "v4.8",
|
||||||
}, {
|
}, {
|
||||||
.calc_bittiming = can_calc_bittiming_v3_18,
|
.calc_bittiming = can_calc_bittiming_v3_18,
|
||||||
.fixup_bittiming = can_fixup_bittiming,
|
.fixup_bittiming = can_fixup_bittiming_v3_18,
|
||||||
.name = "v3.18",
|
.name = "v3.18",
|
||||||
}, {
|
}, {
|
||||||
.calc_bittiming = can_calc_bittiming_v2_6_31,
|
.calc_bittiming = can_calc_bittiming_v2_6_31,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue