summaryrefslogtreecommitdiff
path: root/drivers/net/can/dev.c
diff options
context:
space:
mode:
authorOliver Hartkopp <socketcan@hartkopp.net>2014-02-28 19:36:22 +0400
committerMarc Kleine-Budde <mkl@pengutronix.de>2014-03-07 12:18:22 +0400
commit08da7da41ea490eab08ad9e2674e3b92d6aa2b07 (patch)
treedab3fbc1e164cf04748bb331715ce9261c16a3c5 /drivers/net/can/dev.c
parentd5298dffebae76810a6a942bc6467f893bc11eee (diff)
downloadlinux-08da7da41ea490eab08ad9e2674e3b92d6aa2b07.tar.xz
can: provide a separate bittiming_const parameter to bittiming functions
As the bittiming calculation functions are to be used with different bittiming_const structures for CAN and CAN FD the direct reference to priv->bittiming_const inside these functions has to be removed. Also moved the check for existing bittiming const to one place. Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Acked-by: Stephane Grosjean <s.grosjean@peak-system.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'drivers/net/can/dev.c')
-rw-r--r--drivers/net/can/dev.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index e5f1faf36d8f..8141290e4c18 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -99,10 +99,10 @@ static int can_update_spt(const struct can_bittiming_const *btc,
return 1000 * (tseg + 1 - *tseg2) / (tseg + 1);
}
-static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
+static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
+ const struct can_bittiming_const *btc)
{
struct can_priv *priv = netdev_priv(dev);
- const struct can_bittiming_const *btc = priv->bittiming_const;
long rate, best_rate = 0;
long best_error = 1000000000, error = 0;
int best_tseg = 0, best_brp = 0, brp = 0;
@@ -110,9 +110,6 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
int spt_error = 1000, spt = 0, sampl_pt;
u64 v64;
- if (!priv->bittiming_const)
- return -ENOTSUPP;
-
/* Use CIA recommended sample points */
if (bt->sample_point) {
sampl_pt = bt->sample_point;
@@ -204,7 +201,8 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
return 0;
}
#else /* !CONFIG_CAN_CALC_BITTIMING */
-static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
+static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
+ const struct can_bittiming_const *btc)
{
netdev_err(dev, "bit-timing calculation not available\n");
return -EINVAL;
@@ -217,16 +215,13 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
* 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)
+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);
- const struct can_bittiming_const *btc = priv->bittiming_const;
int tseg1, alltseg;
u64 brp64;
- if (!priv->bittiming_const)
- return -ENOTSUPP;
-
tseg1 = bt->prop_seg + bt->phase_seg1;
if (!bt->sjw)
bt->sjw = 1;
@@ -254,14 +249,14 @@ static int can_fixup_bittiming(struct net_device *dev, struct can_bittiming *bt)
return 0;
}
-static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt)
+static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt,
+ const struct can_bittiming_const *btc)
{
- struct can_priv *priv = netdev_priv(dev);
int err;
/* Check if the CAN device has bit-timing parameters */
- if (!priv->bittiming_const)
- return 0;
+ if (!btc)
+ return -ENOTSUPP;
/*
* Depending on the given can_bittiming parameter structure the CAN
@@ -270,9 +265,9 @@ static int can_get_bittiming(struct net_device *dev, struct can_bittiming *bt)
* provided directly which are then checked and fixed up.
*/
if (!bt->tq && bt->bitrate)
- err = can_calc_bittiming(dev, bt);
+ err = can_calc_bittiming(dev, bt, btc);
else if (bt->tq && !bt->bitrate)
- err = can_fixup_bittiming(dev, bt);
+ err = can_fixup_bittiming(dev, bt, btc);
else
err = -EINVAL;
@@ -670,7 +665,7 @@ static int can_changelink(struct net_device *dev,
if (dev->flags & IFF_UP)
return -EBUSY;
memcpy(&bt, nla_data(data[IFLA_CAN_BITTIMING]), sizeof(bt));
- err = can_get_bittiming(dev, &bt);
+ err = can_get_bittiming(dev, &bt, priv->bittiming_const);
if (err)
return err;
memcpy(&priv->bittiming, &bt, sizeof(bt));