1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * CAN driver for PEAK System PCAN-USB Pro adapter
4  * Derived from the PCAN project file driver/src/pcan_usbpro_fw.h
5  *
6  * Copyright (C) 2003-2011 PEAK System-Technik GmbH
7  * Copyright (C) 2011-2012 Stephane Grosjean <s.grosjean@peak-system.com>
8  */
9 #ifndef PCAN_USB_PRO_H
10 #define PCAN_USB_PRO_H
11 
12 /*
13  * USB Vendor request data types
14  */
15 #define PCAN_USBPRO_REQ_INFO		0
16 #define PCAN_USBPRO_REQ_FCT		2
17 
18 /* Vendor Request value for XXX_INFO */
19 #define PCAN_USBPRO_INFO_BL		0
20 #define PCAN_USBPRO_INFO_FW		1
21 
22 /* PCAN-USB Pro (FD) Endpoints */
23 #define PCAN_USBPRO_EP_CMDOUT		1
24 #define PCAN_USBPRO_EP_CMDIN		(PCAN_USBPRO_EP_CMDOUT | USB_DIR_IN)
25 #define PCAN_USBPRO_EP_MSGOUT_0		2
26 #define PCAN_USBPRO_EP_MSGIN		(PCAN_USBPRO_EP_MSGOUT_0 | USB_DIR_IN)
27 #define PCAN_USBPRO_EP_MSGOUT_1		3
28 #define PCAN_USBPRO_EP_UNUSED		(PCAN_USBPRO_EP_MSGOUT_1 | USB_DIR_IN)
29 
30 /* Vendor Request value for XXX_FCT */
31 #define PCAN_USBPRO_FCT_DRVLD		5 /* tell device driver is loaded */
32 #define PCAN_USBPRO_FCT_DRVLD_REQ_LEN	16
33 
34 /* PCAN_USBPRO_INFO_BL vendor request record type */
35 struct __packed pcan_usb_pro_blinfo {
36 	__le32 ctrl_type;
37 	u8 version[4];
38 	u8 day;
39 	u8 month;
40 	u8 year;
41 	u8 dummy;
42 	__le32 serial_num_hi;
43 	__le32 serial_num_lo;
44 	__le32 hw_type;
45 	__le32 hw_rev;
46 };
47 
48 /* PCAN_USBPRO_INFO_FW vendor request record type */
49 struct __packed pcan_usb_pro_fwinfo {
50 	__le32 ctrl_type;
51 	u8 version[4];
52 	u8 day;
53 	u8 month;
54 	u8 year;
55 	u8 dummy;
56 	__le32 fw_type;
57 };
58 
59 /*
60  * USB Command record types
61  */
62 #define PCAN_USBPRO_SETBTR	0x02
63 #define PCAN_USBPRO_SETBUSACT	0x04
64 #define PCAN_USBPRO_SETSILENT	0x05
65 #define PCAN_USBPRO_SETFILTR	0x0a
66 #define PCAN_USBPRO_SETTS	0x10
67 #define PCAN_USBPRO_GETDEVID	0x12
68 #define PCAN_USBPRO_SETLED	0x1C
69 #define PCAN_USBPRO_RXMSG8	0x80
70 #define PCAN_USBPRO_RXMSG4	0x81
71 #define PCAN_USBPRO_RXMSG0	0x82
72 #define PCAN_USBPRO_RXRTR	0x83
73 #define PCAN_USBPRO_RXSTATUS	0x84
74 #define PCAN_USBPRO_RXTS	0x85
75 #define PCAN_USBPRO_TXMSG8	0x41
76 #define PCAN_USBPRO_TXMSG4	0x42
77 #define PCAN_USBPRO_TXMSG0	0x43
78 
79 /* record structures */
80 struct __packed pcan_usb_pro_btr {
81 	u8 data_type;
82 	u8 channel;
83 	__le16 dummy;
84 	__le32 CCBT;
85 };
86 
87 struct __packed pcan_usb_pro_busact {
88 	u8 data_type;
89 	u8 channel;
90 	__le16 onoff;
91 };
92 
93 struct __packed pcan_usb_pro_silent {
94 	u8 data_type;
95 	u8 channel;
96 	__le16 onoff;
97 };
98 
99 struct __packed pcan_usb_pro_filter {
100 	u8 data_type;
101 	u8 dummy;
102 	__le16 filter_mode;
103 };
104 
105 struct __packed pcan_usb_pro_setts {
106 	u8 data_type;
107 	u8 dummy;
108 	__le16 mode;
109 };
110 
111 struct __packed pcan_usb_pro_devid {
112 	u8 data_type;
113 	u8 channel;
114 	__le16 dummy;
115 	__le32 dev_num;
116 };
117 
118 #define PCAN_USBPRO_LED_DEVICE		0x00
119 #define PCAN_USBPRO_LED_BLINK_FAST	0x01
120 #define PCAN_USBPRO_LED_BLINK_SLOW	0x02
121 #define PCAN_USBPRO_LED_ON		0x03
122 #define PCAN_USBPRO_LED_OFF		0x04
123 
124 struct __packed pcan_usb_pro_setled {
125 	u8 data_type;
126 	u8 channel;
127 	__le16 mode;
128 	__le32 timeout;
129 };
130 
131 struct __packed pcan_usb_pro_rxmsg {
132 	u8 data_type;
133 	u8 client;
134 	u8 flags;
135 	u8 len;
136 	__le32 ts32;
137 	__le32 id;
138 
139 	u8 data[8];
140 };
141 
142 #define PCAN_USBPRO_STATUS_ERROR	0x0001
143 #define PCAN_USBPRO_STATUS_BUS		0x0002
144 #define PCAN_USBPRO_STATUS_OVERRUN	0x0004
145 #define PCAN_USBPRO_STATUS_QOVERRUN	0x0008
146 
147 struct __packed pcan_usb_pro_rxstatus {
148 	u8 data_type;
149 	u8 channel;
150 	__le16 status;
151 	__le32 ts32;
152 	__le32 err_frm;
153 };
154 
155 struct __packed pcan_usb_pro_rxts {
156 	u8 data_type;
157 	u8 dummy[3];
158 	__le32 ts64[2];
159 };
160 
161 struct __packed pcan_usb_pro_txmsg {
162 	u8 data_type;
163 	u8 client;
164 	u8 flags;
165 	u8 len;
166 	__le32 id;
167 	u8 data[8];
168 };
169 
170 union pcan_usb_pro_rec {
171 	u8				data_type;
172 	struct pcan_usb_pro_btr		btr;
173 	struct pcan_usb_pro_busact	bus_act;
174 	struct pcan_usb_pro_silent	silent_mode;
175 	struct pcan_usb_pro_filter	filter_mode;
176 	struct pcan_usb_pro_setts	ts;
177 	struct pcan_usb_pro_devid	dev_id;
178 	struct pcan_usb_pro_setled	set_led;
179 	struct pcan_usb_pro_rxmsg	rx_msg;
180 	struct pcan_usb_pro_rxstatus	rx_status;
181 	struct pcan_usb_pro_rxts	rx_ts;
182 	struct pcan_usb_pro_txmsg	tx_msg;
183 };
184 
185 int pcan_usb_pro_probe(struct usb_interface *intf);
186 int pcan_usb_pro_send_req(struct peak_usb_device *dev, int req_id,
187 			  int req_value, void *req_addr, int req_size);
188 void pcan_usb_pro_restart_complete(struct urb *urb);
189 
190 #endif
191