]> rtime.felk.cvut.cz Git - socketcan-devel.git/commitdiff
candev: allow SJW user setting for bittiming calculation
authorhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Fri, 30 Sep 2011 10:02:24 +0000 (10:02 +0000)
committerhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Fri, 30 Sep 2011 10:02:24 +0000 (10:02 +0000)
This patch adds support for SJW user settings to not set the synchronization
jump width (SJW) to 1 in any case when using the in-kernel bittiming
calculation.

The ip-tool from iproute2 already supports to pass the user defined SJW
value. The given SJW value is sanitized with the controller specific sjw_max
and the calculated tseg2 value. As the SJW can have values up to 4 providing
this value will lead to the maximum possible SJW automatically. A higher SJW
allows higher controller oscillator tolerances.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Acked-by: Wolfgang Grandegger <wg@grandegger.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Acked-by: Kurt Van Dijck <kurt.van.dijck@eia.be>
git-svn-id: svn://svn.berlios.de//socketcan/trunk@1276 030b6a49-0b11-0410-94ab-b0dab22257f2

kernel/2.6/drivers/net/can/dev.c

index 0b68c160b4a58747e005a3ac6a5b9445e37985bc..59e779be38ee0c9c589b920befe67180145231c7 100644 (file)
@@ -160,7 +160,19 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
        bt->prop_seg = tseg1 / 2;
        bt->phase_seg1 = tseg1 - bt->prop_seg;
        bt->phase_seg2 = tseg2;
-       bt->sjw = 1;
+
+       /* check for sjw user settings */
+       if (!bt->sjw || !btc->sjw_max)
+               bt->sjw = 1;
+       else {
+               /* bt->sjw is at least 1 -> sanitize upper bound to sjw_max */
+               if (bt->sjw > btc->sjw_max)
+                       bt->sjw = btc->sjw_max;
+               /* bt->sjw must not be higher than tseg2 */
+               if (tseg2 < bt->sjw)
+                       bt->sjw = tseg2;
+       }
+
        bt->brp = best_brp;
 #ifndef CONFIG_CAN_DEV_SYSFS
        /* real bit-rate */