Skip to content

Commit b3b6df2

Browse files
Jimmy Assarssonmarckleinebudde
authored andcommitted
can: kvaser_usb: kvaser_usb_leaf: fix bittiming limits
Use correct bittiming limits depending on device. For devices based on USBcanII, Leaf M32C or Leaf i.MX28. Fixes: 080f40a ("can: kvaser_usb: Add support for Kvaser CAN/USB devices") Fixes: b4f2013 ("can: kvaser_usb: add support for Kvaser Leaf v2 and usb mini PCIe") Fixes: f5d4abe ("can: kvaser_usb: Add support for the USBcan-II family") Link: https://lore.kernel.org/all/[email protected] Cc: [email protected] Signed-off-by: Jimmy Assarsson <[email protected]> [mkl: remove stray netlink.h include] [mkl: keep struct can_bittiming_const kvaser_usb_flexc_bittiming_const in kvaser_usb_hydra.c] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent e6c80e6 commit b3b6df2

File tree

3 files changed

+47
-35
lines changed

3 files changed

+47
-35
lines changed

drivers/net/can/usb/kvaser_usb/kvaser_usb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,6 @@ int kvaser_usb_send_cmd_async(struct kvaser_usb_net_priv *priv, void *cmd,
187187

188188
int kvaser_usb_can_rx_over_error(struct net_device *netdev);
189189

190+
extern const struct can_bittiming_const kvaser_usb_flexc_bittiming_const;
191+
190192
#endif /* KVASER_USB_H */

drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static const struct can_bittiming_const kvaser_usb_hydra_kcan_bittiming_c = {
375375
.brp_inc = 1,
376376
};
377377

378-
static const struct can_bittiming_const kvaser_usb_hydra_flexc_bittiming_c = {
378+
const struct can_bittiming_const kvaser_usb_flexc_bittiming_const = {
379379
.name = "kvaser_usb_flex",
380380
.tseg1_min = 4,
381381
.tseg1_max = 16,
@@ -2052,7 +2052,7 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_flexc = {
20522052
.freq = 24 * MEGA /* Hz */,
20532053
},
20542054
.timestamp_freq = 1,
2055-
.bittiming_const = &kvaser_usb_hydra_flexc_bittiming_c,
2055+
.bittiming_const = &kvaser_usb_flexc_bittiming_const,
20562056
};
20572057

20582058
static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_rt = {

drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,6 @@
101101
#define USBCAN_ERROR_STATE_RX_ERROR BIT(1)
102102
#define USBCAN_ERROR_STATE_BUSERROR BIT(2)
103103

104-
/* bittiming parameters */
105-
#define KVASER_USB_TSEG1_MIN 1
106-
#define KVASER_USB_TSEG1_MAX 16
107-
#define KVASER_USB_TSEG2_MIN 1
108-
#define KVASER_USB_TSEG2_MAX 8
109-
#define KVASER_USB_SJW_MAX 4
110-
#define KVASER_USB_BRP_MIN 1
111-
#define KVASER_USB_BRP_MAX 64
112-
#define KVASER_USB_BRP_INC 1
113-
114104
/* ctrl modes */
115105
#define KVASER_CTRL_MODE_NORMAL 1
116106
#define KVASER_CTRL_MODE_SILENT 2
@@ -343,48 +333,68 @@ struct kvaser_usb_err_summary {
343333
};
344334
};
345335

346-
static const struct can_bittiming_const kvaser_usb_leaf_bittiming_const = {
347-
.name = "kvaser_usb",
348-
.tseg1_min = KVASER_USB_TSEG1_MIN,
349-
.tseg1_max = KVASER_USB_TSEG1_MAX,
350-
.tseg2_min = KVASER_USB_TSEG2_MIN,
351-
.tseg2_max = KVASER_USB_TSEG2_MAX,
352-
.sjw_max = KVASER_USB_SJW_MAX,
353-
.brp_min = KVASER_USB_BRP_MIN,
354-
.brp_max = KVASER_USB_BRP_MAX,
355-
.brp_inc = KVASER_USB_BRP_INC,
336+
static const struct can_bittiming_const kvaser_usb_leaf_m16c_bittiming_const = {
337+
.name = "kvaser_usb_ucii",
338+
.tseg1_min = 4,
339+
.tseg1_max = 16,
340+
.tseg2_min = 2,
341+
.tseg2_max = 8,
342+
.sjw_max = 4,
343+
.brp_min = 1,
344+
.brp_max = 16,
345+
.brp_inc = 1,
346+
};
347+
348+
static const struct can_bittiming_const kvaser_usb_leaf_m32c_bittiming_const = {
349+
.name = "kvaser_usb_leaf",
350+
.tseg1_min = 3,
351+
.tseg1_max = 16,
352+
.tseg2_min = 2,
353+
.tseg2_max = 8,
354+
.sjw_max = 4,
355+
.brp_min = 2,
356+
.brp_max = 128,
357+
.brp_inc = 2,
356358
};
357359

358-
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_8mhz = {
360+
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_usbcan_dev_cfg = {
359361
.clock = {
360362
.freq = 8 * MEGA /* Hz */,
361363
},
362364
.timestamp_freq = 1,
363-
.bittiming_const = &kvaser_usb_leaf_bittiming_const,
365+
.bittiming_const = &kvaser_usb_leaf_m16c_bittiming_const,
366+
};
367+
368+
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_m32c_dev_cfg = {
369+
.clock = {
370+
.freq = 16 * MEGA /* Hz */,
371+
},
372+
.timestamp_freq = 1,
373+
.bittiming_const = &kvaser_usb_leaf_m32c_bittiming_const,
364374
};
365375

366-
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_16mhz = {
376+
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_imx_dev_cfg_16mhz = {
367377
.clock = {
368378
.freq = 16 * MEGA /* Hz */,
369379
},
370380
.timestamp_freq = 1,
371-
.bittiming_const = &kvaser_usb_leaf_bittiming_const,
381+
.bittiming_const = &kvaser_usb_flexc_bittiming_const,
372382
};
373383

374-
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_24mhz = {
384+
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_imx_dev_cfg_24mhz = {
375385
.clock = {
376386
.freq = 24 * MEGA /* Hz */,
377387
},
378388
.timestamp_freq = 1,
379-
.bittiming_const = &kvaser_usb_leaf_bittiming_const,
389+
.bittiming_const = &kvaser_usb_flexc_bittiming_const,
380390
};
381391

382-
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_dev_cfg_32mhz = {
392+
static const struct kvaser_usb_dev_cfg kvaser_usb_leaf_imx_dev_cfg_32mhz = {
383393
.clock = {
384394
.freq = 32 * MEGA /* Hz */,
385395
},
386396
.timestamp_freq = 1,
387-
.bittiming_const = &kvaser_usb_leaf_bittiming_const,
397+
.bittiming_const = &kvaser_usb_flexc_bittiming_const,
388398
};
389399

390400
static void *
@@ -528,17 +538,17 @@ static void kvaser_usb_leaf_get_software_info_leaf(struct kvaser_usb *dev,
528538
/* Firmware expects bittiming parameters calculated for 16MHz
529539
* clock, regardless of the actual clock
530540
*/
531-
dev->cfg = &kvaser_usb_leaf_dev_cfg_16mhz;
541+
dev->cfg = &kvaser_usb_leaf_m32c_dev_cfg;
532542
} else {
533543
switch (sw_options & KVASER_USB_LEAF_SWOPTION_FREQ_MASK) {
534544
case KVASER_USB_LEAF_SWOPTION_FREQ_16_MHZ_CLK:
535-
dev->cfg = &kvaser_usb_leaf_dev_cfg_16mhz;
545+
dev->cfg = &kvaser_usb_leaf_imx_dev_cfg_16mhz;
536546
break;
537547
case KVASER_USB_LEAF_SWOPTION_FREQ_24_MHZ_CLK:
538-
dev->cfg = &kvaser_usb_leaf_dev_cfg_24mhz;
548+
dev->cfg = &kvaser_usb_leaf_imx_dev_cfg_24mhz;
539549
break;
540550
case KVASER_USB_LEAF_SWOPTION_FREQ_32_MHZ_CLK:
541-
dev->cfg = &kvaser_usb_leaf_dev_cfg_32mhz;
551+
dev->cfg = &kvaser_usb_leaf_imx_dev_cfg_32mhz;
542552
break;
543553
}
544554
}
@@ -565,7 +575,7 @@ static int kvaser_usb_leaf_get_software_info_inner(struct kvaser_usb *dev)
565575
dev->fw_version = le32_to_cpu(cmd.u.usbcan.softinfo.fw_version);
566576
dev->max_tx_urbs =
567577
le16_to_cpu(cmd.u.usbcan.softinfo.max_outstanding_tx);
568-
dev->cfg = &kvaser_usb_leaf_dev_cfg_8mhz;
578+
dev->cfg = &kvaser_usb_leaf_usbcan_dev_cfg;
569579
break;
570580
}
571581

0 commit comments

Comments
 (0)