Skip to content

Commit 0a25e1f

Browse files
Stephane Grosjeanmarckleinebudde
authored andcommitted
can: peak_usb: add support for PEAK new CANFD USB adapters
Add support for the following new PEAK-System technik CANFD USB adapters: PCAN-USB FD single CANFD channel USB adapter PCAN-USB Pro FD dual CANFD channels USB adapter Signed-off-by: Stephane Grosjean <[email protected]> Signed-off-by: Oliver Hartkopp <[email protected]> Acked-by: Andri Yngvason <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent faa233d commit 0a25e1f

File tree

6 files changed

+1337
-4
lines changed

6 files changed

+1337
-4
lines changed

drivers/net/can/usb/Kconfig

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,18 @@ config CAN_KVASER_USB
5959
module will be called kvaser_usb.
6060

6161
config CAN_PEAK_USB
62-
tristate "PEAK PCAN-USB/USB Pro interfaces"
62+
tristate "PEAK PCAN-USB/USB Pro interfaces for CAN 2.0b/CAN-FD"
6363
---help---
64-
This driver supports the PCAN-USB and PCAN-USB Pro adapters
65-
from PEAK-System Technik (http://www.peak-system.com).
64+
This driver supports the PEAK-System Technik USB adapters that enable
65+
access to the CAN bus, with repect to the CAN 2.0b and/or CAN-FD
66+
standards, that is:
67+
68+
PCAN-USB single CAN 2.0b channel USB adapter
69+
PCAN-USB Pro dual CAN 2.0b channels USB adapter
70+
PCAN-USB FD single CAN-FD channel USB adapter
71+
PCAN-USB Pro FD dual CAN-FD channels USB adapter
72+
73+
(see also http://www.peak-system.com).
6674

6775
config CAN_8DEV_USB
6876
tristate "8 devices USB2CAN interface"

drivers/net/can/usb/peak_usb/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
obj-$(CONFIG_CAN_PEAK_USB) += peak_usb.o
2-
peak_usb-y = pcan_usb_core.o pcan_usb.o pcan_usb_pro.o
2+
peak_usb-y = pcan_usb_core.o pcan_usb.o pcan_usb_pro.o pcan_usb_fd.o
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/*
2+
* CAN driver for PEAK System micro-CAN based adapters
3+
*
4+
* Copyright (C) 2003-2011 PEAK System-Technik GmbH
5+
* Copyright (C) 2011-2013 Stephane Grosjean <[email protected]>
6+
*
7+
* This program is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU General Public License as published
9+
* by the Free Software Foundation; version 2 of the License.
10+
*
11+
* This program is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* General Public License for more details.
15+
*/
16+
#ifndef PUCAN_H
17+
#define PUCAN_H
18+
19+
/* uCAN commands opcodes list (low-order 10 bits) */
20+
#define PUCAN_CMD_NOP 0x000
21+
#define PUCAN_CMD_RESET_MODE 0x001
22+
#define PUCAN_CMD_NORMAL_MODE 0x002
23+
#define PUCAN_CMD_LISTEN_ONLY_MODE 0x003
24+
#define PUCAN_CMD_TIMING_SLOW 0x004
25+
#define PUCAN_CMD_TIMING_FAST 0x005
26+
#define PUCAN_CMD_FILTER_STD 0x008
27+
#define PUCAN_CMD_TX_ABORT 0x009
28+
#define PUCAN_CMD_WR_ERR_CNT 0x00a
29+
#define PUCAN_CMD_RX_FRAME_ENABLE 0x00b
30+
#define PUCAN_CMD_RX_FRAME_DISABLE 0x00c
31+
#define PUCAN_CMD_END_OF_COLLECTION 0x3ff
32+
33+
/* uCAN received messages list */
34+
#define PUCAN_MSG_CAN_RX 0x0001
35+
#define PUCAN_MSG_ERROR 0x0002
36+
#define PUCAN_MSG_STATUS 0x0003
37+
#define PUCAN_MSG_BUSLOAD 0x0004
38+
#define PUCAN_MSG_CAN_TX 0x1000
39+
40+
/* uCAN command common header */
41+
struct __packed pucan_command {
42+
__le16 opcode_channel;
43+
u16 args[3];
44+
};
45+
46+
/* 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)
51+
52+
struct __packed pucan_timing_slow {
53+
__le16 opcode_channel;
54+
55+
u8 ewl; /* Error Warning limit */
56+
u8 sjw_t; /* Sync Jump Width + Triple sampling */
57+
u8 tseg2; /* Timing SEGment 2 */
58+
u8 tseg1; /* Timing SEGment 1 */
59+
60+
__le16 brp; /* BaudRate Prescaler */
61+
};
62+
63+
/* 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)
68+
69+
struct __packed pucan_timing_fast {
70+
__le16 opcode_channel;
71+
72+
u8 unused;
73+
u8 sjw; /* Sync Jump Width */
74+
u8 tseg2; /* Timing SEGment 2 */
75+
u8 tseg1; /* Timing SEGment 1 */
76+
77+
__le16 brp; /* BaudRate Prescaler */
78+
};
79+
80+
/* uCAN FILTER_STD command fields */
81+
#define PUCAN_FLTSTD_ROW_IDX_BITS 6
82+
83+
struct __packed pucan_filter_std {
84+
__le16 opcode_channel;
85+
86+
__le16 idx;
87+
__le32 mask; /* CAN-ID bitmask in idx range */
88+
};
89+
90+
/* uCAN WR_ERR_CNT command fields */
91+
#define PUCAN_WRERRCNT_TE 0x4000 /* Tx error cntr write Enable */
92+
#define PUCAN_WRERRCNT_RE 0x8000 /* Rx error cntr write Enable */
93+
94+
struct __packed pucan_wr_err_cnt {
95+
__le16 opcode_channel;
96+
97+
__le16 sel_mask;
98+
u8 tx_counter; /* Tx error counter new value */
99+
u8 rx_counter; /* Rx error counter new value */
100+
101+
u16 unused;
102+
};
103+
104+
/* uCAN RX_FRAME_ENABLE command fields */
105+
#define PUCAN_FLTEXT_ERROR 0x0001
106+
#define PUCAN_FLTEXT_BUSLOAD 0x0002
107+
108+
struct __packed pucan_filter_ext {
109+
__le16 opcode_channel;
110+
111+
__le16 ext_mask;
112+
u32 unused;
113+
};
114+
115+
/* uCAN received messages global format */
116+
struct __packed pucan_msg {
117+
__le16 size;
118+
__le16 type;
119+
__le32 ts_low;
120+
__le32 ts_high;
121+
};
122+
123+
/* uCAN flags for CAN/CANFD messages */
124+
#define PUCAN_MSG_SELF_RECEIVE 0x80
125+
#define PUCAN_MSG_ERROR_STATE_IND 0x40 /* error state indicator */
126+
#define PUCAN_MSG_BITRATE_SWITCH 0x20 /* bitrate switch */
127+
#define PUCAN_MSG_EXT_DATA_LEN 0x10 /* extended data length */
128+
#define PUCAN_MSG_SINGLE_SHOT 0x08
129+
#define PUCAN_MSG_LOOPED_BACK 0x04
130+
#define PUCAN_MSG_EXT_ID 0x02
131+
#define PUCAN_MSG_RTR 0x01
132+
133+
struct __packed pucan_rx_msg {
134+
__le16 size;
135+
__le16 type;
136+
__le32 ts_low;
137+
__le32 ts_high;
138+
__le32 tag_low;
139+
__le32 tag_high;
140+
u8 channel_dlc;
141+
u8 client;
142+
__le16 flags;
143+
__le32 can_id;
144+
u8 d[0];
145+
};
146+
147+
/* uCAN error types */
148+
#define PUCAN_ERMSG_BIT_ERROR 0
149+
#define PUCAN_ERMSG_FORM_ERROR 1
150+
#define PUCAN_ERMSG_STUFF_ERROR 2
151+
#define PUCAN_ERMSG_OTHER_ERROR 3
152+
#define PUCAN_ERMSG_ERR_CNT_DEC 4
153+
154+
struct __packed pucan_error_msg {
155+
__le16 size;
156+
__le16 type;
157+
__le32 ts_low;
158+
__le32 ts_high;
159+
u8 channel_type_d;
160+
u8 code_g;
161+
u8 tx_err_cnt;
162+
u8 rx_err_cnt;
163+
};
164+
165+
#define PUCAN_BUS_PASSIVE 0x20
166+
#define PUCAN_BUS_WARNING 0x40
167+
#define PUCAN_BUS_BUSOFF 0x80
168+
169+
struct __packed pucan_status_msg {
170+
__le16 size;
171+
__le16 type;
172+
__le32 ts_low;
173+
__le32 ts_high;
174+
u8 channel_p_w_b;
175+
u8 unused[3];
176+
};
177+
178+
/* uCAN transmitted message format */
179+
#define PUCAN_MSG_CHANNEL_DLC(c, d) (((c) & 0xf) | ((d) << 4))
180+
181+
struct __packed pucan_tx_msg {
182+
__le16 size;
183+
__le16 type;
184+
__le32 tag_low;
185+
__le32 tag_high;
186+
u8 channel_dlc;
187+
u8 client;
188+
__le16 flags;
189+
__le32 can_id;
190+
u8 d[0];
191+
};
192+
193+
/* build the cmd opcode_channel field with respect to the correct endianness */
194+
static inline __le16 pucan_cmd_opcode_channel(struct peak_usb_device *dev,
195+
int opcode)
196+
{
197+
return cpu_to_le16(((dev->ctrl_idx) << 12) | ((opcode) & 0x3ff));
198+
}
199+
200+
/* return the channel number part from any received message channel_dlc field */
201+
static inline int pucan_msg_get_channel(struct pucan_rx_msg *rm)
202+
{
203+
return rm->channel_dlc & 0xf;
204+
}
205+
206+
/* return the dlc value from any received message channel_dlc field */
207+
static inline int pucan_msg_get_dlc(struct pucan_rx_msg *rm)
208+
{
209+
return rm->channel_dlc >> 4;
210+
}
211+
212+
static inline int pucan_ermsg_get_channel(struct pucan_error_msg *em)
213+
{
214+
return em->channel_type_d & 0x0f;
215+
}
216+
217+
static inline int pucan_stmsg_get_channel(struct pucan_status_msg *sm)
218+
{
219+
return sm->channel_p_w_b & 0x0f;
220+
}
221+
222+
#endif

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ MODULE_LICENSE("GPL v2");
3737
static struct usb_device_id peak_usb_table[] = {
3838
{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USB_PRODUCT_ID)},
3939
{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPRO_PRODUCT_ID)},
40+
{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBFD_PRODUCT_ID)},
41+
{USB_DEVICE(PCAN_USB_VENDOR_ID, PCAN_USBPROFD_PRODUCT_ID)},
4042
{} /* Terminating entry */
4143
};
4244

@@ -46,6 +48,8 @@ MODULE_DEVICE_TABLE(usb, peak_usb_table);
4648
static const struct peak_usb_adapter *const peak_usb_adapters_list[] = {
4749
&pcan_usb,
4850
&pcan_usb_pro,
51+
&pcan_usb_fd,
52+
&pcan_usb_pro_fd,
4953
};
5054

5155
/*

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
/* supported device ids. */
2626
#define PCAN_USB_PRODUCT_ID 0x000c
2727
#define PCAN_USBPRO_PRODUCT_ID 0x000d
28+
#define PCAN_USBPROFD_PRODUCT_ID 0x0011
29+
#define PCAN_USBFD_PRODUCT_ID 0x0012
2830

2931
#define PCAN_USB_DRIVER_NAME "peak_usb"
3032

@@ -86,6 +88,8 @@ struct peak_usb_adapter {
8688

8789
extern const struct peak_usb_adapter pcan_usb;
8890
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_pro_fd;
8993

9094
struct peak_time_ref {
9195
struct timeval tv_host_0, tv_host;

0 commit comments

Comments
 (0)