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