diff options
author | David S. Miller <davem@davemloft.net> | 2016-12-02 14:02:13 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-12-02 14:02:13 -0500 |
commit | f0d21e894713b43a75bdf2d1b31e587bd5db5341 (patch) | |
tree | 00bdf05d9139fba688125ece1e2cc592440b1bb7 | |
parent | 50d5aa4cf822887f88841e4d8f8502434af679a9 (diff) | |
parent | f00b534ded60bd0a23c2fa8dec4ece52aa7d235f (diff) |
Merge tag 'linux-can-fixes-for-4.9-20161201' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can
Marc Kleine-Budde says:
====================
pull-request: can 2016-12-02
this is a pull request for net/master.
There are two patches by Stephane Grosjean, who adds support for the new
PCAN-USB X6 USB interface to the pcan_usb driver.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/can/usb/peak_usb/pcan_ucan.h | 37 | ||||
-rw-r--r-- | drivers/net/can/usb/peak_usb/pcan_usb_core.c | 2 | ||||
-rw-r--r-- | drivers/net/can/usb/peak_usb/pcan_usb_core.h | 2 | ||||
-rw-r--r-- | drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 104 |
4 files changed, 121 insertions, 24 deletions
diff --git a/drivers/net/can/usb/peak_usb/pcan_ucan.h b/drivers/net/can/usb/peak_usb/pcan_ucan.h index e8fc4952c6b0..2147678f0225 100644 --- a/drivers/net/can/usb/peak_usb/pcan_ucan.h +++ b/drivers/net/can/usb/peak_usb/pcan_ucan.h | |||
@@ -43,11 +43,22 @@ struct __packed pucan_command { | |||
43 | u16 args[3]; | 43 | u16 args[3]; |
44 | }; | 44 | }; |
45 | 45 | ||
46 | #define PUCAN_TSLOW_BRP_BITS 10 | ||
47 | #define PUCAN_TSLOW_TSGEG1_BITS 8 | ||
48 | #define PUCAN_TSLOW_TSGEG2_BITS 7 | ||
49 | #define PUCAN_TSLOW_SJW_BITS 7 | ||
50 | |||
51 | #define PUCAN_TSLOW_BRP_MASK ((1 << PUCAN_TSLOW_BRP_BITS) - 1) | ||
52 | #define PUCAN_TSLOW_TSEG1_MASK ((1 << PUCAN_TSLOW_TSGEG1_BITS) - 1) | ||
53 | #define PUCAN_TSLOW_TSEG2_MASK ((1 << PUCAN_TSLOW_TSGEG2_BITS) - 1) | ||
54 | #define PUCAN_TSLOW_SJW_MASK ((1 << PUCAN_TSLOW_SJW_BITS) - 1) | ||
55 | |||
46 | /* uCAN TIMING_SLOW command fields */ | 56 | /* uCAN TIMING_SLOW command fields */ |
47 | #define PUCAN_TSLOW_SJW_T(s, t) (((s) & 0xf) | ((!!(t)) << 7)) | 57 | #define PUCAN_TSLOW_SJW_T(s, t) (((s) & PUCAN_TSLOW_SJW_MASK) | \ |
48 | #define PUCAN_TSLOW_TSEG2(t) ((t) & 0xf) | 58 | ((!!(t)) << 7)) |
49 | #define PUCAN_TSLOW_TSEG1(t) ((t) & 0x3f) | 59 | #define PUCAN_TSLOW_TSEG2(t) ((t) & PUCAN_TSLOW_TSEG2_MASK) |
50 | #define PUCAN_TSLOW_BRP(b) ((b) & 0x3ff) | 60 | #define PUCAN_TSLOW_TSEG1(t) ((t) & PUCAN_TSLOW_TSEG1_MASK) |
61 | #define PUCAN_TSLOW_BRP(b) ((b) & PUCAN_TSLOW_BRP_MASK) | ||
51 | 62 | ||
52 | struct __packed pucan_timing_slow { | 63 | struct __packed pucan_timing_slow { |
53 | __le16 opcode_channel; | 64 | __le16 opcode_channel; |
@@ -60,11 +71,21 @@ struct __packed pucan_timing_slow { | |||
60 | __le16 brp; /* BaudRate Prescaler */ | 71 | __le16 brp; /* BaudRate Prescaler */ |
61 | }; | 72 | }; |
62 | 73 | ||
74 | #define PUCAN_TFAST_BRP_BITS 10 | ||
75 | #define PUCAN_TFAST_TSGEG1_BITS 5 | ||
76 | #define PUCAN_TFAST_TSGEG2_BITS 4 | ||
77 | #define PUCAN_TFAST_SJW_BITS 4 | ||
78 | |||
79 | #define PUCAN_TFAST_BRP_MASK ((1 << PUCAN_TFAST_BRP_BITS) - 1) | ||
80 | #define PUCAN_TFAST_TSEG1_MASK ((1 << PUCAN_TFAST_TSGEG1_BITS) - 1) | ||
81 | #define PUCAN_TFAST_TSEG2_MASK ((1 << PUCAN_TFAST_TSGEG2_BITS) - 1) | ||
82 | #define PUCAN_TFAST_SJW_MASK ((1 << PUCAN_TFAST_SJW_BITS) - 1) | ||
83 | |||
63 | /* uCAN TIMING_FAST command fields */ | 84 | /* uCAN TIMING_FAST command fields */ |
64 | #define PUCAN_TFAST_SJW(s) ((s) & 0x3) | 85 | #define PUCAN_TFAST_SJW(s) ((s) & PUCAN_TFAST_SJW_MASK) |
65 | #define PUCAN_TFAST_TSEG2(t) ((t) & 0x7) | 86 | #define PUCAN_TFAST_TSEG2(t) ((t) & PUCAN_TFAST_TSEG2_MASK) |
66 | #define PUCAN_TFAST_TSEG1(t) ((t) & 0xf) | 87 | #define PUCAN_TFAST_TSEG1(t) ((t) & PUCAN_TFAST_TSEG1_MASK) |
67 | #define PUCAN_TFAST_BRP(b) ((b) & 0x3ff) | 88 | #define PUCAN_TFAST_BRP(b) ((b) & PUCAN_TFAST_BRP_MASK) |
68 | 89 | ||
69 | struct __packed pucan_timing_fast { | 90 | struct __packed pucan_timing_fast { |
70 | __le16 opcode_channel; | 91 | __le16 opcode_channel; |
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c index c06382cdfdfe..f3141ca56bc3 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c | |||
@@ -39,6 +39,7 @@ static struct usb_device_id peak_usb_table[] = { | |||
39 | {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPRO_PRODUCT_ID)}, | 39 | {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPRO_PRODUCT_ID)}, |
40 | {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBFD_PRODUCT_ID)}, | 40 | {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBFD_PRODUCT_ID)}, |
41 | {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPROFD_PRODUCT_ID)}, | 41 | {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPROFD_PRODUCT_ID)}, |
42 | {USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBX6_PRODUCT_ID)}, | ||
42 | {} /* Terminating entry */ | 43 | {} /* Terminating entry */ |
43 | }; | 44 | }; |
44 | 45 | ||
@@ -50,6 +51,7 @@ static const struct peak_usb_adapter *const peak_usb_adapters_list[] = { | |||
50 | &pcan_usb_pro, | 51 | &pcan_usb_pro, |
51 | &pcan_usb_fd, | 52 | &pcan_usb_fd, |
52 | &pcan_usb_pro_fd, | 53 | &pcan_usb_pro_fd, |
54 | &pcan_usb_x6, | ||
53 | }; | 55 | }; |
54 | 56 | ||
55 | /* | 57 | /* |
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.h b/drivers/net/can/usb/peak_usb/pcan_usb_core.h index 506fe506c9d3..3cbfb069893d 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h | |||
@@ -27,6 +27,7 @@ | |||
27 | #define PCAN_USBPRO_PRODUCT_ID 0x000d | 27 | #define PCAN_USBPRO_PRODUCT_ID 0x000d |
28 | #define PCAN_USBPROFD_PRODUCT_ID 0x0011 | 28 | #define PCAN_USBPROFD_PRODUCT_ID 0x0011 |
29 | #define PCAN_USBFD_PRODUCT_ID 0x0012 | 29 | #define PCAN_USBFD_PRODUCT_ID 0x0012 |
30 | #define PCAN_USBX6_PRODUCT_ID 0x0014 | ||
30 | 31 | ||
31 | #define PCAN_USB_DRIVER_NAME "peak_usb" | 32 | #define PCAN_USB_DRIVER_NAME "peak_usb" |
32 | 33 | ||
@@ -90,6 +91,7 @@ extern const struct peak_usb_adapter pcan_usb; | |||
90 | extern const struct peak_usb_adapter pcan_usb_pro; | 91 | extern const struct peak_usb_adapter pcan_usb_pro; |
91 | extern const struct peak_usb_adapter pcan_usb_fd; | 92 | extern const struct peak_usb_adapter pcan_usb_fd; |
92 | extern const struct peak_usb_adapter pcan_usb_pro_fd; | 93 | extern const struct peak_usb_adapter pcan_usb_pro_fd; |
94 | extern const struct peak_usb_adapter pcan_usb_x6; | ||
93 | 95 | ||
94 | struct peak_time_ref { | 96 | struct peak_time_ref { |
95 | struct timeval tv_host_0, tv_host; | 97 | struct timeval tv_host_0, tv_host; |
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c index ce44a033f63b..304732550f0a 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c | |||
@@ -993,24 +993,24 @@ static void pcan_usb_fd_free(struct peak_usb_device *dev) | |||
993 | static const struct can_bittiming_const pcan_usb_fd_const = { | 993 | static const struct can_bittiming_const pcan_usb_fd_const = { |
994 | .name = "pcan_usb_fd", | 994 | .name = "pcan_usb_fd", |
995 | .tseg1_min = 1, | 995 | .tseg1_min = 1, |
996 | .tseg1_max = 64, | 996 | .tseg1_max = (1 << PUCAN_TSLOW_TSGEG1_BITS), |
997 | .tseg2_min = 1, | 997 | .tseg2_min = 1, |
998 | .tseg2_max = 16, | 998 | .tseg2_max = (1 << PUCAN_TSLOW_TSGEG2_BITS), |
999 | .sjw_max = 16, | 999 | .sjw_max = (1 << PUCAN_TSLOW_SJW_BITS), |
1000 | .brp_min = 1, | 1000 | .brp_min = 1, |
1001 | .brp_max = 1024, | 1001 | .brp_max = (1 << PUCAN_TSLOW_BRP_BITS), |
1002 | .brp_inc = 1, | 1002 | .brp_inc = 1, |
1003 | }; | 1003 | }; |
1004 | 1004 | ||
1005 | static const struct can_bittiming_const pcan_usb_fd_data_const = { | 1005 | static const struct can_bittiming_const pcan_usb_fd_data_const = { |
1006 | .name = "pcan_usb_fd", | 1006 | .name = "pcan_usb_fd", |
1007 | .tseg1_min = 1, | 1007 | .tseg1_min = 1, |
1008 | .tseg1_max = 16, | 1008 | .tseg1_max = (1 << PUCAN_TFAST_TSGEG1_BITS), |
1009 | .tseg2_min = 1, | 1009 | .tseg2_min = 1, |
1010 | .tseg2_max = 8, | 1010 | .tseg2_max = (1 << PUCAN_TFAST_TSGEG2_BITS), |
1011 | .sjw_max = 4, | 1011 | .sjw_max = (1 << PUCAN_TFAST_SJW_BITS), |
1012 | .brp_min = 1, | 1012 | .brp_min = 1, |
1013 | .brp_max = 1024, | 1013 | .brp_max = (1 << PUCAN_TFAST_BRP_BITS), |
1014 | .brp_inc = 1, | 1014 | .brp_inc = 1, |
1015 | }; | 1015 | }; |
1016 | 1016 | ||
@@ -1065,24 +1065,24 @@ const struct peak_usb_adapter pcan_usb_fd = { | |||
1065 | static const struct can_bittiming_const pcan_usb_pro_fd_const = { | 1065 | static const struct can_bittiming_const pcan_usb_pro_fd_const = { |
1066 | .name = "pcan_usb_pro_fd", | 1066 | .name = "pcan_usb_pro_fd", |
1067 | .tseg1_min = 1, | 1067 | .tseg1_min = 1, |
1068 | .tseg1_max = 64, | 1068 | .tseg1_max = (1 << PUCAN_TSLOW_TSGEG1_BITS), |
1069 | .tseg2_min = 1, | 1069 | .tseg2_min = 1, |
1070 | .tseg2_max = 16, | 1070 | .tseg2_max = (1 << PUCAN_TSLOW_TSGEG2_BITS), |
1071 | .sjw_max = 16, | 1071 | .sjw_max = (1 << PUCAN_TSLOW_SJW_BITS), |
1072 | .brp_min = 1, | 1072 | .brp_min = 1, |
1073 | .brp_max = 1024, | 1073 | .brp_max = (1 << PUCAN_TSLOW_BRP_BITS), |
1074 | .brp_inc = 1, | 1074 | .brp_inc = 1, |
1075 | }; | 1075 | }; |
1076 | 1076 | ||
1077 | static const struct can_bittiming_const pcan_usb_pro_fd_data_const = { | 1077 | static const struct can_bittiming_const pcan_usb_pro_fd_data_const = { |
1078 | .name = "pcan_usb_pro_fd", | 1078 | .name = "pcan_usb_pro_fd", |
1079 | .tseg1_min = 1, | 1079 | .tseg1_min = 1, |
1080 | .tseg1_max = 16, | 1080 | .tseg1_max = (1 << PUCAN_TFAST_TSGEG1_BITS), |
1081 | .tseg2_min = 1, | 1081 | .tseg2_min = 1, |
1082 | .tseg2_max = 8, | 1082 | .tseg2_max = (1 << PUCAN_TFAST_TSGEG2_BITS), |
1083 | .sjw_max = 4, | 1083 | .sjw_max = (1 << PUCAN_TFAST_SJW_BITS), |
1084 | .brp_min = 1, | 1084 | .brp_min = 1, |
1085 | .brp_max = 1024, | 1085 | .brp_max = (1 << PUCAN_TFAST_BRP_BITS), |
1086 | .brp_inc = 1, | 1086 | .brp_inc = 1, |
1087 | }; | 1087 | }; |
1088 | 1088 | ||
@@ -1132,3 +1132,75 @@ const struct peak_usb_adapter pcan_usb_pro_fd = { | |||
1132 | 1132 | ||
1133 | .do_get_berr_counter = pcan_usb_fd_get_berr_counter, | 1133 | .do_get_berr_counter = pcan_usb_fd_get_berr_counter, |
1134 | }; | 1134 | }; |
1135 | |||
1136 | /* describes the PCAN-USB X6 adapter */ | ||
1137 | static const struct can_bittiming_const pcan_usb_x6_const = { | ||
1138 | .name = "pcan_usb_x6", | ||
1139 | .tseg1_min = 1, | ||
1140 | .tseg1_max = (1 << PUCAN_TSLOW_TSGEG1_BITS), | ||
1141 | .tseg2_min = 1, | ||
1142 | .tseg2_max = (1 << PUCAN_TSLOW_TSGEG2_BITS), | ||
1143 | .sjw_max = (1 << PUCAN_TSLOW_SJW_BITS), | ||
1144 | .brp_min = 1, | ||
1145 | .brp_max = (1 << PUCAN_TSLOW_BRP_BITS), | ||
1146 | .brp_inc = 1, | ||
1147 | }; | ||
1148 | |||
1149 | static const struct can_bittiming_const pcan_usb_x6_data_const = { | ||
1150 | .name = "pcan_usb_x6", | ||
1151 | .tseg1_min = 1, | ||
1152 | .tseg1_max = (1 << PUCAN_TFAST_TSGEG1_BITS), | ||
1153 | .tseg2_min = 1, | ||
1154 | .tseg2_max = (1 << PUCAN_TFAST_TSGEG2_BITS), | ||
1155 | .sjw_max = (1 << PUCAN_TFAST_SJW_BITS), | ||
1156 | .brp_min = 1, | ||
1157 | .brp_max = (1 << PUCAN_TFAST_BRP_BITS), | ||
1158 | .brp_inc = 1, | ||
1159 | }; | ||
1160 | |||
1161 | const struct peak_usb_adapter pcan_usb_x6 = { | ||
1162 | .name = "PCAN-USB X6", | ||
1163 | .device_id = PCAN_USBX6_PRODUCT_ID, | ||
1164 | .ctrl_count = PCAN_USBPROFD_CHANNEL_COUNT, | ||
1165 | .ctrlmode_supported = CAN_CTRLMODE_FD | | ||
1166 | CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, | ||
1167 | .clock = { | ||
1168 | .freq = PCAN_UFD_CRYSTAL_HZ, | ||
1169 | }, | ||
1170 | .bittiming_const = &pcan_usb_x6_const, | ||
1171 | .data_bittiming_const = &pcan_usb_x6_data_const, | ||
1172 | |||
1173 | /* size of device private data */ | ||
1174 | .sizeof_dev_private = sizeof(struct pcan_usb_fd_device), | ||
1175 | |||
1176 | /* timestamps usage */ | ||
1177 | .ts_used_bits = 32, | ||
1178 | .ts_period = 1000000, /* calibration period in ts. */ | ||
1179 | .us_per_ts_scale = 1, /* us = (ts * scale) >> shift */ | ||
1180 | .us_per_ts_shift = 0, | ||
1181 | |||
1182 | /* give here messages in/out endpoints */ | ||
1183 | .ep_msg_in = PCAN_USBPRO_EP_MSGIN, | ||
1184 | .ep_msg_out = {PCAN_USBPRO_EP_MSGOUT_0, PCAN_USBPRO_EP_MSGOUT_1}, | ||
1185 | |||
1186 | /* size of rx/tx usb buffers */ | ||
1187 | .rx_buffer_size = PCAN_UFD_RX_BUFFER_SIZE, | ||
1188 | .tx_buffer_size = PCAN_UFD_TX_BUFFER_SIZE, | ||
1189 | |||
1190 | /* device callbacks */ | ||
1191 | .intf_probe = pcan_usb_pro_probe, /* same as PCAN-USB Pro */ | ||
1192 | .dev_init = pcan_usb_fd_init, | ||
1193 | |||
1194 | .dev_exit = pcan_usb_fd_exit, | ||
1195 | .dev_free = pcan_usb_fd_free, | ||
1196 | .dev_set_bus = pcan_usb_fd_set_bus, | ||
1197 | .dev_set_bittiming = pcan_usb_fd_set_bittiming_slow, | ||
1198 | .dev_set_data_bittiming = pcan_usb_fd_set_bittiming_fast, | ||
1199 | .dev_decode_buf = pcan_usb_fd_decode_buf, | ||
1200 | .dev_start = pcan_usb_fd_start, | ||
1201 | .dev_stop = pcan_usb_fd_stop, | ||
1202 | .dev_restart_async = pcan_usb_fd_restart_async, | ||
1203 | .dev_encode_msg = pcan_usb_fd_encode_msg, | ||
1204 | |||
1205 | .do_get_berr_counter = pcan_usb_fd_get_berr_counter, | ||
1206 | }; | ||