aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Fuchs <matthias.fuchs@esd.eu>2010-08-02 22:55:23 -0400
committerDavid S. Miller <davem@davemloft.net>2010-08-03 19:37:58 -0400
commit96d8e90382dc336b5de401164597edfdc2e8d9f1 (patch)
tree2976dc09729f46ee68217dda7dd2683950e27362
parent4565956dc0847985c0403c9ebbf274b6a122e1e2 (diff)
can: Add driver for esd CAN-USB/2 device
This patch adds a driver for esd's USB high speed CAN interface. The driver supports devices with multiple CAN interfaces. Signed-off-by: Matthias Fuchs <matthias.fuchs@esd.eu> Acked-by: Wolfgang Grandegger <wg@grandegger.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/can/usb/Kconfig6
-rw-r--r--drivers/net/can/usb/Makefile1
-rw-r--r--drivers/net/can/usb/esd_usb2.c1132
3 files changed, 1139 insertions, 0 deletions
diff --git a/drivers/net/can/usb/Kconfig b/drivers/net/can/usb/Kconfig
index 97ff6febad63..04525495b15b 100644
--- a/drivers/net/can/usb/Kconfig
+++ b/drivers/net/can/usb/Kconfig
@@ -7,4 +7,10 @@ config CAN_EMS_USB
7 This driver is for the one channel CPC-USB/ARM7 CAN/USB interface 7 This driver is for the one channel CPC-USB/ARM7 CAN/USB interface
8 from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de). 8 from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de).
9 9
10config CAN_ESD_USB2
11 tristate "ESD USB/2 CAN/USB interface"
12 ---help---
13 This driver supports the CAN-USB/2 interface
14 from esd electronic system design gmbh (http://www.esd.eu).
15
10endmenu 16endmenu
diff --git a/drivers/net/can/usb/Makefile b/drivers/net/can/usb/Makefile
index 0afd51d4c7a5..fce3cf11719f 100644
--- a/drivers/net/can/usb/Makefile
+++ b/drivers/net/can/usb/Makefile
@@ -3,5 +3,6 @@
3# 3#
4 4
5obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o 5obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o
6obj-$(CONFIG_CAN_ESD_USB2) += esd_usb2.o
6 7
7ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG 8ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c
new file mode 100644
index 000000000000..05a52754f486
--- /dev/null
+++ b/drivers/net/can/usb/esd_usb2.c
@@ -0,0 +1,1132 @@
1/*
2 * CAN driver for esd CAN-USB/2
3 *
4 * Copyright (C) 2010 Matthias Fuchs <matthias.fuchs@esd.eu>, esd gmbh
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19#include <linux/init.h>
20#include <linux/signal.h>
21#include <linux/slab.h>
22#include <linux/module.h>
23#include <linux/netdevice.h>
24#include <linux/usb.h>
25
26#include <linux/can.h>
27#include <linux/can/dev.h>
28#include <linux/can/error.h>
29
30MODULE_AUTHOR("Matthias Fuchs <matthias.fuchs@esd.eu>");
31MODULE_DESCRIPTION("CAN driver for esd CAN-USB/2 interfaces");
32MODULE_LICENSE("GPL v2");
33
34/* Define these values to match your devices */
35#define USB_ESDGMBH_VENDOR_ID 0x0ab4
36#define USB_CANUSB2_PRODUCT_ID 0x0010
37
38#define ESD_USB2_CAN_CLOCK 60000000
39#define ESD_USB2_MAX_NETS 2
40
41/* USB2 commands */
42#define CMD_VERSION 1 /* also used for VERSION_REPLY */
43#define CMD_CAN_RX 2 /* device to host only */
44#define CMD_CAN_TX 3 /* also used for TX_DONE */
45#define CMD_SETBAUD 4 /* also used for SETBAUD_REPLY */
46#define CMD_TS 5 /* also used for TS_REPLY */
47#define CMD_IDADD 6 /* also used for IDADD_REPLY */
48
49/* esd CAN message flags - dlc field */
50#define ESD_RTR 0x10
51
52/* esd CAN message flags - id field */
53#define ESD_EXTID 0x20000000
54#define ESD_EVENT 0x40000000
55#define ESD_IDMASK 0x1fffffff
56
57/* esd CAN event ids used by this driver */
58#define ESD_EV_CAN_ERROR_EXT 2
59
60/* baudrate message flags */
61#define ESD_USB2_UBR 0x80000000
62#define ESD_USB2_LOM 0x40000000
63#define ESD_USB2_NO_BAUDRATE 0x7fffffff
64#define ESD_USB2_TSEG1_MIN 1
65#define ESD_USB2_TSEG1_MAX 16
66#define ESD_USB2_TSEG1_SHIFT 16
67#define ESD_USB2_TSEG2_MIN 1
68#define ESD_USB2_TSEG2_MAX 8
69#define ESD_USB2_TSEG2_SHIFT 20
70#define ESD_USB2_SJW_MAX 4
71#define ESD_USB2_SJW_SHIFT 14
72#define ESD_USB2_BRP_MIN 1
73#define ESD_USB2_BRP_MAX 1024
74#define ESD_USB2_BRP_INC 1
75#define ESD_USB2_3_SAMPLES 0x00800000
76
77/* esd IDADD message */
78#define ESD_ID_ENABLE 0x80
79#define ESD_MAX_ID_SEGMENT 64
80
81/* SJA1000 ECC register (emulated by usb2 firmware) */
82#define SJA1000_ECC_SEG 0x1F
83#define SJA1000_ECC_DIR 0x20
84#define SJA1000_ECC_ERR 0x06
85#define SJA1000_ECC_BIT 0x00
86#define SJA1000_ECC_FORM 0x40
87#define SJA1000_ECC_STUFF 0x80
88#define SJA1000_ECC_MASK 0xc0
89
90/* esd bus state event codes */
91#define ESD_BUSSTATE_MASK 0xc0
92#define ESD_BUSSTATE_WARN 0x40
93#define ESD_BUSSTATE_ERRPASSIVE 0x80
94#define ESD_BUSSTATE_BUSOFF 0xc0
95
96#define RX_BUFFER_SIZE 1024
97#define MAX_RX_URBS 4
98#define MAX_TX_URBS 16 /* must be power of 2 */
99
100struct header_msg {
101 u8 len; /* len is always the total message length in 32bit words */
102 u8 cmd;
103 u8 rsvd[2];
104};
105
106struct version_msg {
107 u8 len;
108 u8 cmd;
109 u8 rsvd;
110 u8 flags;
111 __le32 drv_version;
112};
113
114struct version_reply_msg {
115 u8 len;
116 u8 cmd;
117 u8 nets;
118 u8 features;
119 __le32 version;
120 u8 name[16];
121 __le32 rsvd;
122 __le32 ts;
123};
124
125struct rx_msg {
126 u8 len;
127 u8 cmd;
128 u8 net;
129 u8 dlc;
130 __le32 ts;
131 __le32 id; /* upper 3 bits contain flags */
132 u8 data[8];
133};
134
135struct tx_msg {
136 u8 len;
137 u8 cmd;
138 u8 net;
139 u8 dlc;
140 __le32 hnd;
141 __le32 id; /* upper 3 bits contain flags */
142 u8 data[8];
143};
144
145struct tx_done_msg {
146 u8 len;
147 u8 cmd;
148 u8 net;
149 u8 status;
150 __le32 hnd;
151 __le32 ts;
152};
153
154struct id_filter_msg {
155 u8 len;
156 u8 cmd;
157 u8 net;
158 u8 option;
159 __le32 mask[ESD_MAX_ID_SEGMENT + 1];
160};
161
162struct set_baudrate_msg {
163 u8 len;
164 u8 cmd;
165 u8 net;
166 u8 rsvd;
167 __le32 baud;
168};
169
170/* Main message type used between library and application */
171str