2 * CAN driver for PEAK System USB adapters
3 * Derived from the PCAN project file driver/src/pcan_usb_core.c
5 * Copyright (C) 2003-2010 PEAK System-Technik GmbH
6 * Copyright (C) 2010-2012 Stephane Grosjean <s.grosjean@peak-system.com>
8 * Many thanks to Klaus Hitschler <klaus.hitschler@gmx.de>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; version 2 of the License.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 #ifndef PCAN_USB_CORE_H
20 #define PCAN_USB_CORE_H
22 /* PEAK-System vendor id. */
23 #define PCAN_USB_VENDOR_ID 0x0c72
25 /* supported device ids. */
26 #define PCAN_USB_PRODUCT_ID 0x000c
27 #define PCAN_USBPRO_PRODUCT_ID 0x000d
28 #define PCAN_USBPROFD_PRODUCT_ID 0x0011
29 #define PCAN_USBFD_PRODUCT_ID 0x0012
31 #define PCAN_USB_DRIVER_NAME "peak_usb"
33 /* number of urbs that are submitted for rx/tx per channel */
34 #define PCAN_USB_MAX_RX_URBS 4
35 #define PCAN_USB_MAX_TX_URBS 10
37 /* usb adapters maximum channels per usb interface */
38 #define PCAN_USB_MAX_CHANNEL 2
40 /* maximum length of the usb commands sent to/received from the devices */
41 #define PCAN_USB_MAX_CMD_LEN 32
43 struct peak_usb_device
;
45 /* PEAK-System USB adapter descriptor */
46 struct peak_usb_adapter
{
49 u32 ctrlmode_supported
;
50 struct can_clock clock
;
51 const struct can_bittiming_const
* const bittiming_const
;
52 const struct can_bittiming_const
* const data_bittiming_const
;
53 unsigned int ctrl_count
;
55 int (*intf_probe
)(struct usb_interface
*intf
);
57 int (*dev_init
)(struct peak_usb_device
*dev
);
58 void (*dev_exit
)(struct peak_usb_device
*dev
);
59 void (*dev_free
)(struct peak_usb_device
*dev
);
60 int (*dev_open
)(struct peak_usb_device
*dev
);
61 int (*dev_close
)(struct peak_usb_device
*dev
);
62 int (*dev_set_bittiming
)(struct peak_usb_device
*dev
,
63 struct can_bittiming
*bt
);
64 int (*dev_set_data_bittiming
)(struct peak_usb_device
*dev
,
65 struct can_bittiming
*bt
);
66 int (*dev_set_bus
)(struct peak_usb_device
*dev
, u8 onoff
);
67 int (*dev_get_device_id
)(struct peak_usb_device
*dev
, u32
*device_id
);
68 int (*dev_decode_buf
)(struct peak_usb_device
*dev
, struct urb
*urb
);
69 int (*dev_encode_msg
)(struct peak_usb_device
*dev
, struct sk_buff
*skb
,
70 u8
*obuf
, size_t *size
);
71 int (*dev_start
)(struct peak_usb_device
*dev
);
72 int (*dev_stop
)(struct peak_usb_device
*dev
);
73 int (*dev_restart_async
)(struct peak_usb_device
*dev
, struct urb
*urb
,
75 int (*do_get_berr_counter
)(const struct net_device
*netdev
,
76 struct can_berr_counter
*bec
);
78 u8 ep_msg_out
[PCAN_USB_MAX_CHANNEL
];
86 int sizeof_dev_private
;
89 extern const struct peak_usb_adapter pcan_usb
;
90 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
;
94 struct peak_time_ref
{
95 struct timeval tv_host_0
, tv_host
;
96 u32 ts_dev_1
, ts_dev_2
;
99 const struct peak_usb_adapter
*adapter
;
102 struct peak_tx_urb_context
{
103 struct peak_usb_device
*dev
;
109 #define PCAN_USB_STATE_CONNECTED 0x00000001
110 #define PCAN_USB_STATE_STARTED 0x00000002
112 /* PEAK-System USB device */
113 struct peak_usb_device
{
115 const struct peak_usb_adapter
*adapter
;
116 unsigned int ctrl_idx
;
119 struct sk_buff
*echo_skb
[PCAN_USB_MAX_TX_URBS
];
121 struct usb_device
*udev
;
122 struct net_device
*netdev
;
124 atomic_t active_tx_urbs
;
125 struct usb_anchor tx_submitted
;
126 struct peak_tx_urb_context tx_contexts
[PCAN_USB_MAX_TX_URBS
];
129 struct usb_anchor rx_submitted
;
139 struct peak_usb_device
*prev_siblings
;
140 struct peak_usb_device
*next_siblings
;
143 void pcan_dump_mem(char *prompt
, void *p
, int l
);
145 /* common timestamp management */
146 void peak_usb_init_time_ref(struct peak_time_ref
*time_ref
,
147 const struct peak_usb_adapter
*adapter
);
148 void peak_usb_update_ts_now(struct peak_time_ref
*time_ref
, u32 ts_now
);
149 void peak_usb_set_ts_now(struct peak_time_ref
*time_ref
, u32 ts_now
);
150 void peak_usb_get_ts_tv(struct peak_time_ref
*time_ref
, u32 ts
,
152 int peak_usb_netif_rx(struct sk_buff
*skb
,
153 struct peak_time_ref
*time_ref
, u32 ts_low
, u32 ts_high
);
154 void peak_usb_async_complete(struct urb
*urb
);
155 void peak_usb_restart_complete(struct peak_usb_device
*dev
);