Add hardware timestamp support for all usbcan based devices (M16C). The usbcan firmware is slightly different compared to the other Kvaser USB interfaces: - The timestamp is provided by a 32-bit counter, with 10us resolution. Hence, the hardware timestamp will wrap after less than 12 hours. - Each Rx CAN or Tx ACK command only contains the 16-bits LSB of the timestamp counter. - The 16-bits MSB are sent in an asynchronous event (command), if any change occurred in the MSB since the last event. Signed-off-by: Jimmy Assarsson <extja@xxxxxxxxxx> --- drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c | 3 ++- drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c index b5d762d38d5d..576ddf932f47 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c @@ -100,7 +100,8 @@ static const struct kvaser_usb_driver_info kvaser_usb_driver_info_hydra = { static const struct kvaser_usb_driver_info kvaser_usb_driver_info_usbcan = { .quirks = KVASER_USB_QUIRK_HAS_TXRX_ERRORS | - KVASER_USB_QUIRK_HAS_SILENT_MODE, + KVASER_USB_QUIRK_HAS_SILENT_MODE | + KVASER_USB_QUIRK_HAS_HARDWARE_TIMESTAMP, .family = KVASER_USBCAN, .ops = &kvaser_usb_leaf_dev_ops, }; diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c index 9b75f240485d..26227a4ed580 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c @@ -121,6 +121,7 @@ /* USBCanII timestamp */ #define KVASER_USB_USBCAN_CLK_OVERFLOW_MASK GENMASK(31, 16) +#define KVASER_USB_USBCAN_TIMESTAMP_FACTOR 10 struct kvaser_cmd_simple { u8 tid; @@ -980,6 +981,9 @@ static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev, ticks += (u64)(le16_to_cpu(cmd->u.leaf.tx_ack.time[2])) << 32; break; case KVASER_USBCAN: + ticks = le16_to_cpu(cmd->u.usbcan.tx_ack.time); + ticks += dev->card_data.usbcan_timestamp_msb; + ticks = ticks * KVASER_USB_USBCAN_TIMESTAMP_FACTOR; break; } @@ -1402,6 +1406,9 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev, break; case KVASER_USBCAN: rx_data = cmd->u.usbcan.rx_can.data; + ticks = le16_to_cpu(cmd->u.usbcan.rx_can.time); + ticks += dev->card_data.usbcan_timestamp_msb; + ticks = ticks * KVASER_USB_USBCAN_TIMESTAMP_FACTOR; break; } -- 2.45.2