aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSebastian Haas <haas@ems-wuensche.com>2009-09-15 22:04:15 -0400
committerDavid S. Miller <davem@davemloft.net>2009-09-21 14:32:24 -0400
commitc1e815c03b7313d6474164bfe91916da1329ad2b (patch)
tree79059043701d361bac72a1abc5d279453105da33 /drivers
parent762c6aa14c541f0fef44d030f9d422b47583365d (diff)
cpc-usb: Removed driver from staging tree
This patch prepares replacing the staging driver cpc-usb with the new developed ems_usb CAN driver. Signed-off-by: Sebastian Haas <haas@ems-wuensche.com> Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/Kconfig2
-rw-r--r--drivers/staging/Makefile1
-rw-r--r--drivers/staging/cpc-usb/Kconfig4
-rw-r--r--drivers/staging/cpc-usb/Makefile3
-rw-r--r--drivers/staging/cpc-usb/TODO9
-rw-r--r--drivers/staging/cpc-usb/cpc-usb_drv.c1185
-rw-r--r--drivers/staging/cpc-usb/cpc.h440
-rw-r--r--drivers/staging/cpc-usb/cpc_int.h83
-rw-r--r--drivers/staging/cpc-usb/cpcusb.h86
-rw-r--r--drivers/staging/cpc-usb/sja2m16c.h41
-rw-r--r--drivers/staging/cpc-usb/sja2m16c_2.c452
11 files changed, 0 insertions, 2306 deletions
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 975ecddbce30..5e4b8655b57c 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -121,8 +121,6 @@ source "drivers/staging/serqt_usb2/Kconfig"
121 121
122source "drivers/staging/vt6655/Kconfig" 122source "drivers/staging/vt6655/Kconfig"
123 123
124source "drivers/staging/cpc-usb/Kconfig"
125
126source "drivers/staging/pata_rdc/Kconfig" 124source "drivers/staging/pata_rdc/Kconfig"
127 125
128source "drivers/staging/udlfb/Kconfig" 126source "drivers/staging/udlfb/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 2241ae1b21ee..ede1599e7e66 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -42,6 +42,5 @@ obj-$(CONFIG_LINE6_USB) += line6/
42obj-$(CONFIG_USB_SERIAL_QUATECH2) += serqt_usb2/ 42obj-$(CONFIG_USB_SERIAL_QUATECH2) += serqt_usb2/
43obj-$(CONFIG_OCTEON_ETHERNET) += octeon/ 43obj-$(CONFIG_OCTEON_ETHERNET) += octeon/
44obj-$(CONFIG_VT6655) += vt6655/ 44obj-$(CONFIG_VT6655) += vt6655/
45obj-$(CONFIG_USB_CPC) += cpc-usb/
46obj-$(CONFIG_RDC_17F3101X) += pata_rdc/ 45obj-$(CONFIG_RDC_17F3101X) += pata_rdc/
47obj-$(CONFIG_FB_UDL) += udlfb/ 46obj-$(CONFIG_FB_UDL) += udlfb/
diff --git a/drivers/staging/cpc-usb/Kconfig b/drivers/staging/cpc-usb/Kconfig
deleted file mode 100644
index 2be0bc9c39d0..000000000000
--- a/drivers/staging/cpc-usb/Kconfig
+++ /dev/null
@@ -1,4 +0,0 @@
1config USB_CPC
2 tristate "CPC CAN USB driver"
3 depends on USB && PROC_FS
4 default n
diff --git a/drivers/staging/cpc-usb/Makefile b/drivers/staging/cpc-usb/Makefile
deleted file mode 100644
index 3f83170a8fab..000000000000
--- a/drivers/staging/cpc-usb/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1obj-$(CONFIG_USB_CPC) += cpc-usb.o
2
3cpc-usb-y := cpc-usb_drv.o sja2m16c_2.o
diff --git a/drivers/staging/cpc-usb/TODO b/drivers/staging/cpc-usb/TODO
deleted file mode 100644
index 000e8bbc6188..000000000000
--- a/drivers/staging/cpc-usb/TODO
+++ /dev/null
@@ -1,9 +0,0 @@
1Things to do for this driver to get merged into the main portion of the
2kernel:
3 - checkpatch cleanups
4 - sparse clean
5 - remove proc code
6 - tie into CAN socket interfaces if possible
7 - figure out sane userspace api
8
9Send patches to Greg Kroah-Hartman <greg@kroah.com>
diff --git a/drivers/staging/cpc-usb/cpc-usb_drv.c b/drivers/staging/cpc-usb/cpc-usb_drv.c
deleted file mode 100644
index 9bf3f98c6825..000000000000
--- a/drivers/staging/cpc-usb/cpc-usb_drv.c
+++ /dev/null
@@ -1,1185 +0,0 @@
1/*
2 * CPC-USB CAN Interface Kernel Driver
3 *
4 * Copyright (C) 2004-2009 EMS Dr. Thomas Wuensche
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/kernel.h>
20#include <linux/errno.h>
21#include <linux/init.h>
22#include <linux/slab.h>
23#include <linux/vmalloc.h>
24#include <linux/module.h>
25#include <linux/poll.h>
26#include <linux/smp_lock.h>
27#include <linux/completion.h>
28#include <asm/uaccess.h>
29#include <linux/usb.h>
30
31#include <linux/version.h>
32
33#include <linux/proc_fs.h>
34
35#include "cpc.h"
36
37#include "cpc_int.h"
38#include "cpcusb.h"
39
40#include "sja2m16c.h"
41
42/* Version Information */
43#define DRIVER_AUTHOR "Sebastian Haas <haas@ems-wuensche.com>"
44#define DRIVER_DESC "CPC-USB Driver for Linux Kernel 2.6"
45#define DRIVER_VERSION CPC_DRIVER_VERSION
46
47MODULE_AUTHOR(DRIVER_AUTHOR);
48MODULE_DESCRIPTION(DRIVER_DESC);
49MODULE_VERSION(DRIVER_VERSION);
50MODULE_LICENSE("GPL v2");
51
52/* Define these values to match your devices */
53#define USB_CPCUSB_VENDOR_ID 0x12D6
54
55#define USB_CPCUSB_M16C_PRODUCT_ID 0x0888
56#define USB_CPCUSB_LPC2119_PRODUCT_ID 0x0444
57
58#define CPC_USB_PROC_DIR CPC_PROC_DIR "cpc-usb"
59
60static struct proc_dir_entry *procDir;
61static struct proc_dir_entry *procEntry;
62
63/* Module parameters */
64static int debug;
65module_param(debug, int, S_IRUGO);
66
67/* table of devices that work with this driver */
68static struct usb_device_id cpcusb_table[] = {
69 {USB_DEVICE(USB_CPCUSB_VENDOR_ID, USB_CPCUSB_M16C_PRODUCT_ID)},
70 {USB_DEVICE(USB_CPCUSB_VENDOR_ID, USB_CPCUSB_LPC2119_PRODUCT_ID)},
71 {} /* Terminating entry */
72};
73
74MODULE_DEVICE_TABLE(usb, cpcusb_table);
75
76/* use to prevent kernel panic if driver is unloaded
77 * while a programm has still open the device
78 */
79DECLARE_WAIT_QUEUE_HEAD(rmmodWq);
80atomic_t useCount;
81
82static CPC_USB_T *CPCUSB_Table[CPC_USB_CARD_CNT] = { 0 };
83static unsigned int CPCUsbCnt;
84
85/* prevent races between open() and disconnect() */
86static DECLARE_MUTEX(disconnect_sem);
87
88/* local function prototypes */
89static ssize_t cpcusb_read(struct file *file, char *buffer, size_t count,
90 loff_t *ppos);
91static ssize_t cpcusb_write(struct file *file, const char *buffer,
92 size_t count, loff_t *ppos);
93static unsigned int cpcusb_poll(struct file *file, poll_table * wait);
94static int cpcusb_open(struct inode *inode, struct file *file);
95static int cpcusb_release(struct inode *inode, struct file *file);
96
97static int cpcusb_probe(struct usb_interface *interface,
98 const struct usb_device_id *id);
99static void cpcusb_disconnect(struct usb_interface *interface);
100
101static void cpcusb_read_bulk_callback(struct urb *urb);
102static void cpcusb_write_bulk_callback(struct urb *urb);
103static void cpcusb_read_interrupt_callback(struct urb *urb);
104
105static int cpcusb_setup_intrep(CPC_USB_T *card);
106
107static struct file_operations cpcusb_fops = {
108 /*
109 * The owner field is part of the module-locking
110 * mechanism. The idea is that the kernel knows
111 * which module to increment the use-counter of
112 * BEFORE it calls the device's open() function.
113 * This also means that the kernel can decrement
114 * the use-counter again before calling release()
115 * or should the open() function fail.
116 */
117 .owner = THIS_MODULE,
118
119 .read = cpcusb_read,
120 .write = cpcusb_write,
121 .poll = cpcusb_poll,
122 .open = cpcusb_open,
123 .release = cpcusb_release,
124};
125
126/*
127 * usb class driver info in order to get a minor number from the usb core,
128 * and to have the device registered with devfs and the driver core
129 */
130static struct usb_class_driver cpcusb_class = {
131 .name = "usb/cpc_usb%d",
132 .fops = &cpcusb_fops,
133 .minor_base = CPC_USB_BASE_MNR,
134};
135
136/* usb specific object needed to register this driver with the usb subsystem */
137static struct usb_driver cpcusb_driver = {
138 .name = "cpc-usb",
139 .probe = cpcusb_probe,
140 .disconnect = cpcusb_disconnect,
141 .id_table = cpcusb_table,
142};
143
144static int cpcusb_create_info_output(char *buf)
145{
146 int i = 0, j;
147
148 for (j = 0; j < CPC_USB_CARD_CNT; j++) {
149 if (CPCUSB_Table[j]) {
150 CPC_USB_T *card = CPCUSB_Table[j];
151 CPC_CHAN_T *chan = card->chan;
152
153 /* MINOR CHANNELNO BUSNO SLOTNO */
154 i += sprintf(&buf[i], "%d %s\n", chan->minor,
155 card->serialNumber);
156 }
157 }
158
159 return i;
160}
161
162static int cpcusb_proc_read_info(char *page, char **start, off_t off,
163 int count, int *eof, void *data)
164{
165 int len = cpcusb_create_info_output(page);
166
167 if (len <= off + count)
168 *eof = 1;
169 *start = page + off;
170 len -= off;
171 if (len > count)
172 len = count;
173 if (len < 0)
174 len = 0;
175
176 return len;
177}
178
179/*
180 * Remove CPC-USB and cleanup
181 */
182static inline void cpcusb_delete(CPC_USB_T *card)
183{
184 if (card) {
185 if (card->chan) {
186 if (card->chan->buf)
187 vfree(card->chan->buf);
188
189 if (card->chan->CPCWait_q)
190 kfree(card->chan->CPCWait_q);
191
192 kfree(card->chan);
193 }
194
195 CPCUSB_Table[card->idx] = NULL;
196 kfree(card);
197 }
198}
199
200/*
201 * setup the interrupt IN endpoint of a specific CPC-USB device
202 */
203static int cpcusb_setup_intrep(CPC_USB_T *card)
204{
205 int retval = 0;
206 struct usb_endpoint_descriptor *ep;
207
208 ep = &card->interface->altsetting[0].endpoint[card->num_intr_in].desc;
209
210 card->intr_in_buffer[0] = 0;
211 card->free_slots = 15; /* initial size */
212
213 /* setup the urb */
214 usb_fill_int_urb(card->intr_in_urb, card->udev,
215 usb_rcvintpipe(card->udev, card->num_intr_in),
216 card->intr_in_buffer,
217 sizeof(card->intr_in_buffer),
218 cpcusb_read_interrupt_callback,
219 card,
220 ep->bInterval);
221
222 card->intr_in_urb->status = 0; /* needed! */
223
224 /* submit the urb */
225 retval = usb_submit_urb(card->intr_in_urb, GFP_KERNEL);
226
227 if (retval)
228 err("%s - failed submitting intr urb, error %d", __func__,
229 retval);
230
231 return retval;
232}
233
234static int cpcusb_open(struct inode *inode, struct file *file)
235{
236 CPC_USB_T *card = NULL;
237 struct usb_interface *interface;
238 int subminor;
239 int j, retval = 0;
240
241 subminor = iminor(inode);
242
243 /* prevent disconnects */
244 down(&disconnect_sem);
245
246 interface = usb_find_interface(&cpcusb_driver, subminor);
247 if (!interface) {
248 err("%s - error, can't find device for minor %d",
249 __func__, subminor);
250 retval = CPC_ERR_NO_INTERFACE_PRESENT;
251 goto exit_no_device;
252 }
253
254 card = usb_get_intfdata(interface);
255 if (!card) {
256 retval = CPC_ERR_NO_INTERFACE_PRESENT;
257 goto exit_no_device;
258 }
259
260 /* lock this device */
261 down(&card->sem);
262
263 /* increment our usage count for the driver */
264 if (card->open) {
265 dbg("device already opened");
266 retval = CPC_ERR_CHANNEL_ALREADY_OPEN;
267 goto exit_on_error;
268 }
269
270 /* save our object in the file's private structure */
271 file->private_data = card;
272 for (j = 0; j < CPC_USB_URB_CNT; j++) {
273 usb_fill_bulk_urb(card->urbs[j].urb, card->udev,
274 usb_rcvbulkpipe(card->udev, card->num_bulk_in),
275 card->urbs[j].buffer, card->urbs[j].size,
276 cpcusb_read_bulk_callback, card);
277
278 retval = usb_submit_urb(card->urbs[j].urb, GFP_KERNEL);
279
280 if (retval) {
281 err("%s - failed submitting read urb, error %d",
282 __func__, retval);
283 retval = CPC_ERR_TRANSMISSION_FAILED;
284 goto exit_on_error;
285 }
286 }
287
288 info("%s - %d URB's submitted", __func__, j);
289
290 ResetBuffer(card->chan);
291
292 cpcusb_setup_intrep(card);
293 card->open = 1;
294
295 atomic_inc(&useCount);
296
297exit_on_error:
298 /* unlock this device */
299 up(&card->sem);
300
301exit_no_device:
302 up(&disconnect_sem);
303
304 return retval;
305}
306
307static unsigned int cpcusb_poll(struct file *file, poll_table * wait)
308{
309 CPC_USB_T *card = (CPC_USB_T *) file->private_data;
310 unsigned int retval = 0;
311
312 if (!card) {
313 err("%s - device object lost", __func__);
314 return -EIO;
315 }
316
317 poll_wait(file, card->chan->CPCWait_q, wait);
318
319 if (IsBufferNotEmpty(card->chan) || !(card->present))
320 retval |= (POLLIN | POLLRDNORM);
321
322 if (card->free_slots)
323 retval |= (POLLOUT | POLLWRNORM);
324
325 return retval;
326}
327
328static int cpcusb_release(struct inode *inode, struct file *file)
329{
330 CPC_USB_T *card = (CPC_USB_T *) file->private_data;
331 int j, retval = 0;
332
333 if (card == NULL) {
334 dbg("%s - object is NULL", __func__);
335 return CPC_ERR_NO_INTERFACE_PRESENT;
336 }
337
338 /* lock our device */
339 down(&card->sem);
340
341 if (!card->open) {
342 dbg("%s - device not opened", __func__);
343 retval = CPC_ERR_NO_INTERFACE_PRESENT;
344 goto exit_not_opened;
345 }
346
347 /* if device wasn't unplugged kill all urbs */
348 if (card->present) {
349 /* kill read urbs */
350 for (j = 0; j < CPC_USB_URB_CNT; j++) {
351 usb_kill_urb(card->urbs[j].urb);
352 }
353
354 /* kill irq urb */
355 usb_kill_urb(card->intr_in_urb);
356
357 /* kill write urbs */
358 for (j = 0; j < CPC_USB_URB_CNT; j++) {
359 if (atomic_read(&card->wrUrbs[j].busy)) {
360 usb_kill_urb(card->wrUrbs[j].urb);
361 wait_for_completion(&card->wrUrbs[j].finished);
362 }
363 }
364 }
365
366 atomic_dec(&useCount);
367
368 /* last process detached */
369 if (atomic_read(&useCount) == 0) {
370 wake_up(&rmmodWq);
371 }
372
373 if (!card->present && card->open) {
374 /* the device was unplugged before the file was released */
375 up(&card->sem);
376 cpcusb_delete(card);
377 return 0;
378 }
379
380 card->open = 0;
381
382exit_not_opened:
383 up(&card->sem);
384
385 return 0;
386}
387
388static ssize_t cpcusb_read(struct file *file, char *buffer, size_t count,
389 loff_t *ppos)
390{
391 CPC_USB_T *card = (CPC_USB_T *) file->private_data;
392 CPC_CHAN_T *chan;
393 int retval = 0;
394
395 if (count < sizeof(CPC_MSG_T))
396 return CPC_ERR_UNKNOWN;
397
398 /* check if can read from the given address */
399 if (!access_ok(VERIFY_WRITE, buffer, count))
400 return CPC_ERR_UNKNOWN;
401
402 /* lock this object */
403 down(&card->sem);
404
405 /* verify that the device wasn't unplugged */
406 if (!card->present) {
407 up(&card->sem);
408 return CPC_ERR_NO_INTERFACE_PRESENT;
409 }
410
411 if (IsBufferEmpty(card->chan)) {
412 retval = 0;
413 } else {
414 chan = card->chan;
415
416#if 0
417 /* convert LPC2119 params back to SJA1000 params */
418 if (card->deviceRevision >= 0x0200
419 && chan->buf[chan->oidx].type == CPC_MSG_T_CAN_PRMS) {
420 LPC2119_TO_SJA1000_Params(&chan->buf[chan->oidx]);
421 }
422#endif
423
424 if (copy_to_user(buffer, &chan->buf[chan->oidx], count) != 0) {
425 retval = CPC_ERR_IO_TRANSFER;
426 } else {
427 chan->oidx = (chan->oidx + 1) % CPC_MSG_BUF_CNT;
428 chan->WnR = 1;
429 retval = sizeof(CPC_MSG_T);
430 }
431 }
432/* spin_unlock_irqrestore(&card->slock, flags); */
433
434 /* unlock the device */
435 up(&card->sem);
436
437 return retval;
438}
439
440#define SHIFT 1
441static inline void cpcusb_align_buffer_alignment(unsigned char *buf)
442{
443 /* CPC-USB uploads packed bytes. */
444 CPC_MSG_T *cpc = (CPC_MSG_T *) buf;
445 unsigned int i;
446
447 for (i = 0; i < cpc->length + (2 * sizeof(unsigned long)); i++) {
448 ((unsigned char *) &cpc->msgid)[1 + i] =
449 ((unsigned char *) &cpc->msgid)[1 + SHIFT + i];
450 }
451}
452
453static int cpc_get_buffer_count(CPC_CHAN_T *chan)
454{
455 /* check the buffer parameters */
456 if (chan->iidx == chan->oidx)
457 return !chan->WnR ? CPC_MSG_BUF_CNT : 0;
458 else if (chan->iidx >= chan->oidx)
459 return (chan->iidx - chan->oidx) % CPC_MSG_BUF_CNT;
460
461 return (chan->iidx + CPC_MSG_BUF_CNT - chan->oidx) % CPC_MSG_BUF_CNT;
462}
463
464static ssize_t cpcusb_write(struct file *file, const char *buffer,
465 size_t count, loff_t *ppos)
466{
467 CPC_USB_T *card = (CPC_USB_T *) file->private_data;
468 CPC_USB_WRITE_URB_T *wrUrb = NULL;
469
470 ssize_t bytes_written = 0;
471 int retval = 0;
472 int j;
473
474 unsigned char *obuf = NULL;
475 unsigned char type = 0;
476 CPC_MSG_T *info = NULL;
477
478 dbg("%s - entered minor %d, count = %zu, present = %d",
479 __func__, card->minor, count, card->present);
480
481 if (count > sizeof(CPC_MSG_T))
482 return CPC_ERR_UNKNOWN;
483
484 /* check if can read from the given address */
485 if (!access_ok(VERIFY_READ, buffer, count))
486 return CPC_ERR_UNKNOWN;
487
488 /* lock this object */
489 down(&card->sem);
490
491 /* verify that the device wasn't unplugged */
492 if (!card->present) {
493 retval = CPC_ERR_NO_INTERFACE_PRESENT;
494 goto exit;
495 }
496
497 /* verify that we actually have some data to write */
498 if (count == 0) {
499 dbg("%s - write request of 0 bytes", __func__);
500 goto exit;
501 }
502
503 if (card->free_slots <= 5) {
504 info = (CPC_MSG_T *) buffer;
505
506 if (info->type != CPC_CMD_T_CLEAR_CMD_QUEUE
507 || card->free_slots <= 0) {
508 dbg("%s - send buffer full please try again %d",
509 __func__, card->free_slots);
510 retval = CPC_ERR_CAN_NO_TRANSMIT_BUF;
511 goto exit;
512 }
513 }
514
515 /* Find a free write urb */
516 for (j = 0; j < CPC_USB_URB_CNT; j++) {
517 if (!atomic_read(&card->wrUrbs[j].busy)) {
518 wrUrb = &card->wrUrbs[j]; /* remember found URB */
519 atomic_set(&wrUrb->busy, 1); /* lock this URB */
520 init_completion(&wrUrb->finished); /* init completion */
521 dbg("WR URB no. %d started", j);
522 break;
523 }
524 }
525
526 /* don't found write urb say error */
527 if (!wrUrb) {
528 dbg("%s - no free send urb available", __func__);
529 retval = CPC_ERR_CAN_NO_TRANSMIT_BUF;
530 goto exit;
531 }
532 dbg("URB write req");
533
534 obuf = (unsigned char *) wrUrb->urb->transfer_buffer;
535
536 /* copy the data from userspace into our transfer buffer;
537 * this is the only copy required.
538 */
539 if (copy_from_user(&obuf[4], buffer, count) != 0) {
540 atomic_set(&wrUrb->busy, 0); /* release urb */
541 retval = CPC_ERR_IO_TRANSFER;
542 goto exit;
543 }
544
545 /* check if it is a DRIVER information message, so we can
546 * response to that message and not the USB
547 */
548 info = (CPC_MSG_T *) &obuf[4];
549
550 bytes_written = 11 + info->length;
551 if (bytes_written >= wrUrb->size) {
552 retval = CPC_ERR_IO_TRANSFER;
553 goto exit;
554 }
555
556 switch (info->type) {
557 case CPC_CMD_T_CLEAR_MSG_QUEUE:
558 ResetBuffer(card->chan);
559 break;
560
561 case CPC_CMD_T_INQ_MSG_QUEUE_CNT:
562 retval = cpc_get_buffer_count(card->chan);
563 atomic_set(&wrUrb->busy, 0);
564
565 goto exit;
566
567 case CPC_CMD_T_INQ_INFO:
568 if (info->msg.info.source == CPC_INFOMSG_T_DRIVER) {
569 /* release urb cause we'll use it for driver
570 * information
571 */
572 atomic_set(&wrUrb->busy, 0);
573 if (IsBufferFull(card->chan)) {
574 retval = CPC_ERR_IO_TRANSFER;
575 goto exit;
576 }
577
578 /* it is a driver information request message and we have
579 * free rx slots to store the response
580 */
581 type = info->msg.info.type;
582 info = &card->chan->buf[card->chan->iidx];
583
584 info->type = CPC_MSG_T_INFO;
585 info->msg.info.source = CPC_INFOMSG_T_DRIVER;
586 info->msg.info.type = type;
587
588 switch (type) {
589 case CPC_INFOMSG_T_VERSION:
590 info->length = strlen(CPC_DRIVER_VERSION) + 2;
591 sprintf(info->msg.info.msg, "%s\n",
592 CPC_DRIVER_VERSION);
593 break;
594
595 case CPC_INFOMSG_T_SERIAL:
596 info->length = strlen(CPC_DRIVER_SERIAL) + 2;
597 sprintf(info->msg.info.msg, "%s\n",
598 CPC_DRIVER_SERIAL);
599 break;
600
601 default:
602 info->length = 2;
603 info->msg.info.type =
604 CPC_INFOMSG_T_UNKNOWN_TYPE;
605 }
606
607 card->chan->WnR = 0;
608 card->chan->iidx =
609 (card->chan->iidx + 1) % CPC_MSG_BUF_CNT;
610
611 retval = info->length;
612 goto exit;
613 }
614 break;
615 case CPC_CMD_T_CAN_PRMS:
616 /* Check the controller type. If it's the new CPC-USB, make sure if these are SJA1000 params */
617 if (info->msg.canparams.cc_type != SJA1000
618 && info->msg.canparams.cc_type != M16C_BASIC
619 && (card->productId == USB_CPCUSB_LPC2119_PRODUCT_ID
620 && info->msg.canparams.cc_type != SJA1000)) {
621 /* don't forget to release the urb */
622 atomic_set(&wrUrb->busy, 0);
623 retval = CPC_ERR_WRONG_CONTROLLER_TYPE;
624 goto exit;
625 }
626 break;
627 }
628
629 /* just convert the params if it is an old CPC-USB with M16C controller */
630 if (card->productId == USB_CPCUSB_M16C_PRODUCT_ID) {
631 /* if it is a parameter message convert it from SJA1000 controller
632 * settings to M16C Basic controller settings
633 */
634 SJA1000_TO_M16C_BASIC_Params((CPC_MSG_T *) &obuf[4]);
635 }
636
637 /* don't forget the byte alignment */
638 cpcusb_align_buffer_alignment(&obuf[4]);
639
640 /* setup a the 4 byte header */
641 obuf[0] = obuf[1] = obuf[2] = obuf[3] = 0;
642
643 /* this urb was already set up, except for this write size */
644 wrUrb->urb->transfer_buffer_length = bytes_written + 4;
645
646 /* send the data out the bulk port */
647 /* a character device write uses GFP_KERNEL,
648 unless a spinlock is held */
649 retval = usb_submit_urb(wrUrb->urb, GFP_KERNEL);
650 if (retval) {
651 atomic_set(&wrUrb->busy, 0); /* release urb */
652 err("%s - failed submitting write urb, error %d",
653 __func__, retval);
654 } else {
655 retval = bytes_written;
656 }
657
658exit:
659 /* unlock the device */
660 up(&card->sem);
661
662 dbg("%s - leaved", __func__);
663
664 return retval;
665}
666
667/*
668 * callback for interrupt IN urb
669 */
670static void cpcusb_read_interrupt_callback(struct urb *urb)
671{
672 CPC_USB_T *card = (CPC_USB_T *) urb->context;
673 int retval;
674 unsigned long flags;
675
676 spin_lock_irqsave(&card->slock, flags);
677
678 if (!card->present) {
679 spin_unlock_irqrestore(&card->slock, flags);
680 info("%s - no such device", __func__);
681 return;
682 }
683
684 switch (urb->status) {
685 case 0: /* success */
686 card->free_slots = card->intr_in_buffer[1];
687 break;
688 case -ECONNRESET:
689 case -ENOENT:
690 case -ESHUTDOWN:
691 /* urb was killed */
692 spin_unlock_irqrestore(&card->slock, flags);
693 dbg("%s - intr urb killed", __func__);
694 return;
695 default:
696 info("%s - nonzero urb status %d", __func__, urb->status);
697 break;
698 }
699
700 retval = usb_submit_urb(urb, GFP_ATOMIC);
701 if (retval) {
702 err("%s - failed resubmitting intr urb, error %d",
703 __func__, retval);
704 }
705
706 spin_unlock_irqrestore(&card->slock, flags);
707 wake_up_interruptible(card->chan->CPCWait_q);
708
709 return;
710}
711
712#define UN_SHIFT 1
713#define CPCMSG_HEADER_LEN_FIRMWARE 11
714static inline int cpcusb_unalign_and_copy_buffy(unsigned char *out,
715 unsigned char *in)
716{
717 unsigned int i, j;
718
719 for (i = 0; i < 3; i++)
720 out[i] = in[i];
721
722 for (j = 0; j < (in[1] + (CPCMSG_HEADER_LEN_FIRMWARE - 3)); j++)
723 out[j + i + UN_SHIFT] = in[j + i];
724
725 return i + j;
726}
727
728/*
729 * callback for bulk IN urb
730 */
731static void cpcusb_read_bulk_callback(struct urb *urb)
732{
733 CPC_USB_T *card = (CPC_USB_T *) urb->context;
734 CPC_CHAN_T *chan;
735 unsigned char *ibuf = urb->transfer_buffer;
736 int retval, msgCnt, start, again = 0;
737 unsigned long flags;
738
739 if (!card) {
740 err("%s - device object lost", __func__);
741 return;
742 }
743
744 spin_lock_irqsave(&card->slock, flags);
745
746 if (!card->present) {
747 spin_unlock_irqrestore(&card->slock, flags);
748 info("%s - no such device", __func__);
749 return;
750 }
751
752 switch (urb->status) {
753 case 0: /* success */
754 break;
755 case -ECONNRESET:
756 case -ENOENT:
757 case -ESHUTDOWN:
758 /* urb was killed */
759 spin_unlock_irqrestore(&card->slock, flags);
760 dbg("%s - read urb killed", __func__);
761 return;
762 default:
763 info("%s - nonzero urb status %d", __func__, urb->status);
764 break;
765 }
766
767 if (urb->actual_length) {
768 msgCnt = ibuf[0] & ~0x80;
769 again = ibuf[0] & 0x80;
770
771 /* we have a 4 byte header */
772 start = 4;
773 chan = card->chan;
774 while (msgCnt) {
775 if (!(IsBufferFull(card->chan))) {
776 start +=
777 cpcusb_unalign_and_copy_buffy((unsigned char *)
778 &chan->buf[chan->iidx], &ibuf[start]);
779
780 if (start > urb->transfer_buffer_length) {
781 err("%d > %d", start, urb->transfer_buffer_length);
782 break;
783 }
784
785 chan->WnR = 0;
786 chan->iidx = (chan->iidx + 1) % CPC_MSG_BUF_CNT;
787 msgCnt--;
788 } else {
789 break;
790 }
791 }
792 }
793
794 usb_fill_bulk_urb(urb, card->udev,
795 usb_rcvbulkpipe(card->udev, card->num_bulk_in),
796 urb->transfer_buffer,
797 urb->transfer_buffer_length,
798 cpcusb_read_bulk_callback, card);
799
800 retval = usb_submit_urb(urb, GFP_ATOMIC);
801
802 if (retval) {
803 err("%s - failed resubmitting read urb, error %d", __func__, retval);
804 }
805
806 spin_unlock_irqrestore(&card->slock, flags);
807
808 wake_up_interruptible(card->chan->CPCWait_q);
809}
810
811/*
812 * callback for bulk IN urb
813 */
814static void cpcusb_write_bulk_callback(struct urb *urb)
815{
816 CPC_USB_T *card = (CPC_USB_T *) urb->context;
817 unsigned long flags;
818 int j;
819
820 spin_lock_irqsave(&card->slock, flags);
821
822 /* find this urb */
823 for (j = 0; j < CPC_USB_URB_CNT; j++) {
824 if (card->wrUrbs[j].urb == urb) {
825 dbg("URB found no. %d", j);
826 /* notify anyone waiting that the write has finished */
827 complete(&card->wrUrbs[j].finished);
828 atomic_set(&card->wrUrbs[j].busy, 0);
829 break;
830 }
831 }
832
833 switch (urb->status) {
834 case 0: /* success */
835 break;
836 case -ECONNRESET:
837 case -ENOENT:
838 case -ESHUTDOWN:
839 /* urb was killed */
840 spin_unlock_irqrestore(&card->slock, flags);
841 dbg("%s - write urb no. %d killed", __func__, j);
842 return;
843 default:
844 info("%s - nonzero urb status %d", __func__, urb->status);
845 break;
846 }
847
848 spin_unlock_irqrestore(&card->slock, flags);
849
850 wake_up_interruptible(card->chan->CPCWait_q);
851}
852
853static inline int cpcusb_get_free_slot(void)
854{
855 int i;
856
857 for (i = 0; i < CPC_USB_CARD_CNT; i++) {
858 if (!CPCUSB_Table[i])
859 return i;
860 }
861
862 return -1;
863}
864
865/*
866 * probe function for new CPC-USB devices
867 */
868static int cpcusb_probe(struct usb_interface *interface,
869 const struct usb_device_id *id)
870{
871 CPC_USB_T *card = NULL;
872 CPC_CHAN_T *chan = NULL;
873
874 struct usb_device *udev = interface_to_usbdev(interface);
875 struct usb_host_interface *iface_desc;
876 struct usb_endpoint_descriptor *endpoint;
877
878 int i, j, retval = -ENOMEM, slot;
879
880 slot = cpcusb_get_free_slot();
881 if (slot < 0) {
882 info("No more devices supported");
883 return -ENOMEM;
884 }
885
886 /* allocate memory for our device state and initialize it */
887 card = kzalloc(sizeof(CPC_USB_T), GFP_KERNEL);
888 if (!card) {
889 err("Out of memory");
890 return -ENOMEM;
891 }
892 CPCUSB_Table[slot] = card;
893
894 /* allocate and initialize the channel struct */
895 card->chan = kmalloc(sizeof(CPC_CHAN_T), GFP_KERNEL);
896 if (!card->chan) {
897 kfree(card);
898 err("Out of memory");
899 return -ENOMEM;
900 }
901
902 chan = card->chan;
903 memset(chan, 0, sizeof(CPC_CHAN_T));
904 ResetBuffer(chan);
905
906 init_MUTEX(&card->sem);
907 spin_lock_init(&card->slock);
908
909 card->udev = udev;
910 card->interface = interface;
911 if (udev->descriptor.iSerialNumber) {
912 usb_string(udev, udev->descriptor.iSerialNumber, card->serialNumber,
913 128);
914 info("Serial %s", card->serialNumber);
915 }
916
917 card->productId = udev->descriptor.idProduct;
918 info("Product %s",
919 card->productId == USB_CPCUSB_LPC2119_PRODUCT_ID ?
920 "CPC-USB/ARM7" : "CPC-USB/M16C");
921
922 /* set up the endpoint information */
923 /* check out the endpoints */
924 /* use only the first bulk-in and bulk-out endpoints */
925 iface_desc = &interface->altsetting[0];
926 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
927 endpoint = &iface_desc->endpoint[i].desc;
928
929 if (!card->num_intr_in &&
930 (endpoint->bEndpointAddress & USB_DIR_IN) &&
931 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
932 == USB_ENDPOINT_XFER_INT)) {
933 card->intr_in_urb = usb_alloc_urb(0, GFP_KERNEL);
934 card->num_intr_in = 1;
935
936 if (!card->intr_in_urb) {
937 err("No free urbs available");
938 goto error;
939 }
940
941 dbg("intr_in urb %d", card->num_intr_in);
942 }
943
944 if (!card->num_bulk_in &&
945 (endpoint->bEndpointAddress & USB_DIR_IN) &&
946 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
947 == USB_ENDPOINT_XFER_BULK)) {
948 card->num_bulk_in = 2;
949 for (j = 0; j < CPC_USB_URB_CNT; j++) {
950 card->urbs[j].size = endpoint->wMaxPacketSize;
951 card->urbs[j].urb = usb_alloc_urb(0, GFP_KERNEL);
952 if (!card->urbs[j].urb) {
953 err("No free urbs available");
954 goto error;
955 }
956 card->urbs[j].buffer =
957 usb_buffer_alloc(udev,
958 card->urbs[j].size,
959 GFP_KERNEL,
960 &card->urbs[j].urb->transfer_dma);
961 if (!card->urbs[j].buffer) {
962 err("Couldn't allocate bulk_in_buffer");
963 goto error;
964 }
965 }
966 info("%s - %d reading URB's allocated",
967 __func__, CPC_USB_URB_CNT);
968 }
969
970 if (!card->num_bulk_out &&
971 !(endpoint->bEndpointAddress & USB_DIR_IN) &&
972 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
973 == USB_ENDPOINT_XFER_BULK)) {
974
975 card->num_bulk_out = 2;
976
977 for (j = 0; j < CPC_USB_URB_CNT; j++) {
978 card->wrUrbs[j].size =
979 endpoint->wMaxPacketSize;
980 card->wrUrbs[j].urb =
981 usb_alloc_urb(0, GFP_KERNEL);
982 if (!card->wrUrbs[j].urb) {
983 err("No free urbs available");
984 goto error;
985 }
986 card->wrUrbs[j].buffer = usb_buffer_alloc(udev,
987 card->wrUrbs[j].size, GFP_KERNEL,
988 &card->wrUrbs[j].urb->transfer_dma);
989
990 if (!card->wrUrbs[j].buffer) {
991 err("Couldn't allocate bulk_out_buffer");
992 goto error;
993 }
994
995 usb_fill_bulk_urb(card->wrUrbs[j].urb, udev,
996 usb_sndbulkpipe(udev, endpoint->bEndpointAddress),
997 card->wrUrbs[j].buffer,
998 card->wrUrbs[j].size,
999 cpcusb_write_bulk_callback,
1000 card);
1001 }
1002
1003 info("%s - %d writing URB's allocated", __func__, CPC_USB_URB_CNT);
1004 }
1005 }
1006
1007 if (!(card->num_bulk_in && card->num_bulk_out)) {
1008 err("Couldn't find both bulk-in and bulk-out endpoints");
1009 goto error;
1010 }
1011
1012 /* allow device read, write and ioctl */
1013 card->present = 1;
1014
1015 /* we can register the device now, as it is ready */
1016 usb_set_intfdata(interface, card);
1017 retval = usb_register_dev(interface, &cpcusb_class);
1018
1019 if (retval) {
1020 /* something prevented us from registering this driver */
1021 err("Not able to get a minor for this device.");
1022 usb_set_intfdata(interface, NULL);
1023 goto error;
1024 }
1025
1026 card->chan->minor = card->minor = interface->minor;
1027
1028 chan->buf = vmalloc(sizeof(CPC_MSG_T) * CPC_MSG_BUF_CNT);
1029 if (chan->buf == NULL) {
1030 err("Out of memory");
1031 retval = -ENOMEM;
1032 goto error;
1033 }
1034 info("Allocated memory for %d messages (%lu kbytes)",
1035 CPC_MSG_BUF_CNT, (long unsigned int)(sizeof(CPC_MSG_T) * CPC_MSG_BUF_CNT) / 1000);
1036 memset(chan->buf, 0, sizeof(CPC_MSG_T) * CPC_MSG_BUF_CNT);
1037
1038 ResetBuffer(chan);
1039
1040 card->chan->CPCWait_q = kmalloc(sizeof(wait_queue_head_t), GFP_KERNEL);
1041 if (!card->chan->CPCWait_q) {
1042 err("Out of memory");
1043 retval = -ENOMEM;
1044 goto error;
1045 }
1046 init_waitqueue_head(card->chan->CPCWait_q);
1047
1048 CPCUSB_Table[slot] = card;
1049 card->idx = slot;
1050 CPCUsbCnt++;
1051
1052 /* let the user know what node this device is now attached to */
1053 info("Device now attached to USB-%d", card->minor);
1054 return 0;
1055
1056error:
1057 for (j = 0; j < CPC_USB_URB_CNT; j++) {
1058 if (card->urbs[j].buffer) {
1059 usb_buffer_free(card->udev, card->urbs[j].size,
1060 card->urbs[j].buffer,
1061 card->urbs[j].urb->transfer_dma);
1062 card->urbs[j].buffer = NULL;
1063 }
1064 if (card->urbs[j].urb) {
1065 usb_free_urb(card->urbs[j].urb);
1066 card->urbs[j].urb = NULL;
1067 }
1068 }
1069
1070 cpcusb_delete(card);
1071 return retval;
1072}
1073
1074/*
1075 * called by the usb core when the device is removed from the system
1076 */
1077static void cpcusb_disconnect(struct usb_interface *interface)
1078{
1079 CPC_USB_T *card = NULL;
1080 int minor, j;
1081
1082 /* prevent races with open() */
1083 down(&disconnect_sem);
1084
1085 card = usb_get_intfdata(interface);
1086 usb_set_intfdata(interface, NULL);
1087
1088 down(&card->sem);
1089
1090 /* prevent device read, write and ioctl */
1091 card->present = 0;
1092
1093 minor = card->minor;
1094
1095 /* free all urbs and their buffers */
1096 for (j = 0; j < CPC_USB_URB_CNT; j++) {
1097 /* terminate an ongoing write */
1098 if (atomic_read(&card->wrUrbs[j].busy)) {
1099 usb_kill_urb(card->wrUrbs[j].urb);
1100 wait_for_completion(&card->wrUrbs[j].finished);
1101 }
1102 usb_buffer_free(card->udev, card->wrUrbs[j].size,
1103 card->wrUrbs[j].buffer,
1104 card->wrUrbs[j].urb->transfer_dma);
1105 usb_free_urb(card->wrUrbs[j].urb);
1106 }
1107 info("%d write URBs freed", CPC_USB_URB_CNT);
1108
1109 /* free all urbs and their buffers */
1110 for (j = 0; j < CPC_USB_URB_CNT; j++) {
1111 usb_buffer_free(card->udev, card->urbs[j].size,
1112 card->urbs[j].buffer,
1113 card->urbs[j].urb->transfer_dma);
1114 usb_free_urb(card->urbs[j].urb);
1115 }
1116 info("%d read URBs freed", CPC_USB_URB_CNT);
1117 usb_free_urb(card->intr_in_urb);
1118
1119 /* give back our minor */
1120 usb_deregister_dev(interface, &cpcusb_class);
1121
1122 up(&card->sem);
1123
1124 /* if the device is opened, cpcusb_release will clean this up */
1125 if (!card->open)
1126 cpcusb_delete(card);
1127 else
1128 wake_up_interruptible(card->chan->CPCWait_q);
1129
1130 up(&disconnect_sem);
1131
1132 CPCUsbCnt--;
1133 info("USB-%d now disconnected", minor);
1134}
1135
1136static int __init CPCUsb_Init(void)
1137{
1138 int result, i;
1139
1140 info(DRIVER_DESC " v" DRIVER_VERSION);
1141 info("Build on " __DATE__ " at " __TIME__);
1142
1143 for (i = 0; i < CPC_USB_CARD_CNT; i++)
1144 CPCUSB_Table[i] = 0;
1145
1146 /* register this driver with the USB subsystem */
1147 result = usb_register(&cpcusb_driver);
1148 if (result) {
1149 err("usb_register failed. Error number %d", result);
1150 return result;
1151 }
1152
1153 procDir = proc_mkdir(CPC_USB_PROC_DIR, NULL);
1154 if (!procDir) {
1155 err("Could not create proc entry");
1156 } else {
1157 procEntry = create_proc_read_entry("info", 0444, procDir,
1158 cpcusb_proc_read_info,
1159 NULL);
1160 if (!procEntry) {
1161 err("Could not create proc entry %s", CPC_USB_PROC_DIR "/info");
1162 remove_proc_entry(CPC_USB_PROC_DIR, NULL);
1163 procDir = NULL;
1164 }
1165 }
1166
1167 return 0;
1168}
1169
1170static void __exit CPCUsb_Exit(void)
1171{
1172 wait_event(rmmodWq, !atomic_read(&useCount));
1173
1174 /* deregister this driver with the USB subsystem */
1175 usb_deregister(&cpcusb_driver);
1176
1177 if (procDir) {
1178 if (procEntry)
1179 remove_proc_entry("info", procDir);
1180 remove_proc_entry(CPC_USB_PROC_DIR, NULL);
1181 }
1182}
1183
1184module_init(CPCUsb_Init);
1185module_exit(CPCUsb_Exit);
diff --git a/drivers/staging/cpc-usb/cpc.h b/drivers/staging/cpc-usb/cpc.h
deleted file mode 100644
index ed8cb34d4763..000000000000
--- a/drivers/staging/cpc-usb/cpc.h
+++ /dev/null
@@ -1,440 +0,0 @@
1/*
2 * CPC CAN Interface Definitions
3 *
4 * Copyright (C) 2000-2008 EMS Dr. Thomas Wuensche
5 *
6 * This program is distributed in the hope that it will be useful, but
7 * WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 */
10#ifndef CPC_HEADER
11#define CPC_HEADER
12
13// the maximum length of the union members within a CPC_MSG
14// this value can be defined by the customer, but has to be
15// >= 64 bytes
16// however, if not defined before, we set a length of 64 byte
17#if !defined(CPC_MSG_LEN) || (CPC_MSG_LEN < 64)
18#undef CPC_MSG_LEN
19#define CPC_MSG_LEN 64
20#endif
21
22// check the operating system used
23#ifdef _WIN32 // running a Windows OS
24
25// define basic types on Windows platforms
26#ifdef _MSC_VER // Visual Studio
27 typedef unsigned __int8 u8;
28 typedef unsigned __int16 u16;
29 typedef unsigned __int32 u32;
30#else // Borland Compiler
31 typedef unsigned char u8;
32 typedef unsigned short u16;
33 typedef unsigned int u32;
34#endif
35 // on Windows OS we use a byte alignment of 1
36 #pragma pack(push, 1)
37
38 // set the calling conventions for the library function calls
39 #define CALL_CONV __stdcall
40#else
41 // Kernel headers already define this types
42 #ifndef __KERNEL__
43 // define basic types
44 typedef unsigned char u8;
45 typedef unsigned short u16;
46 typedef unsigned int u32;
47 #endif
48
49 // Linux does not use this calling convention
50 #define CALL_CONV
51#endif
52
53// Transmission of events from CPC interfaces to PC can be individually
54// controlled per event type. Default state is: don't transmit
55// Control values are constructed by bit-or of Subject and Action
56// and passed to CPC_Control()
57
58// Control-Values for CPC_Control() Command Subject Selection
59#define CONTR_CAN_Message 0x04
60#define CONTR_Busload 0x08
61#define CONTR_CAN_State 0x0C
62#define CONTR_SendAck 0x10
63#define CONTR_Filter 0x14
64#define CONTR_CmdQueue 0x18 // reserved, do not use
65#define CONTR_BusError 0x1C
66
67// Control Command Actions
68#define CONTR_CONT_OFF 0
69#define CONTR_CONT_ON 1
70#define CONTR_SING_ON 2
71// CONTR_SING_ON doesn't change CONTR_CONT_ON state, so it should be
72// read as: transmit at least once
73
74// defines for confirmed request
75#define DO_NOT_CONFIRM 0
76#define DO_CONFIRM 1
77
78// event flags
79#define EVENT_READ 0x01
80#define EVENT_WRITE 0x02
81
82// Messages from CPC to PC contain a message object type field.
83// The following message types are sent by CPC and can be used in
84// handlers, others should be ignored.
85#define CPC_MSG_T_RESYNC 0 // Normally to be ignored
86#define CPC_MSG_T_CAN 1 // CAN data frame
87#define CPC_MSG_T_BUSLOAD 2 // Busload message
88#define CPC_MSG_T_STRING 3 // Normally to be ignored
89#define CPC_MSG_T_CONTI 4 // Normally to be ignored
90#define CPC_MSG_T_MEM 7 // Normally not to be handled
91#define CPC_MSG_T_RTR 8 // CAN remote frame
92#define CPC_MSG_T_TXACK 9 // Send acknowledge
93#define CPC_MSG_T_POWERUP 10 // Power-up message
94#define CPC_MSG_T_CMD_NO 11 // Normally to be ignored
95#define CPC_MSG_T_CAN_PRMS 12 // Actual CAN parameters
96#define CPC_MSG_T_ABORTED 13 // Command aborted message
97#define CPC_MSG_T_CANSTATE 14 // CAN state message
98#define CPC_MSG_T_RESET 15 // used to reset CAN-Controller
99#define CPC_MSG_T_XCAN 16 // XCAN data frame
100#define CPC_MSG_T_XRTR 17 // XCAN remote frame
101#define CPC_MSG_T_INFO 18 // information strings
102#define CPC_MSG_T_CONTROL 19 // used for control of interface/driver behaviour
103#define CPC_MSG_T_CONFIRM 20 // response type for confirmed requests
104#define CPC_MSG_T_OVERRUN 21 // response type for overrun conditions
105#define CPC_MSG_T_KEEPALIVE 22 // response type for keep alive conditions
106#define CPC_MSG_T_CANERROR 23 // response type for bus error conditions
107#define CPC_MSG_T_DISCONNECTED 24 // response type for a disconnected interface
108#define CPC_MSG_T_ERR_COUNTER 25 // RX/TX error counter of CAN controller
109
110#define CPC_MSG_T_FIRMWARE 100 // response type for USB firmware download
111
112// Messages from the PC to the CPC interface contain a command field
113// Most of the command types are wrapped by the library functions and have therefore
114// normally not to be used.
115// However, programmers who wish to circumvent the library and talk directly
116// to the drivers (mainly Linux programmers) can use the following
117// command types:
118
119#define CPC_CMD_T_CAN 1 // CAN data frame
120#define CPC_CMD_T_CONTROL 3 // used for control of interface/driver behaviour
121#define CPC_CMD_T_CAN_PRMS 6 // set CAN parameters
122#define CPC_CMD_T_CLEARBUF 8 // clears input queue; this is depricated, use CPC_CMD_T_CLEAR_MSG_QUEUE instead
123#define CPC_CMD_T_INQ_CAN_PARMS 11 // inquire actual CAN parameters
124#define CPC_CMD_T_FILTER_PRMS 12 // set filter parameter
125#define CPC_CMD_T_RTR 13 // CAN remote frame
126#define CPC_CMD_T_CANSTATE 14 // CAN state message
127#define CPC_CMD_T_XCAN 15 // XCAN data frame
128#define CPC_CMD_T_XRTR 16 // XCAN remote frame
129#define CPC_CMD_T_RESET 17 // used to reset CAN-Controller
130#define CPC_CMD_T_INQ_INFO 18 // miscellanous information strings
131#define CPC_CMD_T_OPEN_CHAN 19 // open a channel
132#define CPC_CMD_T_CLOSE_CHAN 20 // close a channel
133#define CPC_CMD_T_CNTBUF 21 // this is depricated, use CPC_CMD_T_INQ_MSG_QUEUE_CNT instead
134#define CPC_CMD_T_CAN_EXIT 200 // exit the CAN (disable interrupts; reset bootrate; reset output_cntr; mode = 1)
135
136#define CPC_CMD_T_INQ_MSG_QUEUE_CNT CPC_CMD_T_CNTBUF // inquires the count of elements in the message queue
137#define CPC_CMD_T_INQ_ERR_COUNTER 25 // request the CAN controllers error counter
138#define CPC_CMD_T_CLEAR_MSG_QUEUE CPC_CMD_T_CLEARBUF // clear CPC_MSG queue
139#define CPC_CMD_T_CLEAR_CMD_QUEUE 28 // clear CPC_CMD queue
140#define CPC_CMD_T_FIRMWARE 100 // reserved, must not be used
141#define CPC_CMD_T_USB_RESET 101 // reserved, must not be used
142#define CPC_CMD_T_WAIT_NOTIFY 102 // reserved, must not be used
143#define CPC_CMD_T_WAIT_SETUP 103 // reserved, must not be used
144#define CPC_CMD_T_ABORT 255 // Normally not to be used
145
146// definitions for CPC_MSG_T_INFO
147// information sources
148#define CPC_INFOMSG_T_UNKNOWN_SOURCE 0
149#define CPC_INFOMSG_T_INTERFACE 1
150#define CPC_INFOMSG_T_DRIVER 2
151#define CPC_INFOMSG_T_LIBRARY 3
152
153// information types
154#define CPC_INFOMSG_T_UNKNOWN_TYPE 0
155#define CPC_INFOMSG_T_VERSION 1
156#define CPC_INFOMSG_T_SERIAL 2
157
158// definitions for controller types
159#define PCA82C200 1 // Philips basic CAN controller, replaced by SJA1000
160#define SJA1000 2 // Philips basic CAN controller
161#define AN82527 3 // Intel full CAN controller
162#define M16C_BASIC 4 // M16C controller running in basic CAN (not full CAN) mode
163
164// channel open error codes
165#define CPC_ERR_NO_FREE_CHANNEL -1 // no more free space within the channel array
166#define CPC_ERR_CHANNEL_ALREADY_OPEN -2 // the channel is already open
167#define CPC_ERR_CHANNEL_NOT_ACTIVE -3 // access to a channel not active failed
168#define CPC_ERR_NO_DRIVER_PRESENT -4 // no driver at the location searched by the library
169#define CPC_ERR_NO_INIFILE_PRESENT -5 // the library could not find the inifile
170#define CPC_ERR_WRONG_PARAMETERS -6 // wrong parameters in the inifile
171#define CPC_ERR_NO_INTERFACE_PRESENT -7 // 1. The specified interface is not connected
172 // 2. The interface (mostly CPC-USB) was disconnected upon operation
173#define CPC_ERR_NO_MATCHING_CHANNEL -8 // the driver couldn't find a matching channel
174#define CPC_ERR_NO_BUFFER_AVAILABLE -9 // the driver couldn't allocate buffer for messages
175#define CPC_ERR_NO_INTERRUPT -10 // the requested interrupt couldn't be claimed
176#define CPC_ERR_NO_MATCHING_INTERFACE -11 // no interface type related to this channel was found
177#define CPC_ERR_NO_RESOURCES -12 // the requested resources could not be claimed
178#define CPC_ERR_SOCKET -13 // error concerning TCP sockets
179
180// init error codes
181#define CPC_ERR_WRONG_CONTROLLER_TYPE -14 // wrong CAN controller type within initialization
182#define CPC_ERR_NO_RESET_MODE -15 // the controller could not be set into reset mode
183#define CPC_ERR_NO_CAN_ACCESS -16 // the CAN controller could not be accessed
184
185// transmit error codes
186#define CPC_ERR_CAN_WRONG_ID -20 // the provided CAN id is too big
187#define CPC_ERR_CAN_WRONG_LENGTH -21 // the provided CAN length is too long
188#define CPC_ERR_CAN_NO_TRANSMIT_BUF -22 // the transmit buffer was occupied
189#define CPC_ERR_CAN_TRANSMIT_TIMEOUT -23 // The message could not be sent within a
190 // specified time
191
192// other error codes
193#define CPC_ERR_SERVICE_NOT_SUPPORTED -30 // the requested service is not supported by the interface
194#define CPC_ERR_IO_TRANSFER -31 // a transmission error down to the driver occurred
195#define CPC_ERR_TRANSMISSION_FAILED -32 // a transmission error down to the interface occurred
196#define CPC_ERR_TRANSMISSION_TIMEOUT -33 // a timeout occurred within transmission to the interface
197#define CPC_ERR_OP_SYS_NOT_SUPPORTED -35 // the operating system is not supported
198#define CPC_ERR_UNKNOWN -40 // an unknown error ocurred (mostly IOCTL errors)
199
200#define CPC_ERR_LOADING_DLL -50 // the library 'cpcwin.dll' could not be loaded
201#define CPC_ERR_ASSIGNING_FUNCTION -51 // the specified function could not be assigned
202#define CPC_ERR_DLL_INITIALIZATION -52 // the DLL was not initialized correctly
203#define CPC_ERR_MISSING_LICFILE -55 // the file containing the licenses does not exist
204#define CPC_ERR_MISSING_LICENSE -56 // a required license was not found
205
206// CAN state bit values. Ignore any bits not listed
207#define CPC_CAN_STATE_BUSOFF 0x80
208#define CPC_CAN_STATE_ERROR 0x40
209
210// Mask to help ignore undefined bits
211#define CPC_CAN_STATE_MASK 0xc0
212
213// CAN-Message representation in a CPC_MSG
214// Message object type is CPC_MSG_T_CAN or CPC_MSG_T_RTR
215// or CPC_MSG_T_XCAN or CPC_MSG_T_XRTR
216typedef struct CPC_CAN_MSG {
217 u32 id;
218 u8 length;
219 u8 msg[8];
220} CPC_CAN_MSG_T;
221
222
223// representation of the CAN parameters for the PCA82C200 controller
224typedef struct CPC_PCA82C200_PARAMS {
225 u8 acc_code; // Acceptance-code for receive, Standard: 0
226 u8 acc_mask; // Acceptance-mask for receive, Standard: 0xff (everything)
227 u8 btr0; // Bus-timing register 0
228 u8 btr1; // Bus-timing register 1
229 u8 outp_contr; // Output-control register
230} CPC_PCA82C200_PARAMS_T;
231
232// representation of the CAN parameters for the SJA1000 controller
233typedef struct CPC_SJA1000_PARAMS {
234 u8 mode; // enables single or dual acceptance filtering
235 u8 acc_code0; // Acceptance-code for receive, Standard: 0
236 u8 acc_code1;
237 u8 acc_code2;
238 u8 acc_code3;
239 u8 acc_mask0; // Acceptance-mask for receive, Standard: 0xff (everything)
240 u8 acc_mask1;
241 u8 acc_mask2;
242 u8 acc_mask3;
243 u8 btr0; // Bus-timing register 0
244 u8 btr1; // Bus-timing register 1
245 u8 outp_contr; // Output-control register
246} CPC_SJA1000_PARAMS_T;
247
248// representation of the CAN parameters for the M16C controller
249// in basic CAN mode (means no full CAN)
250typedef struct CPC_M16C_BASIC_PARAMS {
251 u8 con0;
252 u8 con1;
253 u8 ctlr0;
254 u8 ctlr1;
255 u8 clk;
256 u8 acc_std_code0;
257 u8 acc_std_code1;
258 u8 acc_ext_code0;
259 u8 acc_ext_code1;
260 u8 acc_ext_code2;
261 u8 acc_ext_code3;
262 u8 acc_std_mask0;
263 u8 acc_std_mask1;
264 u8 acc_ext_mask0;
265 u8 acc_ext_mask1;
266 u8 acc_ext_mask2;
267 u8 acc_ext_mask3;
268} CPC_M16C_BASIC_PARAMS_T;
269
270// CAN params message representation
271typedef struct CPC_CAN_PARAMS {
272 u8 cc_type; // represents the controller type
273 union {
274 CPC_M16C_BASIC_PARAMS_T m16c_basic;
275 CPC_SJA1000_PARAMS_T sja1000;
276 CPC_PCA82C200_PARAMS_T pca82c200;
277 } cc_params;
278} CPC_CAN_PARAMS_T;
279
280// the following structures are slightly different for Windows and Linux
281// To be able to use the 'Select' mechanism with Linux the application
282// needs to know the devices file desciptor.
283// This mechanism is not implemented within Windows and the file descriptor
284// is therefore not needed
285#ifdef _WIN32
286
287// CAN init params message representation
288typedef struct CPC_INIT_PARAMS {
289 CPC_CAN_PARAMS_T canparams;
290} CPC_INIT_PARAMS_T;
291
292#else// Linux
293
294// CHAN init params representation
295typedef struct CPC_CHAN_PARAMS {
296 int fd;
297} CPC_CHAN_PARAMS_T;
298
299// CAN init params message representation
300typedef struct CPC_INIT_PARAMS {
301 CPC_CHAN_PARAMS_T chanparams;
302 CPC_CAN_PARAMS_T canparams;
303} CPC_INIT_PARAMS_T;
304
305#endif
306
307// structure for confirmed message handling
308typedef struct CPC_CONFIRM {
309 u8 result; // error code
310} CPC_CONFIRM_T;
311
312// structure for information requests
313typedef struct CPC_INFO {
314 u8 source; // interface, driver or library
315 u8 type; // version or serial number
316 char msg[CPC_MSG_LEN - 2]; // string holding the requested information
317} CPC_INFO_T;
318
319// OVERRUN ///////////////////////////////////////
320// In general two types of overrun may occur.
321// A hardware overrun, where the CAN controller
322// lost a message, because the interrupt was
323// not handled before the next messgae comes in.
324// Or a software overrun, where i.e. a received
325// message could not be stored in the CPC_MSG
326// buffer.
327
328// After a software overrun has occurred
329// we wait until we have CPC_OVR_GAP slots
330// free in the CPC_MSG buffer.
331#define CPC_OVR_GAP 10
332
333// Two types of software overrun may occur.
334// A received CAN message or a CAN state event
335// can cause an overrun.
336// Note: A CPC_CMD which would normally store
337// its result immediately in the CPC_MSG
338// queue may fail, because the message queue is full.
339// This will not generate an overrun message, but
340// will halt command execution, until this command
341// is able to store its message in the message queue.
342#define CPC_OVR_EVENT_CAN 0x01
343#define CPC_OVR_EVENT_CANSTATE 0x02
344#define CPC_OVR_EVENT_BUSERROR 0x04
345
346// If the CAN controller lost a message
347// we indicate it with the highest bit
348// set in the count field.
349#define CPC_OVR_HW 0x80
350
351// structure for overrun conditions
352typedef struct {
353 u8 event;
354 u8 count;
355} CPC_OVERRUN_T;
356
357// CAN errors ////////////////////////////////////
358// Each CAN controller type has different
359// registers to record errors.
360// Therefor a structure containing the specific
361// errors is set up for each controller here
362
363// SJA1000 error structure
364// see the SJA1000 datasheet for detailed
365// explanation of the registers
366typedef struct CPC_SJA1000_CAN_ERROR {
367 u8 ecc; // error capture code register
368 u8 rxerr; // RX error counter register
369 u8 txerr; // TX error counter register
370} CPC_SJA1000_CAN_ERROR_T;
371
372// M16C error structure
373// see the M16C datasheet for detailed
374// explanation of the registers
375typedef struct CPC_M16C_CAN_ERROR {
376 u8 tbd; // to be defined
377} CPC_M16C_CAN_ERROR_T;
378
379// structure for CAN error conditions
380#define CPC_CAN_ECODE_ERRFRAME 0x01
381typedef struct CPC_CAN_ERROR {
382 u8 ecode;
383 struct {
384 u8 cc_type; // CAN controller type
385 union {
386 CPC_SJA1000_CAN_ERROR_T sja1000;
387 CPC_M16C_CAN_ERROR_T m16c;
388 } regs;
389 } cc;
390} CPC_CAN_ERROR_T;
391
392// Structure containing RX/TX error counter.
393// This structure is used to request the
394// values of the CAN controllers TX and RX
395// error counter.
396typedef struct CPC_CAN_ERR_COUNTER {
397 u8 rx;
398 u8 tx;
399} CPC_CAN_ERR_COUNTER_T;
400
401// If this flag is set, transmissions from PC to CPC are protected against loss
402#define CPC_SECURE_TO_CPC 0x01
403
404// If this flag is set, transmissions from CPC to PC are protected against loss
405#define CPC_SECURE_TO_PC 0x02
406
407// If this flag is set, the CAN-transmit buffer is checked to be free before sending a message
408#define CPC_SECURE_SEND 0x04
409
410// If this flag is set, the transmission complete flag is checked
411// after sending a message
412// THIS IS CURRENTLY ONLY IMPLEMENTED IN THE PASSIVE INTERFACE DRIVERS
413#define CPC_SECURE_TRANSMIT 0x08
414
415// main message type used between library and application
416typedef struct CPC_MSG {
417 u8 type; // type of message
418 u8 length; // length of data within union 'msg'
419 u8 msgid; // confirmation handle
420 u32 ts_sec; // timestamp in seconds
421 u32 ts_nsec; // timestamp in nano seconds
422 union {
423 u8 generic[CPC_MSG_LEN];
424 CPC_CAN_MSG_T canmsg;
425 CPC_CAN_PARAMS_T canparams;
426 CPC_CONFIRM_T confirmation;
427 CPC_INFO_T info;
428 CPC_OVERRUN_T overrun;
429 CPC_CAN_ERROR_T error;
430 CPC_CAN_ERR_COUNTER_T err_counter;
431 u8 busload;
432 u8 canstate;
433 } msg;
434} CPC_MSG_T;
435
436#ifdef _WIN32
437#pragma pack(pop) // reset the byte alignment
438#endif
439
440#endif // CPC_HEADER
diff --git a/drivers/staging/cpc-usb/cpc_int.h b/drivers/staging/cpc-usb/cpc_int.h
deleted file mode 100644
index a0d60c080819..000000000000
--- a/drivers/staging/cpc-usb/cpc_int.h
+++ /dev/null
@@ -1,83 +0,0 @@
1/*
2 * CPCLIB
3 *
4 * Copyright (C) 2000-2008 EMS Dr. Thomas Wuensche
5 *
6 * This program is distributed in the hope that it will be useful, but
7 * WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 *
10 */
11#ifndef CPC_INT_H
12#define CPC_INT_H
13
14#include <linux/wait.h>
15
16#define CPC_MSG_BUF_CNT 1500
17
18#define CPC_PROC_DIR "driver/"
19
20#undef dbg
21#undef err
22#undef info
23
24/* Use our own dbg macro */
25#define dbg(format, arg...) do { if (debug) printk( KERN_INFO format "\n" , ## arg); } while (0)
26#define err(format, arg...) do { printk( KERN_INFO "ERROR " format "\n" , ## arg); } while (0)
27#define info(format, arg...) do { printk( KERN_INFO format "\n" , ## arg); } while (0)
28
29/* Macros help using of our buffers */
30#define IsBufferFull(x) (!(x)->WnR) && ((x)->iidx == (x)->oidx)
31#define IsBufferEmpty(x) ((x)->WnR) && ((x)->iidx == (x)->oidx)
32#define IsBufferNotEmpty(x) (!(x)->WnR) || ((x)->iidx != (x)->oidx)
33#define ResetBuffer(x) do { (x)->oidx = (x)->iidx=0; (x)->WnR = 1; } while(0);
34
35#define CPC_BufWriteAllowed ((chan->oidx != chan->iidx) || chan->WnR)
36
37typedef void (*chan_write_byte_t) (void *chan, unsigned int reg,
38 unsigned char val);
39typedef unsigned char (*chan_read_byte_t) (void *chan, unsigned int reg);
40
41typedef struct CPC_CHAN {
42 void __iomem * canBase; // base address of SJA1000
43 chan_read_byte_t read_byte; // CAN controller read access routine
44 chan_write_byte_t write_byte; // CAN controller write access routine
45 CPC_MSG_T *buf; // buffer for CPC msg
46 unsigned int iidx;
47 unsigned int oidx;
48 unsigned int WnR;
49 unsigned int minor;
50 unsigned int locked;
51 unsigned int irqDisabled;
52
53 unsigned char cpcCtrlCANMessage;
54 unsigned char cpcCtrlCANState;
55 unsigned char cpcCtrlBUSState;
56
57 unsigned char controllerType;
58
59 unsigned long ovrTimeSec;
60 unsigned long ovrTimeNSec;
61 unsigned long ovrLockedBuffer;
62 CPC_OVERRUN_T ovr;
63
64 /* for debugging only */
65 unsigned int handledIrqs;
66 unsigned int lostMessages;
67
68 unsigned int sentStdCan;
69 unsigned int sentExtCan;
70 unsigned int sentStdRtr;
71 unsigned int sentExtRtr;
72
73 unsigned int recvStdCan;
74 unsigned int recvExtCan;
75 unsigned int recvStdRtr;
76 unsigned int recvExtRtr;
77
78 wait_queue_head_t *CPCWait_q;
79
80 void *private;
81} CPC_CHAN_T;
82
83#endif
diff --git a/drivers/staging/cpc-usb/cpcusb.h b/drivers/staging/cpc-usb/cpcusb.h
deleted file mode 100644
index e5273ddd9e0a..000000000000
--- a/drivers/staging/cpc-usb/cpcusb.h
+++ /dev/null
@@ -1,86 +0,0 @@
1/* Header for CPC-USB Driver ********************
2 * Copyright 1999, 2000, 2001
3 *
4 * Company: EMS Dr. Thomas Wuensche
5 * Sonnenhang 3
6 * 85304 Ilmmuenster
7 * Phone: +49-8441-490260
8 * Fax: +49-8441-81860
9 * email: support@ems-wuensche.com
10 * WWW: www.ems-wuensche.com
11 */
12
13#ifndef CPCUSB_H
14#define CPCUSB_H
15
16#undef err
17#undef dbg
18#undef info
19
20/* Use our own dbg macro */
21#define dbg(format, arg...) do { if (debug) printk(KERN_INFO "CPC-USB: " format "\n" , ## arg); } while (0)
22#define info(format, arg...) do { printk(KERN_INFO "CPC-USB: " format "\n" , ## arg); } while (0)
23#define err(format, arg...) do { printk(KERN_INFO "CPC-USB(ERROR): " format "\n" , ## arg); } while (0)
24
25#define CPC_USB_CARD_CNT 4
26
27typedef struct CPC_USB_READ_URB {
28 unsigned char *buffer; /* the buffer to send data */
29 size_t size; /* the size of the send buffer */
30 struct urb *urb; /* the urb used to send data */
31} CPC_USB_READ_URB_T;
32
33typedef struct CPC_USB_WRITE_URB {
34 unsigned char *buffer; /* the buffer to send data */
35 size_t size; /* the size of the send buffer */
36 struct urb *urb; /* the urb used to send data */
37 atomic_t busy; /* true if write urb is busy */
38 struct completion finished; /* wait for the write to finish */
39} CPC_USB_WRITE_URB_T;
40
41#define CPC_USB_URB_CNT 10
42
43typedef struct CPC_USB {
44 struct usb_device *udev; /* save off the usb device pointer */
45 struct usb_interface *interface; /* the interface for this device */
46 unsigned char minor; /* the starting minor number for this device */
47 unsigned char num_ports; /* the number of ports this device has */
48 int num_intr_in; /* number of interrupt in endpoints we have */
49 int num_bulk_in; /* number of bulk in endpoints we have */
50 int num_bulk_out; /* number of bulk out endpoints we have */
51
52 CPC_USB_READ_URB_T urbs[CPC_USB_URB_CNT];
53
54 unsigned char intr_in_buffer[4]; /* interrupt transfer buffer */
55 struct urb *intr_in_urb; /* interrupt transfer urb */
56
57 CPC_USB_WRITE_URB_T wrUrbs[CPC_USB_URB_CNT];
58
59 int open; /* if the port is open or not */
60 int present; /* if the device is not disconnected */
61 struct semaphore sem; /* locks this structure */
62
63 int free_slots; /* free send slots of CPC-USB */
64 int idx;
65
66 spinlock_t slock;
67
68 char serialNumber[128]; /* serial number */
69 int productId; /* product id to differ between M16C and LPC2119 */
70 CPC_CHAN_T *chan;
71} CPC_USB_T;
72
73#define CPCTable CPCUSB_Table
74
75#define CPC_DRIVER_VERSION "0.724"
76#define CPC_DRIVER_SERIAL "not applicable"
77
78#define OBUF_SIZE 255 // 4096
79
80/* read timeouts -- RD_NAK_TIMEOUT * RD_EXPIRE = Number of seconds */
81#define RD_NAK_TIMEOUT (10*HZ) /* Default number of X seconds to wait */
82#define RD_EXPIRE 12 /* Number of attempts to wait X seconds */
83
84#define CPC_USB_BASE_MNR 0 /* CPC-USB start at minor 0 */
85
86#endif
diff --git a/drivers/staging/cpc-usb/sja2m16c.h b/drivers/staging/cpc-usb/sja2m16c.h
deleted file mode 100644
index 654bd3fc91dc..000000000000
--- a/drivers/staging/cpc-usb/sja2m16c.h
+++ /dev/null
@@ -1,41 +0,0 @@
1#ifndef _SJA2M16C_H
2#define _SJA2M16C_H
3
4#include "cpc.h"
5
6#define BAUDRATE_TOLERANCE_PERCENT 1
7#define SAMPLEPOINT_TOLERANCE_PERCENT 5
8#define SAMPLEPOINT_UPPER_LIMIT 88
9
10/* M16C parameters */
11struct FIELD_C0CONR {
12 unsigned int brp:4;
13 unsigned int sam:1;
14 unsigned int pr:3;
15 unsigned int dummy:8;
16};
17struct FIELD_C1CONR {
18 unsigned int ph1:3;
19 unsigned int ph2:3;
20 unsigned int sjw:2;
21 unsigned int dummy:8;
22};
23typedef union C0CONR {
24 unsigned char c0con;
25 struct FIELD_C0CONR bc0con;
26} C0CONR_T;
27typedef union C1CONR {
28 unsigned char c1con;
29 struct FIELD_C1CONR bc1con;
30} C1CONR_T;
31
32#define SJA_TSEG1 ((pParams->btr1 & 0x0f)+1)
33#define SJA_TSEG2 (((pParams->btr1 & 0x70)>>4)+1)
34#define SJA_BRP ((pParams->btr0 & 0x3f)+1)
35#define SJA_SJW ((pParams->btr0 & 0xc0)>>6)
36#define SJA_SAM ((pParams->btr1 & 0x80)>>7)
37int baudrate_m16c(int clk, int brp, int pr, int ph1, int ph2);
38int samplepoint_m16c(int brp, int pr, int ph1, int ph2);
39int SJA1000_TO_M16C_BASIC_Params(CPC_MSG_T *pMsg);
40
41#endif
diff --git a/drivers/staging/cpc-usb/sja2m16c_2.c b/drivers/staging/cpc-usb/sja2m16c_2.c
deleted file mode 100644
index bf0230fb7780..000000000000
--- a/drivers/staging/cpc-usb/sja2m16c_2.c
+++ /dev/null
@@ -1,452 +0,0 @@
1/****************************************************************************
2*
3* Copyright (c) 2003,2004 by EMS Dr. Thomas Wuensche
4*
5* - All rights reserved -
6*
7* This code is provided "as is" without warranty of any kind, either
8* expressed or implied, including but not limited to the liability
9* concerning the freedom from material defects, the fitness for parti-
10* cular purposes or the freedom of proprietary rights of third parties.
11*
12*****************************************************************************
13* Module name.: cpcusb
14*****************************************************************************
15* Include file: cpc.h
16*****************************************************************************
17* Project.....: Windows Driver Development Kit
18* Filename....: sja2m16c.cpp
19* Authors.....: (GU) Gerhard Uttenthaler
20* (CS) Christian Schoett
21*****************************************************************************
22* Short descr.: converts baudrate between SJA1000 and M16C
23*****************************************************************************
24* Description.: handles the baudrate conversion from SJA1000 parameters to
25* M16C parameters
26*****************************************************************************
27* Address : EMS Dr. Thomas Wuensche
28* Sonnenhang 3
29* D-85304 Ilmmuenster
30* Tel. : +49-8441-490260
31* Fax. : +49-8441-81860
32* email: support@ems-wuensche.com
33*****************************************************************************
34* History
35*****************************************************************************
36* Version Date Auth Remark
37*
38* 01.00 ?? GU - initial release
39* 01.10 ?????????? CS - adapted to fit into the USB Windows driver
40* 02.00 18.08.2004 GU - improved the baudrate calculating algorithm
41* - implemented acceptance filtering
42* 02.10 10.09.2004 CS - adapted to fit into the USB Windows driver
43*****************************************************************************
44* ToDo's
45*****************************************************************************
46*/
47
48/****************************************************************************/
49/* I N C L U D E S
50*/
51#include <linux/kernel.h>
52#include <linux/errno.h>
53#include <linux/init.h>
54#include <linux/slab.h>
55#include <linux/vmalloc.h>
56#include <linux/module.h>
57#include <linux/poll.h>
58#include <linux/smp_lock.h>
59#include <linux/completion.h>
60#include <asm/uaccess.h>
61#include <linux/usb.h>
62
63#include "cpc.h"
64#include "cpc_int.h"
65#include "cpcusb.h"
66
67#include "sja2m16c.h"
68
69/*********************************************************************/
70int baudrate_m16c(int clk, int brp, int pr, int ph1, int ph2)
71{
72 return (16000000 / (1 << clk)) / 2 / (brp + 1) / (1 + pr + 1 +
73 ph1 + 1 + ph2 +
74 1);
75}
76
77
78/*********************************************************************/
79int samplepoint_m16c(int brp, int pr, int ph1, int ph2)
80{
81 return (100 * (1 + pr + 1 + ph1 + 1)) / (1 + pr + 1 + ph1 + 1 +
82 ph2 + 1);
83}
84
85
86/****************************************************************************
87* Function.....: SJA1000_TO_M16C_BASIC_Params
88*
89* Task.........: This routine converts SJA1000 CAN btr parameters into M16C
90* parameters based on the sample point and the error. In
91* addition it converts the acceptance filter parameters to
92* suit the M16C parameters
93*
94* Parameters...: None
95*
96* Return values: None
97*
98* Comments.....:
99*****************************************************************************
100* History
101*****************************************************************************
102* 19.01.2005 CS - modifed the conversion of SJA1000 filter params into
103* M16C params. Due to compatibility reasons with the
104* older 82C200 CAN controller the SJA1000
105****************************************************************************/
106int SJA1000_TO_M16C_BASIC_Params(CPC_MSG_T * in)
107{
108 int sjaBaudrate;
109 int sjaSamplepoint;
110 int *baudrate_error; // BRP[0..15], PR[0..7], PH1[0..7], PH2[0..7]
111 int *samplepoint_error; // BRP[0..15], PR[0..7], PH1[0..7], PH2[0..7]
112 int baudrate_error_merk;
113 int clk, brp, pr, ph1, ph2;
114 int clk_merk, brp_merk, pr_merk, ph1_merk, ph2_merk;
115 int index;
116 unsigned char acc_code0, acc_code1, acc_code2, acc_code3;
117 unsigned char acc_mask0, acc_mask1, acc_mask2, acc_mask3;
118 CPC_MSG_T * out;
119 C0CONR_T c0con;
120 C1CONR_T c1con;
121 int tmpAccCode;
122 int tmpAccMask;
123
124 // we have to convert the parameters into M16C parameters
125 CPC_SJA1000_PARAMS_T * pParams;
126
127 // check if the type is CAN parameters and if we have to convert the given params
128 if (in->type != CPC_CMD_T_CAN_PRMS
129 || in->msg.canparams.cc_type != SJA1000)
130 return 0;
131 pParams =
132 (CPC_SJA1000_PARAMS_T *) & in->msg.canparams.cc_params.sja1000;
133 acc_code0 = pParams->acc_code0;
134 acc_code1 = pParams->acc_code1;
135 acc_code2 = pParams->acc_code2;
136 acc_code3 = pParams->acc_code3;
137 acc_mask0 = pParams->acc_mask0;
138 acc_mask1 = pParams->acc_mask1;
139 acc_mask2 = pParams->acc_mask2;
140 acc_mask3 = pParams->acc_mask3;
141
142#ifdef _DEBUG_OUTPUT_CAN_PARAMS
143 info("acc_code0: %2.2Xh\n", acc_code0);
144 info("acc_code1: %2.2Xh\n", acc_code1);
145 info("acc_code2: %2.2Xh\n", acc_code2);
146 info("acc_code3: %2.2Xh\n", acc_code3);
147 info("acc_mask0: %2.2Xh\n", acc_mask0);
148 info("acc_mask1: %2.2Xh\n", acc_mask1);
149 info("acc_mask2: %2.2Xh\n", acc_mask2);
150 info("acc_mask3: %2.2Xh\n", acc_mask3);
151
152#endif /* */
153 if (!
154 (baudrate_error =
155 (int *) vmalloc(sizeof(int) * 16 * 8 * 8 * 8 * 5))) {
156 err("Could not allocate memory\n");
157 return -3;
158 }
159 if (!
160 (samplepoint_error =
161 (int *) vmalloc(sizeof(int) * 16 * 8 * 8 * 8 * 5))) {
162 err("Could not allocate memory\n");
163 vfree(baudrate_error);
164 return -3;
165 }
166 memset(baudrate_error, 0xff, sizeof(baudrate_error));
167 memset(samplepoint_error, 0xff, sizeof(baudrate_error));
168 sjaBaudrate =
169 16000000 / 2 / SJA_BRP / (1 + SJA_TSEG1 + SJA_TSEG2);
170 sjaSamplepoint =
171 100 * (1 + SJA_TSEG1) / (1 + SJA_TSEG1 + SJA_TSEG2);
172 if (sjaBaudrate == 0) {
173 vfree(baudrate_error);
174 vfree(samplepoint_error);
175 return -2;
176 }
177
178#ifdef _DEBUG_OUTPUT_CAN_PARAMS
179 info("\nStarting SJA CAN params\n");
180 info("-------------------------\n");
181 info("TS1 : %2.2Xh TS2 : %2.2Xh\n", SJA_TSEG1, SJA_TSEG2);
182 info("BTR0 : %2.2Xh BTR1: %2.2Xh\n", pParams->btr0,
183 pParams->btr1);
184 info("Baudrate: %d.%dkBaud\n", sjaBaudrate / 1000,
185 sjaBaudrate % 1000);
186 info("Sample P: 0.%d\n", sjaSamplepoint);
187 info("\n");
188
189#endif /* */
190 c0con.bc0con.sam = SJA_SAM;
191 c1con.bc1con.sjw = SJA_SJW;
192
193 // calculate errors for all baudrates
194 index = 0;
195 for (clk = 0; clk < 5; clk++) {
196 for (brp = 0; brp < 16; brp++) {
197 for (pr = 0; pr < 8; pr++) {
198 for (ph1 = 0; ph1 < 8; ph1++) {
199 for (ph2 = 0; ph2 < 8; ph2++) {
200 baudrate_error[index] =
201 100 *
202 abs(baudrate_m16c
203 (clk, brp, pr, ph1,
204 ph2) -
205 sjaBaudrate) /
206 sjaBaudrate;
207 samplepoint_error[index] =
208 abs(samplepoint_m16c
209 (brp, pr, ph1,
210 ph2) -
211 sjaSamplepoint);
212
213#if 0
214 info
215 ("Baudrate : %d kBaud\n",
216 baudrate_m16c(clk,
217 brp, pr,
218 ph1,
219 ph2));
220 info
221 ("Baudrate Error: %d\n",
222 baudrate_error
223 [index]);
224 info
225 ("Sample P Error: %d\n",
226 samplepoint_error
227 [index]);
228 info
229 ("clk : %d\n",
230 clk);
231
232#endif /* */
233 index++;
234 }
235 }
236 }
237 }
238 }
239
240 // mark all baudrate_error entries which are outer limits
241 index = 0;
242 for (clk = 0; clk < 5; clk++) {
243 for (brp = 0; brp < 16; brp++) {
244 for (pr = 0; pr < 8; pr++) {
245 for (ph1 = 0; ph1 < 8; ph1++) {
246 for (ph2 = 0; ph2 < 8; ph2++) {
247 if ((baudrate_error[index]
248 >
249 BAUDRATE_TOLERANCE_PERCENT)
250 ||
251 (samplepoint_error
252 [index] >
253 SAMPLEPOINT_TOLERANCE_PERCENT)
254 ||
255 (samplepoint_m16c
256 (brp, pr, ph1,
257 ph2) >
258 SAMPLEPOINT_UPPER_LIMIT))
259 {
260 baudrate_error
261 [index] = -1;
262 } else
263 if (((1 + pr + 1 +
264 ph1 + 1 + ph2 +
265 1) < 8)
266 ||
267 ((1 + pr + 1 +
268 ph1 + 1 + ph2 +
269 1) > 25)) {
270 baudrate_error
271 [index] = -1;
272 }
273
274#if 0
275 else {
276 info
277 ("Baudrate : %d kBaud\n",
278 baudrate_m16c
279 (clk, brp, pr,
280 ph1, ph2));
281 info
282 ("Baudrate Error: %d\n",
283 baudrate_error
284 [index]);
285 info
286 ("Sample P Error: %d\n",
287 samplepoint_error
288 [index]);
289 }
290
291#endif /* */
292 index++;
293 }
294 }
295 }
296 }
297 }
298
299 // find list of minimum of baudrate_error within unmarked entries
300 clk_merk = brp_merk = pr_merk = ph1_merk = ph2_merk = 0;
301 baudrate_error_merk = 100;
302 index = 0;
303 for (clk = 0; clk < 5; clk++) {
304 for (brp = 0; brp < 16; brp++) {
305 for (pr = 0; pr < 8; pr++) {
306 for (ph1 = 0; ph1 < 8; ph1++) {
307 for (ph2 = 0; ph2 < 8; ph2++) {
308 if (baudrate_error[index]
309 != -1) {
310 if (baudrate_error
311 [index] <
312 baudrate_error_merk)
313 {
314 baudrate_error_merk
315 =
316 baudrate_error
317 [index];
318 brp_merk =
319 brp;
320 pr_merk =
321 pr;
322 ph1_merk =
323 ph1;
324 ph2_merk =
325 ph2;
326 clk_merk =
327 clk;
328
329#if 0
330 info
331 ("brp: %2.2Xh pr: %2.2Xh ph1: %2.2Xh ph2: %2.2Xh\n",
332 brp,
333 pr,
334 ph1,
335 ph2);
336 info
337 ("Baudrate : %d kBaud\n",
338 baudrate_m16c
339 (clk,
340 brp,
341 pr,
342 ph1,
343 ph2));
344 info
345 ("Baudrate Error: %d\n",
346 baudrate_error
347 [index]);
348 info
349 ("Sample P Error: %d\n",
350 samplepoint_error
351 [index]);
352
353#endif /* */
354 }
355 }
356 index++;
357 }
358 }
359 }
360 }
361 }
362 if (baudrate_error_merk == 100) {
363 info("ERROR: Could not convert CAN init parameter\n");
364 vfree(baudrate_error);
365 vfree(samplepoint_error);
366 return -1;
367 }
368
369 // setting m16c CAN parameter
370 c0con.bc0con.brp = brp_merk;
371 c0con.bc0con.pr = pr_merk;
372 c1con.bc1con.ph1 = ph1_merk;
373 c1con.bc1con.ph2 = ph2_merk;
374
375#ifdef _DEBUG_OUTPUT_CAN_PARAMS
376 info("\nResulting M16C CAN params\n");
377 info("-------------------------\n");
378 info("clk : %2.2Xh\n", clk_merk);
379 info("ph1 : %2.2Xh ph2: %2.2Xh\n", c1con.bc1con.ph1 + 1,
380 c1con.bc1con.ph2 + 1);
381 info("pr : %2.2Xh brp: %2.2Xh\n", c0con.bc0con.pr + 1,
382 c0con.bc0con.brp + 1);
383 info("sjw : %2.2Xh sam: %2.2Xh\n", c1con.bc1con.sjw,
384 c0con.bc0con.sam);
385 info("co1 : %2.2Xh co0: %2.2Xh\n", c1con.c1con, c0con.c0con);
386 info("Baudrate: %d.%dBaud\n",
387 baudrate_m16c(clk_merk, c0con.bc0con.brp, c0con.bc0con.pr,
388 c1con.bc1con.ph1, c1con.bc1con.ph2) / 1000,
389 baudrate_m16c(clk_merk, c0con.bc0con.brp, c0con.bc0con.pr,
390 c1con.bc1con.ph1, c1con.bc1con.ph2) % 1000);
391 info("Sample P: 0.%d\n",
392 samplepoint_m16c(c0con.bc0con.brp, c0con.bc0con.pr,
393 c1con.bc1con.ph1, c1con.bc1con.ph2));
394 info("\n");
395
396#endif /* */
397 out = in;
398 out->type = 6;
399 out->length = sizeof(CPC_M16C_BASIC_PARAMS_T) + 1;
400 out->msg.canparams.cc_type = M16C_BASIC;
401 out->msg.canparams.cc_params.m16c_basic.con0 = c0con.c0con;
402 out->msg.canparams.cc_params.m16c_basic.con1 = c1con.c1con;
403 out->msg.canparams.cc_params.m16c_basic.ctlr0 = 0x4C;
404 out->msg.canparams.cc_params.m16c_basic.ctlr1 = 0x00;
405 out->msg.canparams.cc_params.m16c_basic.clk = clk_merk;
406 out->msg.canparams.cc_params.m16c_basic.acc_std_code0 =
407 acc_code0;
408 out->msg.canparams.cc_params.m16c_basic.acc_std_code1 = acc_code1;
409
410// info("code0: 0x%2.2X, code1: 0x%2.2X\n", out->msg.canparams.cc_params.m16c_basic.acc_std_code0, out->msg.canparams.cc_params.m16c_basic.acc_std_code1);
411 tmpAccCode = (acc_code1 >> 5) + (acc_code0 << 3);
412 out->msg.canparams.cc_params.m16c_basic.acc_std_code0 =
413 (unsigned char) tmpAccCode;
414 out->msg.canparams.cc_params.m16c_basic.acc_std_code1 =
415 (unsigned char) (tmpAccCode >> 8);
416
417// info("code0: 0x%2.2X, code1: 0x%2.2X\n", out->msg.canparams.cc_params.m16c_basic.acc_std_code0, out->msg.canparams.cc_params.m16c_basic.acc_std_code1);
418 out->msg.canparams.cc_params.m16c_basic.acc_std_mask0 =
419 ~acc_mask0;
420 out->msg.canparams.cc_params.m16c_basic.acc_std_mask1 =
421 ~acc_mask1;
422
423// info("mask0: 0x%2.2X, mask1: 0x%2.2X\n", out->msg.canparams.cc_params.m16c_basic.acc_std_mask0, out->msg.canparams.cc_params.m16c_basic.acc_std_mask1);
424 tmpAccMask = ((acc_mask1) >> 5) + ((acc_mask0) << 3);
425
426// info("tmpAccMask: 0x%4.4X\n", tmpAccMask);
427 out->msg.canparams.cc_params.m16c_basic.acc_std_mask0 =
428 (unsigned char) ~tmpAccMask;
429 out->msg.canparams.cc_params.m16c_basic.acc_std_mask1 =
430 (unsigned char) ~(tmpAccMask >> 8);
431
432// info("mask0: 0x%2.2X, mask1: 0x%2.2X\n", out->msg.canparams.cc_params.m16c_basic.acc_std_mask0, out->msg.canparams.cc_params.m16c_basic.acc_std_mask1);
433 out->msg.canparams.cc_params.m16c_basic.acc_ext_code0 =
434 (unsigned char) tmpAccCode;
435 out->msg.canparams.cc_params.m16c_basic.acc_ext_code1 =
436 (unsigned char) (tmpAccCode >> 8);
437 out->msg.canparams.cc_params.m16c_basic.acc_ext_code2 = acc_code2;
438 out->msg.canparams.cc_params.m16c_basic.acc_ext_code3 = acc_code3;
439 out->msg.canparams.cc_params.m16c_basic.acc_ext_mask0 =
440 (unsigned char) ~tmpAccMask;
441 out->msg.canparams.cc_params.m16c_basic.acc_ext_mask1 =
442 (unsigned char) ~(tmpAccMask >> 8);
443 out->msg.canparams.cc_params.m16c_basic.acc_ext_mask2 =
444 ~acc_mask2;
445 out->msg.canparams.cc_params.m16c_basic.acc_ext_mask3 =
446 ~acc_mask3;
447 vfree(baudrate_error);
448 vfree(samplepoint_error);
449 return 0;
450}
451
452