aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/can
diff options
context:
space:
mode:
authorStephane Grosjean <s.grosjean@peak-system.com>2017-01-19 10:31:06 -0500
committerMarc Kleine-Budde <mkl@pengutronix.de>2017-04-25 03:00:44 -0400
commitc3df7c5755ee1a53cd56a4efcf3426334ab9eea4 (patch)
tree454139fd3dfdd4cfc93a2efa316faeb40f28657b /include/linux/can
parent113ab88b2b689b431904e1d753e20390529ed204 (diff)
can: peak: move header file to new can common subdir
The CAN-FD IP from PEAK-System runs into several kinds of PC CAN-FD interfaces. Up to now, only the USB CAN-FD adapters were supported by the Kernel. In order to prepare the adding of some new non-USB CAN-FD interfaces, this patch moves - and rename - the IP definitions file from its private (usb) sub-directory into a - newly created - CAN specific one. Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'include/linux/can')
-rw-r--r--include/linux/can/dev/peak_canfd.h243
1 files changed, 243 insertions, 0 deletions
diff --git a/include/linux/can/dev/peak_canfd.h b/include/linux/can/dev/peak_canfd.h
new file mode 100644
index 000000000000..25e20ef2fef8
--- /dev/null
+++ b/include/linux/can/dev/peak_canfd.h
@@ -0,0 +1,243 @@
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 <s.grosjean@peak-system.com>
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_SET_EN_OPTION 0x00b
30#define PUCAN_CMD_CLR_DIS_OPTION 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 */
41struct __packed pucan_command {
42 __le16 opcode_channel;
43 u16 args[3];
44};
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
56/* uCAN TIMING_SLOW command fields */
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)
62
63struct __packed pucan_timing_slow {
64 __le16 opcode_channel;
65
66 u8 ewl; /* Error Warning limit */
67 u8 sjw_t; /* Sync Jump Width + Triple sampling */
68 u8 tseg2; /* Timing SEGment 2 */
69 u8 tseg1; /* Timing SEGment 1 */
70
71 __le16 brp; /* BaudRate Prescaler */
72};
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
84/* uCAN TIMING_FAST command fields */
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)
89
90struct __packed pucan_timing_fast {
91 __le16 opcode_channel;
92
93 u8 unused;
94 u8 sjw; /* Sync Jump Width */
95 u8 tseg2; /* Timing SEGment 2 */
96 u8 tseg1; /* Timing SEGment 1 */
97
98 __le16 brp; /* BaudRate Prescaler */
99};
100
101/* uCAN FILTER_STD command fields */
102#define PUCAN_FLTSTD_ROW_IDX_BITS 6
103
104struct __packed pucan_filter_std {
105 __le16 opcode_channel;
106
107 __le16 idx;
108 __le32 mask; /* CAN-ID bitmask in idx range */
109};
110
111/* uCAN WR_ERR_CNT command fields */
112#define PUCAN_WRERRCNT_TE 0x4000 /* Tx error cntr write Enable */
113#define PUCAN_WRERRCNT_RE 0x8000 /* Rx error cntr write Enable */
114
115struct __packed pucan_wr_err_cnt {
116 __le16 opcode_channel;
117
118 __le16 sel_mask;
119 u8 tx_counter; /* Tx error counter new value */
120 u8 rx_counter; /* Rx error counter new value */
121
122 u16 unused;
123};
124
125/* uCAN SET_EN/CLR_DIS _OPTION command fields */
126#define PUCAN_OPTION_ERROR 0x0001
127#define PUCAN_OPTION_BUSLOAD 0x0002
128#define PUCAN_OPTION_CANDFDISO 0x0004
129
130struct __packed pucan_options {
131 __le16 opcode_channel;
132
133 __le16 options;
134 u32 unused;
135};
136
137/* uCAN received messages global format */
138struct __packed pucan_msg {
139 __le16 size;
140 __le16 type;
141 __le32 ts_low;
142 __le32 ts_high;
143};
144
145/* uCAN flags for CAN/CANFD messages */
146#define PUCAN_MSG_SELF_RECEIVE 0x80
147#define PUCAN_MSG_ERROR_STATE_IND 0x40 /* error state indicator */
148#define PUCAN_MSG_BITRATE_SWITCH 0x20 /* bitrate switch */
149#define PUCAN_MSG_EXT_DATA_LEN 0x10 /* extended data length */
150#define PUCAN_MSG_SINGLE_SHOT 0x08
151#define PUCAN_MSG_LOOPED_BACK 0x04
152#define PUCAN_MSG_EXT_ID 0x02
153#define PUCAN_MSG_RTR 0x01
154
155struct __packed pucan_rx_msg {
156 __le16 size;
157 __le16 type;
158 __le32 ts_low;
159 __le32 ts_high;
160 __le32 tag_low;
161 __le32 tag_high;
162 u8 channel_dlc;
163 u8 client;
164 __le16 flags;
165 __le32 can_id;
166 u8 d[0];
167};
168
169/* uCAN error types */
170#define PUCAN_ERMSG_BIT_ERROR 0
171#define PUCAN_ERMSG_FORM_ERROR 1
172#define PUCAN_ERMSG_STUFF_ERROR 2
173#define PUCAN_ERMSG_OTHER_ERROR 3
174#define PUCAN_ERMSG_ERR_CNT_DEC 4
175
176struct __packed pucan_error_msg {
177 __le16 size;
178 __le16 type;
179 __le32 ts_low;
180 __le32 ts_high;
181 u8 channel_type_d;
182 u8 code_g;
183 u8 tx_err_cnt;
184 u8 rx_err_cnt;
185};
186
187#define PUCAN_BUS_PASSIVE 0x20
188#define PUCAN_BUS_WARNING 0x40
189#define PUCAN_BUS_BUSOFF 0x80
190
191struct __packed pucan_status_msg {
192 __le16 size;
193 __le16 type;
194 __le32 ts_low;
195 __le32 ts_high;
196 u8 channel_p_w_b;
197 u8 unused[3];
198};
199
200/* uCAN transmitted message format */
201#define PUCAN_MSG_CHANNEL_DLC(c, d) (((c) & 0xf) | ((d) << 4))
202
203struct __packed pucan_tx_msg {
204 __le16 size;
205 __le16 type;
206 __le32 tag_low;
207 __le32 tag_high;
208 u8 channel_dlc;
209 u8 client;
210 __le16 flags;
211 __le32 can_id;
212 u8 d[0];
213};
214
215/* build the cmd opcode_channel field with respect to the correct endianness */
216static inline __le16 pucan_cmd_opcode_channel(int index, int opcode)
217{
218 return cpu_to_le16(((index) << 12) | ((opcode) & 0x3ff));
219}
220
221/* return the channel number part from any received message channel_dlc field */
222static inline int pucan_msg_get_channel(const struct pucan_rx_msg *msg)
223{
224 return msg->channel_dlc & 0xf;
225}
226
227/* return the dlc value from any received message channel_dlc field */
228static inline int pucan_msg_get_dlc(const struct pucan_rx_msg *msg)
229{
230 return msg->channel_dlc >> 4;
231}
232
233static inline int pucan_ermsg_get_channel(const struct pucan_error_msg *msg)
234{
235 return msg->channel_type_d & 0x0f;
236}
237
238static inline int pucan_stmsg_get_channel(const struct pucan_status_msg *msg)
239{
240 return msg->channel_p_w_b & 0x0f;
241}
242
243#endif