Skip to content

Commit f0d21e8

Browse files
committed
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>
2 parents 50d5aa4 + f00b534 commit f0d21e8

4 files changed

Lines changed: 121 additions & 24 deletions

File tree

drivers/net/can/usb/peak_usb/pcan_ucan.h

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,22 @@ struct __packed pucan_command {
4343
u16 args[3];
4444
};
4545

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+
4656
/* uCAN TIMING_SLOW command fields */
47-
#define PUCAN_TSLOW_SJW_T(s, t) (((s) & 0xf) | ((!!(t)) << 7))
48-
#define PUCAN_TSLOW_TSEG2(t) ((t) & 0xf)
49-
#define PUCAN_TSLOW_TSEG1(t) ((t) & 0x3f)
50-
#define PUCAN_TSLOW_BRP(b) ((b) & 0x3ff)
57+
#define PUCAN_TSLOW_SJW_T(s, t) (((s) & PUCAN_TSLOW_SJW_MASK) | \
58+
((!!(t)) << 7))
59+
#define PUCAN_TSLOW_TSEG2(t) ((t) & PUCAN_TSLOW_TSEG2_MASK)
60+
#define PUCAN_TSLOW_TSEG1(t) ((t) & PUCAN_TSLOW_TSEG1_MASK)
61+
#define PUCAN_TSLOW_BRP(b) ((b) & PUCAN_TSLOW_BRP_MASK)
5162

5263
struct __packed pucan_timing_slow {
5364
__le16 opcode_channel;
@@ -60,11 +71,21 @@ struct __packed pucan_timing_slow {
6071
__le16 brp; /* BaudRate Prescaler */
6172
};
6273

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+
6384
/* uCAN TIMING_FAST command fields */
64-
#define PUCAN_TFAST_SJW(s) ((s) & 0x3)
65-
#define PUCAN_TFAST_TSEG2(t) ((t) & 0x7)
66-
#define PUCAN_TFAST_TSEG1(t) ((t) & 0xf)
67-
#define PUCAN_TFAST_BRP(b) ((b) & 0x3ff)
85+
#define PUCAN_TFAST_SJW(s) ((s) & PUCAN_TFAST_SJW_MASK)
86+
#define PUCAN_TFAST_TSEG2(t) ((t) & PUCAN_TFAST_TSEG2_MASK)
87+
#define PUCAN_TFAST_TSEG1(t) ((t) & PUCAN_TFAST_TSEG1_MASK)
88+
#define PUCAN_TFAST_BRP(b) ((b) & PUCAN_TFAST_BRP_MASK)
6889

6990
struct __packed pucan_timing_fast {
7091
__le16 opcode_channel;

drivers/net/can/usb/peak_usb/pcan_usb_core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static struct usb_device_id peak_usb_table[] = {
3939
{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPRO_PRODUCT_ID)},
4040
{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBFD_PRODUCT_ID)},
4141
{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPROFD_PRODUCT_ID)},
42+
{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBX6_PRODUCT_ID)},
4243
{} /* Terminating entry */
4344
};
4445

@@ -50,6 +51,7 @@ static const struct peak_usb_adapter *const peak_usb_adapters_list[] = {
5051
&pcan_usb_pro,
5152
&pcan_usb_fd,
5253
&pcan_usb_pro_fd,
54+
&pcan_usb_x6,
5355
};
5456

5557
/*

drivers/net/can/usb/peak_usb/pcan_usb_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define PCAN_USBPRO_PRODUCT_ID 0x000d
2828
#define PCAN_USBPROFD_PRODUCT_ID 0x0011
2929
#define PCAN_USBFD_PRODUCT_ID 0x0012
30+
#define PCAN_USBX6_PRODUCT_ID 0x0014
3031

3132
#define PCAN_USB_DRIVER_NAME "peak_usb"
3233

@@ -90,6 +91,7 @@ extern const struct peak_usb_adapter pcan_usb;
9091
extern const struct peak_usb_adapter pcan_usb_pro;
9192
extern const struct peak_usb_adapter pcan_usb_fd;
9293
extern const struct peak_usb_adapter pcan_usb_pro_fd;
94+
extern const struct peak_usb_adapter pcan_usb_x6;
9395

9496
struct peak_time_ref {
9597
struct timeval tv_host_0, tv_host;

drivers/net/can/usb/peak_usb/pcan_usb_fd.c

Lines changed: 88 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -993,24 +993,24 @@ static void pcan_usb_fd_free(struct peak_usb_device *dev)
993993
static const struct can_bittiming_const pcan_usb_fd_const = {
994994
.name = "pcan_usb_fd",
995995
.tseg1_min = 1,
996-
.tseg1_max = 64,
996+
.tseg1_max = (1 << PUCAN_TSLOW_TSGEG1_BITS),
997997
.tseg2_min = 1,
998-
.tseg2_max = 16,
999-
.sjw_max = 16,
998+
.tseg2_max = (1 << PUCAN_TSLOW_TSGEG2_BITS),
999+
.sjw_max = (1 << PUCAN_TSLOW_SJW_BITS),
10001000
.brp_min = 1,
1001-
.brp_max = 1024,
1001+
.brp_max = (1 << PUCAN_TSLOW_BRP_BITS),
10021002
.brp_inc = 1,
10031003
};
10041004

10051005
static const struct can_bittiming_const pcan_usb_fd_data_const = {
10061006
.name = "pcan_usb_fd",
10071007
.tseg1_min = 1,
1008-
.tseg1_max = 16,
1008+
.tseg1_max = (1 << PUCAN_TFAST_TSGEG1_BITS),
10091009
.tseg2_min = 1,
1010-
.tseg2_max = 8,
1011-
.sjw_max = 4,
1010+
.tseg2_max = (1 << PUCAN_TFAST_TSGEG2_BITS),
1011+
.sjw_max = (1 << PUCAN_TFAST_SJW_BITS),
10121012
.brp_min = 1,
1013-
.brp_max = 1024,
1013+
.brp_max = (1 << PUCAN_TFAST_BRP_BITS),
10141014
.brp_inc = 1,
10151015
};
10161016

@@ -1065,24 +1065,24 @@ const struct peak_usb_adapter pcan_usb_fd = {
10651065
static const struct can_bittiming_const pcan_usb_pro_fd_const = {
10661066
.name = "pcan_usb_pro_fd",
10671067
.tseg1_min = 1,
1068-
.tseg1_max = 64,
1068+
.tseg1_max = (1 << PUCAN_TSLOW_TSGEG1_BITS),
10691069
.tseg2_min = 1,
1070-
.tseg2_max = 16,
1071-
.sjw_max = 16,
1070+
.tseg2_max = (1 << PUCAN_TSLOW_TSGEG2_BITS),
1071+
.sjw_max = (1 << PUCAN_TSLOW_SJW_BITS),
10721072
.brp_min = 1,
1073-
.brp_max = 1024,
1073+
.brp_max = (1 << PUCAN_TSLOW_BRP_BITS),
10741074
.brp_inc = 1,
10751075
};
10761076

10771077
static const struct can_bittiming_const pcan_usb_pro_fd_data_const = {
10781078
.name = "pcan_usb_pro_fd",
10791079
.tseg1_min = 1,
1080-
.tseg1_max = 16,
1080+
.tseg1_max = (1 << PUCAN_TFAST_TSGEG1_BITS),
10811081
.tseg2_min = 1,
1082-
.tseg2_max = 8,
1083-
.sjw_max = 4,
1082+
.tseg2_max = (1 << PUCAN_TFAST_TSGEG2_BITS),
1083+
.sjw_max = (1 << PUCAN_TFAST_SJW_BITS),
10841084
.brp_min = 1,
1085-
.brp_max = 1024,
1085+
.brp_max = (1 << PUCAN_TFAST_BRP_BITS),
10861086
.brp_inc = 1,
10871087
};
10881088

@@ -1132,3 +1132,75 @@ const struct peak_usb_adapter pcan_usb_pro_fd = {
11321132

11331133
.do_get_berr_counter = pcan_usb_fd_get_berr_counter,
11341134
};
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+
};

0 commit comments

Comments
 (0)