Skip to content

Commit e6c80e6

Browse files
Jimmy Assarssonmarckleinebudde
authored andcommitted
can: kvaser_usb: kvaser_usb_leaf: fix CAN clock frequency regression
The firmware of M32C based Leaf devices expects bittiming parameters calculated for 16MHz clock. Since we use the actual clock frequency of the device, the device may end up with wrong bittiming parameters, depending on user requested parameters. This regression affects M32C based Leaf devices with non-16MHz clock. Fixes: fb12797 ("can: kvaser_usb: get CAN clock frequency from device") Link: https://lore.kernel.org/all/[email protected] Cc: [email protected] Signed-off-by: Jimmy Assarsson <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 49f274c commit e6c80e6

File tree

3 files changed

+38
-21
lines changed

3 files changed

+38
-21
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
/* Kvaser USB device quirks */
3939
#define KVASER_USB_QUIRK_HAS_SILENT_MODE BIT(0)
4040
#define KVASER_USB_QUIRK_HAS_TXRX_ERRORS BIT(1)
41+
#define KVASER_USB_QUIRK_IGNORE_CLK_FREQ BIT(2)
4142

4243
/* Device capabilities */
4344
#define KVASER_USB_CAP_BERR_CAP 0x01

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,33 @@ static const struct kvaser_usb_driver_info kvaser_usb_driver_info_usbcan = {
101101
};
102102

103103
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf = {
104-
.quirks = 0,
104+
.quirks = KVASER_USB_QUIRK_IGNORE_CLK_FREQ,
105105
.family = KVASER_LEAF,
106106
.ops = &kvaser_usb_leaf_dev_ops,
107107
};
108108

109109
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err = {
110-
.quirks = KVASER_USB_QUIRK_HAS_TXRX_ERRORS,
110+
.quirks = KVASER_USB_QUIRK_HAS_TXRX_ERRORS |
111+
KVASER_USB_QUIRK_IGNORE_CLK_FREQ,
111112
.family = KVASER_LEAF,
112113
.ops = &kvaser_usb_leaf_dev_ops,
113114
};
114115

115116
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leaf_err_listen = {
116117
.quirks = KVASER_USB_QUIRK_HAS_TXRX_ERRORS |
117-
KVASER_USB_QUIRK_HAS_SILENT_MODE,
118+
KVASER_USB_QUIRK_HAS_SILENT_MODE |
119+
KVASER_USB_QUIRK_IGNORE_CLK_FREQ,
118120
.family = KVASER_LEAF,
119121
.ops = &kvaser_usb_leaf_dev_ops,
120122
};
121123

124+
static const struct kvaser_usb_driver_info kvaser_usb_driver_info_leafimx = {
125+
.quirks = 0,
126+
.ops = &kvaser_usb_leaf_dev_ops,
127+
};
128+
122129
static const struct usb_device_id kvaser_usb_table[] = {
123-
/* Leaf USB product IDs */
130+
/* Leaf M32C USB product IDs */
124131
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_DEVEL_PRODUCT_ID),
125132
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
126133
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LITE_PRODUCT_ID),
@@ -161,22 +168,24 @@ static const struct usb_device_id kvaser_usb_table[] = {
161168
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err },
162169
{ USB_DEVICE(KVASER_VENDOR_ID, USB_CAN_R_PRODUCT_ID),
163170
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf_err },
171+
172+
/* Leaf i.MX28 USB product IDs */
164173
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LITE_V2_PRODUCT_ID),
165-
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
174+
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
166175
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MINI_PCIE_HS_PRODUCT_ID),
167-
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
176+
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
168177
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LIGHT_HS_V2_OEM_PRODUCT_ID),
169-
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
178+
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
170179
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_LIGHT_2HS_PRODUCT_ID),
171-
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
180+
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
172181
{ USB_DEVICE(KVASER_VENDOR_ID, USB_MINI_PCIE_2HS_PRODUCT_ID),
173-
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
182+
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
174183
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN_R_V2_PRODUCT_ID),
175-
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
184+
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
176185
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LIGHT_R_V2_PRODUCT_ID),
177-
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
186+
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
178187
{ USB_DEVICE(KVASER_VENDOR_ID, USB_LEAF_LIGHT_HS_V2_OEM2_PRODUCT_ID),
179-
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leaf },
188+
.driver_info = (kernel_ulong_t)&kvaser_usb_driver_info_leafimx },
180189

181190
/* USBCANII USB product IDs */
182191
{ USB_DEVICE(KVASER_VENDOR_ID, USB_USBCAN2_PRODUCT_ID),

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -524,16 +524,23 @@ static void kvaser_usb_leaf_get_software_info_leaf(struct kvaser_usb *dev,
524524
dev->fw_version = le32_to_cpu(softinfo->fw_version);
525525
dev->max_tx_urbs = le16_to_cpu(softinfo->max_outstanding_tx);
526526

527-
switch (sw_options & KVASER_USB_LEAF_SWOPTION_FREQ_MASK) {
528-
case KVASER_USB_LEAF_SWOPTION_FREQ_16_MHZ_CLK:
527+
if (dev->driver_info->quirks & KVASER_USB_QUIRK_IGNORE_CLK_FREQ) {
528+
/* Firmware expects bittiming parameters calculated for 16MHz
529+
* clock, regardless of the actual clock
530+
*/
529531
dev->cfg = &kvaser_usb_leaf_dev_cfg_16mhz;
530-
break;
531-
case KVASER_USB_LEAF_SWOPTION_FREQ_24_MHZ_CLK:
532-
dev->cfg = &kvaser_usb_leaf_dev_cfg_24mhz;
533-
break;
534-
case KVASER_USB_LEAF_SWOPTION_FREQ_32_MHZ_CLK:
535-
dev->cfg = &kvaser_usb_leaf_dev_cfg_32mhz;
536-
break;
532+
} else {
533+
switch (sw_options & KVASER_USB_LEAF_SWOPTION_FREQ_MASK) {
534+
case KVASER_USB_LEAF_SWOPTION_FREQ_16_MHZ_CLK:
535+
dev->cfg = &kvaser_usb_leaf_dev_cfg_16mhz;
536+
break;
537+
case KVASER_USB_LEAF_SWOPTION_FREQ_24_MHZ_CLK:
538+
dev->cfg = &kvaser_usb_leaf_dev_cfg_24mhz;
539+
break;
540+
case KVASER_USB_LEAF_SWOPTION_FREQ_32_MHZ_CLK:
541+
dev->cfg = &kvaser_usb_leaf_dev_cfg_32mhz;
542+
break;
543+
}
537544
}
538545
}
539546

0 commit comments

Comments
 (0)