From: Oliver Hartkopp <socketcan@hartkopp•net>
To: David Miller <davem@davemloft•net>
Cc: "Linux Netdev List" <netdev@vger•kernel.org>,
"Wolfgang Grandegger" <wg@grandegger•com>,
"Pavel Píša" <pisa@cmp•felk.cvut.cz>,
"SocketCAN Core Mailing List" <socketcan-core@lists•berlios.de>
Subject: [PATCH net-next v2] candev: allow SJW user setting for bittiming calculation
Date: Thu, 22 Sep 2011 12:28:54 +0200 [thread overview]
Message-ID: <4E7B0DE6.9020807@hartkopp.net> (raw)
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>
---
v2: Resend due to wrong mail address header encoding.
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 9bf1116..25695bd 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -150,7 +150,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;
/* real bit-rate */
bt->bitrate = priv->clock.freq / (bt->brp * (tseg1 + tseg2 + 1));
next reply other threads:[~2011-09-22 10:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-22 10:28 Oliver Hartkopp [this message]
[not found] ` <4E7B0DE6.9020807-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org>
2011-09-22 13:07 ` [PATCH net-next v2] candev: allow SJW user setting for bittiming calculation Wolfgang Grandegger
[not found] ` <4E7B331F.3070801-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
2011-09-22 16:26 ` Oliver Hartkopp
[not found] ` <4E7B61C8.8020506-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org>
2011-09-22 18:10 ` Wolfgang Grandegger
[not found] ` <4E7B7A30.4030707-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
2011-09-22 19:41 ` Oliver Hartkopp
[not found] ` <4E7B8F63.6060108-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org>
2011-09-23 7:24 ` Wolfgang Grandegger
[not found] ` <4E7C3424.8030406-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
2011-09-23 9:32 ` Pavel Pisa
[not found] ` <201109231132.49976.pisa-/N2ztlQkxE7Ub/6JBqosbQ@public.gmane.org>
2011-09-23 15:50 ` Oliver Hartkopp
2011-09-24 7:22 ` Wolfgang Grandegger
[not found] ` <4E7D8537.8010302-5Yr1BZd7O62+XT7JhA+gdA@public.gmane.org>
2011-09-27 17:32 ` Oliver Hartkopp
[not found] ` <4E8208B5.4050907-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org>
2011-09-27 20:04 ` Wolfgang Grandegger
2011-09-24 7:44 ` Wolfgang Grandegger
2011-09-27 20:05 ` Wolfgang Grandegger
2011-09-29 6:14 ` Kurt Van Dijck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E7B0DE6.9020807@hartkopp.net \
--to=socketcan@hartkopp$(echo .)net \
--cc=davem@davemloft$(echo .)net \
--cc=netdev@vger$(echo .)kernel.org \
--cc=pisa@cmp$(echo .)felk.cvut.cz \
--cc=socketcan-core@lists$(echo .)berlios.de \
--cc=wg@grandegger$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox