Skip to contentSkip to conversation

ems_usb: Added support for EMS CPC-USB/ARM7 CAN interface

PATCH New Sebastian Haas 3 participants 4 messages Sep 16, 2009 2 messages not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover ems_usb: Added support for EMS CPC-USB/ARM7 CAN interface

The following series replaces the staging driver cpc-usb with the newly written ems_usb CAN driver.

---

Sebastian Haas (2):
ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface
cpc-usb: Removed driver from staging tree

 drivers/net/can/Kconfig               |    7 
 drivers/net/can/Makefile              |    2 
 drivers/net/can/usb/Makefile          |    5 
 drivers/net/can/usb/ems_usb.c         | 1151 ++++++++++++++++++++++++++++++++
 drivers/staging/Kconfig               |    2 
 drivers/staging/Makefile              |    1 
 drivers/staging/cpc-usb/Kconfig       |    4 
 drivers/staging/cpc-usb/Makefile      |    3 
 drivers/staging/cpc-usb/TODO          |    9 
 drivers/staging/cpc-usb/cpc-usb_drv.c | 1185 ---------------------------------
 drivers/staging/cpc-usb/cpc.h         |  440 ------------
 drivers/staging/cpc-usb/cpc_int.h     |   83 --
 drivers/staging/cpc-usb/cpcusb.h      |   86 --
 drivers/staging/cpc-usb/sja2m16c.h    |   41 -
 drivers/staging/cpc-usb/sja2m16c_2.c  |  452 -------------
 15 files changed, 1165 insertions(+), 2306 deletions(-)
 create mode 100644 drivers/net/can/usb/Makefile
 create mode 100644 drivers/net/can/usb/ems_usb.c
 delete mode 100644 drivers/staging/cpc-usb/Kconfig
 delete mode 100644 drivers/staging/cpc-usb/Makefile
 delete mode 100644 drivers/staging/cpc-usb/TODO
 delete mode 100644 drivers/staging/cpc-usb/cpc-usb_drv.c
 delete mode 100644 drivers/staging/cpc-usb/cpc.h
 delete mode 100644 drivers/staging/cpc-usb/cpc_int.h
 delete mode 100644 drivers/staging/cpc-usb/cpcusb.h
 delete mode 100644 drivers/staging/cpc-usb/sja2m16c.h
 delete mode 100644 drivers/staging/cpc-usb/sja2m16c_2.c
Signature · 9 lines
Cheers, Sebastian
-- 
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HRA Neuburg a.d. Donau, HR-Nr. 70.106
Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

A message that is not in the archive (sent off-list or not yet received): 20090916090408.12370.94680.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#2 lore raw

PATCH v2 1/2 cpc-usb: Removed driver from staging tree

This patch prepares replacing the staging driver cpc-usb with the new developed ems_usb CAN driver.

---

 drivers/staging/Kconfig               |    2 
 drivers/staging/Makefile              |    1 
 drivers/staging/cpc-usb/Kconfig       |    4 
 drivers/staging/cpc-usb/Makefile      |    3 
 drivers/staging/cpc-usb/TODO          |    9 
 drivers/staging/cpc-usb/cpc-usb_drv.c | 1185 ---------------------------------
 drivers/staging/cpc-usb/cpc.h         |  440 ------------
 drivers/staging/cpc-usb/cpc_int.h     |   83 --
 drivers/staging/cpc-usb/cpcusb.h      |   86 --
 drivers/staging/cpc-usb/sja2m16c.h    |   41 -
 drivers/staging/cpc-usb/sja2m16c_2.c  |  452 -------------
 11 files changed, 0 insertions(+), 2306 deletions(-)
 delete mode 100644 drivers/staging/cpc-usb/Kconfig
 delete mode 100644 drivers/staging/cpc-usb/Makefile
 delete mode 100644 drivers/staging/cpc-usb/TODO
 delete mode 100644 drivers/staging/cpc-usb/cpc-usb_drv.c
 delete mode 100644 drivers/staging/cpc-usb/cpc.h
 delete mode 100644 drivers/staging/cpc-usb/cpc_int.h
 delete mode 100644 drivers/staging/cpc-usb/cpcusb.h
 delete mode 100644 drivers/staging/cpc-usb/sja2m16c.h
 delete mode 100644 drivers/staging/cpc-usb/sja2m16c_2.c
drivers/staging/Kconfig +0 -2
index 975ecdd..5e4b865 100644
@@ -121,8 +121,6 @@ source "drivers/staging/serqt_usb2/Kconfig"
 
 source "drivers/staging/vt6655/Kconfig"
 
-source "drivers/staging/cpc-usb/Kconfig"
-
 source "drivers/staging/pata_rdc/Kconfig"
 
 source "drivers/staging/udlfb/Kconfig"
drivers/staging/Makefile +0 -1
index 2241ae1..ede1599 100644
@@ -42,6 +42,5 @@ obj-$(CONFIG_LINE6_USB)		+= line6/
 obj-$(CONFIG_USB_SERIAL_QUATECH2)	+= serqt_usb2/
 obj-$(CONFIG_OCTEON_ETHERNET)	+= octeon/
 obj-$(CONFIG_VT6655)		+= vt6655/
-obj-$(CONFIG_USB_CPC)		+= cpc-usb/
 obj-$(CONFIG_RDC_17F3101X)	+= pata_rdc/
 obj-$(CONFIG_FB_UDL)		+= udlfb/
drivers/staging/cpc-usb/Kconfig deleted +0 -4
deleted file mode 100644
index 2be0bc9..0000000
@@ -1,4 +0,0 @@
-config USB_CPC
-	tristate "CPC CAN USB driver"
-	depends on USB && PROC_FS
-	default n
drivers/staging/cpc-usb/Makefile deleted +0 -3
deleted file mode 100644
index 3f83170..0000000
@@ -1,3 +0,0 @@
-obj-$(CONFIG_USB_CPC)	+= cpc-usb.o
-
-cpc-usb-y := cpc-usb_drv.o sja2m16c_2.o
drivers/staging/cpc-usb/TODO deleted +0 -9
deleted file mode 100644
index 000e8bb..0000000
@@ -1,9 +0,0 @@
-Things to do for this driver to get merged into the main portion of the
-kernel:
-	- checkpatch cleanups
-	- sparse clean
-	- remove proc code
-	- tie into CAN socket interfaces if possible
-	- figure out sane userspace api
-
-Send patches to Greg Kroah-Hartman <[email protected]>
drivers/staging/cpc-usb/cpc-usb_drv.c deleted +0 -1185

1,185 lines not on this page · raw message

drivers/staging/cpc-usb/cpc.h deleted +0 -440

440 lines not on this page · raw message

drivers/staging/cpc-usb/cpc_int.h deleted +0 -83

83 lines not on this page · raw message

drivers/staging/cpc-usb/cpcusb.h deleted +0 -86

86 lines not on this page · raw message

drivers/staging/cpc-usb/sja2m16c.h deleted +0 -41

41 lines not on this page · raw message

drivers/staging/cpc-usb/sja2m16c_2.c deleted +0 -452

452 lines not on this page · raw message

Signature · 7 lines
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HRA Neuburg a.d. Donau, HR-Nr. 70.106
Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com
#3 lore raw

PATCH v2 2/2 ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface

In reply to a message not in the archive

This patch adds support for one channel CAN/USB interace CPC-USB/ARM7 from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.com).

---

 drivers/net/can/Kconfig       |    7 
 drivers/net/can/Makefile      |    2 
 drivers/net/can/usb/Makefile  |    5 
 drivers/net/can/usb/ems_usb.c | 1151 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1165 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/can/usb/Makefile
 create mode 100644 drivers/net/can/usb/ems_usb.c
drivers/net/can/Kconfig +7 -0
index 0900743..6ac5aa5 100644
@@ -75,6 +75,13 @@ config CAN_EMS_PCI
 	  CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche
 	  (http://www.ems-wuensche.de).
 
+config CAN_EMS_USB
+	tristate "EMS CPC-USB/ARM7 CAN/USB interface"
+	depends on USB && CAN_DEV
+	---help---
+	  This driver is for the one channel CPC-USB/ARM7 CAN/USB interface
+	  from from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de).
+
 config CAN_KVASER_PCI
 	tristate "Kvaser PCIcanx and Kvaser PCIcan PCI Cards"
 	depends on PCI && CAN_SJA1000
drivers/net/can/Makefile +2 -0
index 523a941..9b035ec 100644
@@ -7,6 +7,8 @@ obj-$(CONFIG_CAN_VCAN)		+= vcan.o
 obj-$(CONFIG_CAN_DEV)		+= can-dev.o
 can-dev-y			:= dev.o
 
+obj-y				+= usb/
+
 obj-$(CONFIG_CAN_SJA1000)	+= sja1000/
 
 ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
drivers/net/can/usb/Makefile new file +5 -0
new file mode 100644
index 0000000..c3f75ba
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network USB drivers.
+#
+
+obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o
drivers/net/can/usb/ems_usb.c new file +1151 -0

1,151 lines not on this page · raw message

Signature · 7 lines
EMS Dr. Thomas Wuensche e.K.
Sonnenhang 3
85304 Ilmmuenster
HRA Neuburg a.d. Donau, HR-Nr. 70.106
Phone: +49-8441-490260
Fax  : +49-8441-81860
http://www.ems-wuensche.com

A message that is not in the archive (sent off-list or not yet received): 20090916090418.12370.16510.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#5 lore raw

Re: [PATCH V2 2/2] ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface

Quoted 4 lines · Sebastian Haas

This patch adds support for one channel CAN/USB interace CPC-USB/ARM7 from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.com).

The cleanup in the probe function is still not OK :-(.

Quoted 53 lines

---

 drivers/net/can/Kconfig       |    7 
 drivers/net/can/Makefile      |    2 
 drivers/net/can/usb/Makefile  |    5 
 drivers/net/can/usb/ems_usb.c | 1151 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1165 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/can/usb/Makefile
 create mode 100644 drivers/net/can/usb/ems_usb.c
drivers/net/can/Kconfig +7 -0
index 0900743..6ac5aa5 100644
@@ -75,6 +75,13 @@ config CAN_EMS_PCI
 	  CPC-PCIe and CPC-104P cards from EMS Dr. Thomas Wuensche
 	  (http://www.ems-wuensche.de).
 
+config CAN_EMS_USB
+	tristate "EMS CPC-USB/ARM7 CAN/USB interface"
+	depends on USB && CAN_DEV
+	---help---
+	  This driver is for the one channel CPC-USB/ARM7 CAN/USB interface
+	  from from EMS Dr. Thomas Wuensche (http://www.ems-wuensche.de).
+
 config CAN_KVASER_PCI
 	tristate "Kvaser PCIcanx and Kvaser PCIcan PCI Cards"
 	depends on PCI && CAN_SJA1000
drivers/net/can/Makefile +2 -0
index 523a941..9b035ec 100644
@@ -7,6 +7,8 @@ obj-$(CONFIG_CAN_VCAN)		+= vcan.o
 obj-$(CONFIG_CAN_DEV)		+= can-dev.o
 can-dev-y			:= dev.o
 
+obj-y				+= usb/
+
 obj-$(CONFIG_CAN_SJA1000)	+= sja1000/
 
 ccflags-$(CONFIG_CAN_DEBUG_DEVICES) := -DDEBUG
drivers/net/can/usb/Makefile new file +5 -0
new file mode 100644
index 0000000..c3f75ba
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network USB drivers.
+#
+
+obj-$(CONFIG_CAN_EMS_USB) += ems_usb.o
drivers/net/can/usb/ems_usb.c +0 -0

[snip]

drivers/net/can/usb/ems_usb.c line 1009

Quoted 10 lines
drivers/net/can/usb/ems_usb.c +10 -0
+/*
+ * probe function for new CPC-USB devices
+ */
+static int ems_usb_probe(struct usb_interface *intf,
+			 const struct usb_device_id *id)
+{
+	struct net_device *netdev;
+	struct ems_usb *dev;
+	int i, err;
+	int retval = -ENOMEM;

Why do you need an extra variable here.

	int err = -ENOMEM;

Should work fine!?

Quoted 58 lines
drivers/net/can/usb/ems_usb.c +58 -0
+
+	netdev = alloc_candev(sizeof(struct ems_usb));
+	if (!netdev) {
+		dev_err(netdev->dev.parent, "Couldn't alloc candev\n");
+		return -ENOMEM;
+	}
+
+	dev = netdev_priv(netdev);
+
+	dev->udev = interface_to_usbdev(intf);
+	dev->netdev = netdev;
+
+	dev->can.state = CAN_STATE_STOPPED;
+	dev->can.clock.freq = EMS_USB_ARM7_CLOCK;
+	dev->can.bittiming_const = &ems_usb_bittiming_const;
+	dev->can.do_set_bittiming = ems_usb_set_bittiming;
+	dev->can.do_set_mode = ems_usb_set_mode;
+
+	netdev->flags |= IFF_ECHO; /* we support local echo */
+
+	/*
+	 * The device actually uses a 16MHz clock to generate the CAN clock
+	 * but it expects SJA1000 bit settings based on 8MHz (is internally
+	 * converted).
+	 */
+
+	netdev->netdev_ops = &ems_usb_netdev_ops;
+
+	netdev->flags |= IFF_ECHO; /* we support local echo */
+
+	init_usb_anchor(&dev->rx_submitted);
+
+	init_usb_anchor(&dev->tx_submitted);
+	atomic_set(&dev->active_tx_urbs, 0);
+
+	for (i = 0; i < MAX_TX_URBS; i++)
+		dev->tx_contexts[i].echo_index = MAX_TX_URBS;
+
+	dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
+	if (!dev->intr_urb) {
+		dev_err(netdev->dev.parent, "Couldn't alloc intr URB\n");
+		goto cleanup_candev;
+	}
+
+	dev->intr_in_buffer = kzalloc(INTR_IN_BUFFER_SIZE, GFP_KERNEL);
+	if (!dev->intr_in_buffer) {
+		dev_err(netdev->dev.parent, "Couldn't alloc Intr buffer\n");
+		goto cleanup_intr_urb;
+	}
+
+	dev->tx_msg_buffer = kzalloc(CPC_HEADER_SIZE +
+				     sizeof(struct ems_cpc_msg), GFP_KERNEL);
+	if (!dev->tx_msg_buffer) {
+		dev_err(netdev->dev.parent, "Couldn't alloc Tx buffer\n");
+		goto cleanup_intr_in_buffer;
+	}
+
+	usb_set_intfdata(intf, dev);

drivers/net/can/usb/ems_usb.c line 1077

Quoted 10 lines
drivers/net/can/usb/ems_usb.c +10 -0
+
+	SET_NETDEV_DEV(netdev, &intf->dev);
+
+	init_params_sja1000(&dev->active_params);
+
+	err = ems_usb_command_msg(dev, &dev->active_params);
+	if (err) {
+		dev_err(netdev->dev.parent,
+			"couldn't initialize controller: %d\n", err);
+		retval = err;

Could be removed then.

drivers/net/can/usb/ems_usb.c line 1081

Quoted 4 lines
drivers/net/can/usb/ems_usb.c +4 -0
+		goto cleanup_tx_msg_buffer;
+	}
+
+	return register_candev(netdev);

Cleanup is missing if register_candev() fails!

Quoted 5 lines
drivers/net/can/usb/ems_usb.c +5 -0
+
+cleanup_tx_msg_buffer:
+	kfree(dev->tx_msg_buffer);
+
+cleanup_intr_in_buffer:

drivers/net/can/usb/ems_usb.c line 1096

Quoted 10 lines
drivers/net/can/usb/ems_usb.c +10 -0
+	kfree(dev->intr_in_buffer);
+
+cleanup_intr_urb:
+	usb_free_urb(dev->intr_urb);
+
+cleanup_candev:
+	free_candev(netdev);
+
+	return retval;
+}

Wolfgang.