]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/usbcan.c
cb1c9b0b2d285433fefec52715c629ca03ccdf5f
[lincan.git] / lincan / src / usbcan.c
1 /* usbcan.h
2  * Header file for the Linux CAN-bus driver.
3  * Written by Jan Kriz email:johen@post.cz
4  * This software is released under the GPL-License.
5  * Version lincan-0.3  17 Jul 2008
6  */
7
8 #include "../include/kthread.h"
9 #include "../include/can.h"
10 #include "../include/can_sysdep.h"
11 #include "../include/main.h"
12 #include "../include/devcommon.h"
13 #include "../include/setup.h"
14 #include "../include/usbcan.h"
15
16 /**
17  * usbcan_request_io: - reserve io or memory range for can board
18  * @candev: pointer to candevice/board which asks for io. Field @io_addr
19  *      of @candev is used in most cases to define start of the range
20  *
21  * The function usbcan_request_io() is used to reserve the io-memory. If your
22  * hardware uses a dedicated memory range as hardware control registers you
23  * will have to add the code to reserve this memory as well.
24  * %IO_RANGE is the io-memory range that gets reserved, please adjust according
25  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
26  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
27  * Return Value: The function returns zero on success or %-ENODEV on failure
28  * File: src/usbcan.c
29  */
30 int usbcan_request_io(struct candevice_t *candev)
31 {
32         struct usbcan_usb *dev = (struct usbcan_usb*)candev->sysdevptr.anydev;
33
34         /* start kernel thread */
35         dev->rcvthread.arg = dev;
36         start_kthread(usbcan_read_kthread, &dev->rcvthread);
37
38         /* Adding link to can device into usbcan_usb struct */
39         ((struct usbcan_usb*)candev->sysdevptr.anydev)->candev=candev;
40         return 0;
41 }
42
43 /**
44  * usbcan_release_io - free reserved io memory range
45  * @candev: pointer to candevice/board which releases io
46  *
47  * The function usbcan_release_io() is used to free reserved io-memory.
48  * In case you have reserved more io memory, don't forget to free it here.
49  * IO_RANGE is the io-memory range that gets released, please adjust according
50  * your hardware. Example: #define IO_RANGE 0x100 for i82527 chips or
51  * #define IO_RANGE 0x20 for sja1000 chips in basic CAN mode.
52  * Return Value: The function always returns zero
53  * File: src/usbcan.c
54  */
55 int usbcan_release_io(struct candevice_t *candev)
56 {
57         struct usbcan_usb *dev = ((struct usbcan_usb*)candev->sysdevptr.anydev);
58
59         /* terminate the kernel thread */
60         if (dev->rcv){
61                 usb_kill_urb(dev->rcv);
62                 usb_free_urb(dev->rcv);
63         }
64         stop_kthread(&dev->rcvthread);
65         return 0;
66 }
67
68 /**
69  * usbcan_reset - hardware reset routine
70  * @candev: Pointer to candevice/board structure
71  *
72  * The function usbcan_reset() is used to give a hardware reset. This is
73  * rather hardware specific so I haven't included example code. Don't forget to
74  * check the reset status of the chip before returning.
75  * Return Value: The function returns zero on success or %-ENODEV on failure
76  * File: src/usbcan.c
77  */
78 int usbcan_reset(struct candevice_t *candev)
79 {
80         return 0;
81 }
82
83 /**
84  * usbcan_init_hw_data - Initialize hardware cards
85  * @candev: Pointer to candevice/board structure
86  *
87  * The function usbcan_init_hw_data() is used to initialize the hardware
88  * structure containing information about the installed CAN-board.
89  * %RESET_ADDR represents the io-address of the hardware reset register.
90  * %NR_82527 represents the number of Intel 82527 chips on the board.
91  * %NR_SJA1000 represents the number of Philips sja1000 chips on the board.
92  * The flags entry can currently only be %CANDEV_PROGRAMMABLE_IRQ to indicate that
93  * the hardware uses programmable interrupts.
94  * Return Value: The function always returns zero
95  * File: src/usbcan.c
96  */
97 int usbcan_init_hw_data(struct candevice_t *candev)
98 {
99         candev->res_addr=RESET_ADDR;
100         candev->nr_82527_chips=0;
101         candev->nr_sja1000_chips=0;
102         candev->nr_all_chips=1;
103         candev->flags |= CANDEV_PROGRAMMABLE_IRQ*0;
104
105         return 0;
106 }
107
108 /**
109  * usbcan_init_obj_data - Initialize message buffers
110  * @chip: Pointer to chip specific structure
111  * @objnr: Number of the message buffer
112  *
113  * The function usbcan_init_obj_data() is used to initialize the hardware
114  * structure containing information about the different message objects on the
115  * CAN chip. In case of the sja1000 there's only one message object but on the
116  * i82527 chip there are 15.
117  * The code below is for a i82527 chip and initializes the object base addresses
118  * The entry @obj_base_addr represents the first memory address of the message
119  * object. In case of the sja1000 @obj_base_addr is taken the same as the chips
120  * base address.
121  * Unless the hardware uses a segmented memory map, flags can be set zero.
122  * Return Value: The function always returns zero
123  * File: src/usbcan.c
124  */
125 int usbcan_init_obj_data(struct canchip_t *chip, int objnr)
126 {
127         chip->msgobj[objnr]->obj_base_addr=chip->chip_base_addr+(objnr+1)*0x10;
128
129         return 0;
130 }
131
132 /**
133  * usbcan_program_irq - program interrupts
134  * @candev: Pointer to candevice/board structure
135  *
136  * The function usbcan_program_irq() is used for hardware that uses
137  * programmable interrupts. If your hardware doesn't use programmable interrupts
138  * you should not set the @candevices_t->flags entry to %CANDEV_PROGRAMMABLE_IRQ and
139  * leave this function unedited. Again this function is hardware specific so
140  * there's no example code.
141  * Return value: The function returns zero on success or %-ENODEV on failure
142  * File: src/usbcan.c
143  */
144 int usbcan_program_irq(struct candevice_t *candev)
145 {
146         return 0;
147 }
148
149 /* !!! Don't change this function !!! */
150 int usbcan_register(struct hwspecops_t *hwspecops)
151 {
152         hwspecops->request_io = usbcan_request_io;
153         hwspecops->release_io = usbcan_release_io;
154         hwspecops->reset = usbcan_reset;
155         hwspecops->init_hw_data = usbcan_init_hw_data;
156         hwspecops->init_chip_data = usbcan_init_chip_data;
157         hwspecops->init_obj_data = usbcan_init_obj_data;
158         hwspecops->write_register = NULL;
159         hwspecops->read_register = NULL;
160         hwspecops->program_irq = usbcan_program_irq;
161         return 0;
162 }
163
164 static int sja1000_report_error_limit_counter;
165
166 static void sja1000_report_error(struct canchip_t *chip,
167                                 unsigned sr, unsigned ir, unsigned ecc)
168 {
169         /*TODO : Error reporting from device */
170
171 /*      if(sja1000_report_error_limit_counter>=100)
172                 return;
173
174         CANMSG("Error: status register: 0x%x irq_register: 0x%02x error: 0x%02x\n",
175                 sr, ir, ecc);
176
177         sja1000_report_error_limit_counter+=10;
178
179         if(sja1000_report_error_limit_counter>=100){
180                 sja1000_report_error_limit_counter+=10;
181                 CANMSG("Error: too many errors, reporting disabled\n");
182                 return;
183         }
184
185 #ifdef CONFIG_OC_LINCAN_DETAILED_ERRORS
186         CANMSG("SR: BS=%c  ES=%c  TS=%c  RS=%c  TCS=%c TBS=%c DOS=%c RBS=%c\n",
187                 sr&sjaSR_BS?'1':'0',sr&sjaSR_ES?'1':'0',
188                 sr&sjaSR_TS?'1':'0',sr&sjaSR_RS?'1':'0',
189                 sr&sjaSR_TCS?'1':'0',sr&sjaSR_TBS?'1':'0',
190                 sr&sjaSR_DOS?'1':'0',sr&sjaSR_RBS?'1':'0');
191         CANMSG("IR: BEI=%c ALI=%c EPI=%c WUI=%c DOI=%c EI=%c  TI=%c  RI=%c\n",
192                 sr&sjaIR_BEI?'1':'0',sr&sjaIR_ALI?'1':'0',
193                 sr&sjaIR_EPI?'1':'0',sr&sjaIR_WUI?'1':'0',
194                 sr&sjaIR_DOI?'1':'0',sr&sjaIR_EI?'1':'0',
195                 sr&sjaIR_TI?'1':'0',sr&sjaIR_RI?'1':'0');
196         if((sr&sjaIR_EI) || 1){
197                 CANMSG("EI: %s %s %s\n",
198                        sja1000_ecc_errc_str[(ecc&(sjaECC_ERCC1|sjaECC_ERCC0))/sjaECC_ERCC0],
199                        ecc&sjaECC_DIR?"RX":"TX",
200                        sja1000_ecc_seg_str[ecc&sjaECC_SEG_M]
201                       );
202         }
203 #endif /*CONFIG_OC_LINCAN_DETAILED_ERRORS*/
204 }
205
206
207 /**
208  * usbcan_enable_configuration - enable chip configuration mode
209  * @chip: pointer to chip state structure
210  */
211 int usbcan_enable_configuration(struct canchip_t *chip)
212 {
213         return 0;
214 }
215
216 /**
217  * usbcan_disable_configuration - disable chip configuration mode
218  * @chip: pointer to chip state structure
219  */
220 int usbcan_disable_configuration(struct canchip_t *chip)
221 {
222         return 0;
223 }
224
225 /**
226  * usbcan_chip_config: - can chip configuration
227  * @chip: pointer to chip state structure
228  *
229  * This function configures chip and prepares it for message
230  * transmission and reception. The function resets chip,
231  * resets mask for acceptance of all messages by call to
232  * usbcan_extended_mask() function and then
233  * computes and sets baudrate with use of function usbcan_baud_rate().
234  * Return Value: negative value reports error.
235  * File: src/usbcan.c
236  */
237 int usbcan_chip_config(struct canchip_t *chip)
238 {
239         return 0;
240 }
241
242 /**
243  * usbcan_extended_mask: - setup of extended mask for message filtering
244  * @chip: pointer to chip state structure
245  * @code: can message acceptance code
246  * @mask: can message acceptance mask
247  *
248  * Return Value: negative value reports error.
249  * File: src/usbcan.c
250  */
251 int usbcan_extended_mask(struct canchip_t *chip, unsigned long code, unsigned  long mask)
252 {
253         int retval;
254         struct usbcan_usb *dev=(struct usbcan_usb*)chip->hostdevice->sysdevptr.anydev;
255
256         struct usbcan_mask_t mask={
257                 .code=code;
258                 .mask=mask;
259         };
260
261         retval=usb_control_msg(dev->udev,
262                 usb_sndctrlpipe(dev->udev, dev->ctl_out_endpointAddr),
263                 USBCAN_VENDOR_EXT_MASK_SET,
264                 USB_TYPE_VENDOR,
265                 0, chip->chip_idx,
266                 &mask, sizeof(usbcan_mask_t),
267                 10000);
268         if (retval<0)
269                 return -ENODEV;
270
271         retval = usb_control_msg(dev->udev,
272                 usb_rcvctrlpipe(dev->udev, dev->ctl_in_endpointAddr),
273                 USBCAN_VENDOR_EXT_MASK_STATUS,
274                 USB_TYPE_VENDOR,
275                 0, chip->chip_idx,
276                 dev->ctl_in_buffer, dev->ctl_in_size,
277                 10000);
278
279         if (retval==1){
280                 if(dev->ctl_in_buffer[0]==1){
281                         DEBUGMSG("Setting acceptance code to 0x%lx\n",(unsigned long)code);
282                         DEBUGMSG("Setting acceptance mask to 0x%lx\n",(unsigned long)mask);
283                         return 0;
284                 }
285         }
286
287         CANMSG("Setting extended mask failed\n");
288         return -EINVAL;
289 }
290
291 /**
292  * usbcan_baud_rate: - set communication parameters.
293  * @chip: pointer to chip state structure
294  * @rate: baud rate in Hz
295  * @clock: frequency of sja1000 clock in Hz (ISA osc is 14318000)
296  * @sjw: synchronization jump width (0-3) prescaled clock cycles
297  * @sampl_pt: sample point in % (0-100) sets (TSEG1+1)/(TSEG1+TSEG2+2) ratio
298  * @flags: fields %BTR1_SAM, %OCMODE, %OCPOL, %OCTP, %OCTN, %CLK_OFF, %CBP
299  *
300  * Return Value: negative value reports error.
301  * File: src/usbcan.c
302  */
303 int usbcan_baud_rate(struct canchip_t *chip, int rate, int clock, int sjw,
304                                                         int sampl_pt, int flags)
305 {
306         int retval;
307         struct usbcan_usb *dev=(struct usbcan_usb*)chip->hostdevice->sysdevptr.anydev;
308
309         // Data too big to use single receive control message
310         struct can_baudparams_t baud={
311                 .flags=flags,
312                 .baudrate=rate,
313                 .sjw=sjw,
314                 .sample_pt=sampl_pt,
315         };
316
317
318         retval=usb_control_msg(dev->udev,
319                 usb_sndctrlpipe(dev->udev, dev->ctl_out_endpointAddr),
320                 USBCAN_VENDOR_BAUD_RATE_SET,
321                 USB_TYPE_VENDOR,
322                 0, chip->chip_idx,
323                 &baud, sizeof(can_baudparams_t),
324                 10000);
325         if (retval<0)
326                 return -ENODEV;
327
328         retval = usb_control_msg(dev->udev,
329                 usb_rcvctrlpipe(dev->udev, dev->ctl_in_endpointAddr),
330                 USBCAN_VENDOR_BAUD_RATE_STATUS,
331                 USB_TYPE_VENDOR,
332                 0, chip->chip_idx,
333                 dev->ctl_in_buffer, dev->ctl_in_size,
334                 10000);
335
336         if (retval==1){
337                 if(dev->ctl_in_buffer[0]==1)
338                         return 0;
339         }
340
341         CANMSG("baud rate %d is not possible to set\n",
342                 rate);
343         return -EINVAL;
344 }
345
346 /**
347  * usbcan_pre_read_config: - prepares message object for message reception
348  * @chip: pointer to chip state structure
349  * @obj: pointer to message object state structure
350  *
351  * Return Value: negative value reports error.
352  *      Positive value indicates immediate reception of message.
353  * File: src/usbcan.c
354  */
355 int usbcan_pre_read_config(struct canchip_t *chip, struct msgobj_t *obj)
356 {
357         return 0;
358 }
359
360 #define MAX_TRANSMIT_WAIT_LOOPS 10
361 /**
362  * usbcan_pre_write_config: - prepares message object for message transmission
363  * @chip: pointer to chip state structure
364  * @obj: pointer to message object state structure
365  * @msg: pointer to CAN message
366  *
367  * This function prepares selected message object for future initiation
368  * of message transmission by usbcan_send_msg() function.
369  * The CAN message data and message ID are transfered from @msg slot
370  * into chip buffer in this function.
371  * Return Value: negative value reports error.
372  * File: src/usbcan.c
373  */
374 int usbcan_pre_write_config(struct canchip_t *chip, struct msgobj_t *obj,
375                                                         struct canmsg_t *msg)
376 {
377         struct usbcan_usb *dev=(struct usbcan_usb*)chip->hostdevice->sysdevptr.anydev;
378         int i=0;
379         int len;
380
381         /* Wait until Transmit Buffer Status is released */
382         while ( usbcan_chip_queue_status(chip) &&
383                                                 i++<MAX_TRANSMIT_WAIT_LOOPS) {
384                 udelay(i);
385         }
386         if (usbcan_chip_queue_status(chip)){
387                 CANMSG("Buffer full, cannot send message\n");
388                 return -EIO;
389         }
390
391         dev->tx_msg.chip_id=(__u8)chip->chip_idx;
392
393         len = msg->length;
394         if(len > CAN_MSG_LENGTH) len = CAN_MSG_LENGTH;
395         dev->tx_msg.length=(__u8)len;
396         dev->tx_msg.flags=(__u16)msg->flags;
397
398         if(msg->flags&MSG_EXT) {
399                 dev->tx_msg.id[0]=(msg->id) & 0xff;
400                 dev->tx_msg.id[1]=(msg->id>>8) & 0xff;
401                 dev->tx_msg.id[2]=(msg->id>>16) & 0xff;
402                 dev->tx_msg.id[3]=(msg->id>>24) & 0xff;
403         } else {
404                 dev->tx_msg.id[0]=(msg->id) & 0xff;
405                 dev->tx_msg.id[1]=(msg->id>>8) & 0xff;
406                 dev->tx_msg.id[2]=0;
407                 dev->tx_msg.id[3]=0;
408         }
409         for(i=0; i < len; i++) {
410                 dev->tx_msg.data[i]=(__u8) msg->data[i];
411         }
412         for(i; i < 8; i++) {
413                 dev->tx_msg.data[i]=0;
414         }
415         return 0;
416 }
417
418 /**
419  * usbcan_send_msg: - initiate message transmission
420  * @chip: pointer to chip state structure
421  * @obj: pointer to message object state structure
422  * @msg: pointer to CAN message
423  *
424  * This function is called after usbcan_pre_write_config() function,
425  * which prepares data in chip buffer.
426  * Return Value: negative value reports error.
427  * File: src/usbcan.c
428  */
429 int usbcan_send_msg(struct canchip_t *chip, struct msgobj_t *obj,
430                                                         struct canmsg_t *msg)
431 {
432         struct usbcan_usb *dev=(struct usbcan_usb*)chip->hostdevice->sysdevptr.anydev;
433         int len;
434
435         set_bit(USBCAN_TX_PENDING,&dev->flags);
436         retval=usb_bulk_msg(dev->udev,
437                         usb_sndbulkpipe(dev->udev, dev->bulk_out_endpointAddr),
438                         &dev->tx_msg, sizeof(usbcan_canmsg_t),
439                         &len,10000);
440         clear_bit(USBCAN_TX_PENDING,&dev->flags);
441         if (retval){
442                 CANMSG("URB error %d\n",retval);
443                 return -EIO;
444         }
445         if (len!=sizeof(struct usbcan_canmsg_t)){
446                 CANMSG("CAN message not sent\n");
447                 return -EIO;
448         }
449
450         return 0;
451 }
452
453 /**
454  * usbcan_check_tx_stat: - checks state of transmission engine
455  * @chip: pointer to chip state structure
456  *
457  * Return Value: negative value reports error.
458  *      Positive return value indicates transmission under way status.
459  *      Zero value indicates finishing of all issued transmission requests.
460  * File: src/usbcan.c
461  */
462 int usbcan_check_tx_stat(struct canchip_t *chip)
463 {
464         if (test_bit(USBCAN_TX_PENDING,&((struct usbcan_usb*)chip->hostdevice->sysdevptr.anydev)->flags))
465                 return 1;
466         return 0;
467 }
468
469 /**
470  * usbcan_set_btregs: -  configures bitrate registers
471  * @chip: pointer to chip state structure
472  * @btr0: bitrate register 0
473  * @btr1: bitrate register 1
474  *
475  * Return Value: negative value reports error.
476  * File: src/usbcan.c
477  */
478 int usbcan_set_btregs(struct canchip_t *chip, unsigned short btr0,
479                                                         unsigned short btr1)
480 {
481         int retval;
482         struct usbcan_usb *dev=(struct usbcan_usb*)chip->hostdevice->sysdevptr.anydev;
483
484         retval = usb_control_msg(dev->udev,
485         usb_rcvctrlpipe(dev->udev, dev->ctl_in_endpointAddr),
486         USBCAN_VENDOR_SET_BTREGS,
487         USB_TYPE_VENDOR,
488         btr1<<8 | btr0, chip->chip_idx,
489         dev->ctl_in_buffer, dev->ctl_in_size,
490         10000);
491
492         if (retval==1){
493                 if(dev->ctl_in_buffer[0]==1)
494                         return 0;
495         }
496         return -ENODEV;
497 }
498
499 /**
500  * usbcan_start_chip: -  starts chip message processing
501  * @chip: pointer to chip state structure
502  *
503  * Return Value: negative value reports error.
504  * File: src/usbcan.c
505  */
506 int usbcan_start_chip(struct canchip_t *chip)
507 {
508         int retval;
509         struct usbcan_usb *dev=(struct usbcan_usb*)chip->hostdevice->sysdevptr.anydev;
510
511         retval = usb_control_msg(dev->udev,
512         usb_rcvctrlpipe(dev->udev, dev->ctl_in_endpointAddr),
513         USBCAN_VENDOR_START_CHIP,
514         USB_TYPE_VENDOR,
515         0, chip->chip_idx,
516         dev->ctl_in_buffer, dev->ctl_in_size,
517         10000);
518
519         if (retval==1){
520                 if(dev->ctl_in_buffer[0]==1)
521                         return 0;
522         }
523         return -ENODEV;
524 }
525
526 /**
527  * usbcan_chip_queue_status: -  gets queue status from usb device
528  * @chip: pointer to chip state structure
529  *
530  * Return Value: negative value reports error.
531  * 0 means queue is not full
532  * 1 means queue is full
533  * File: src/usbcan.c
534  */
535 int usbcan_chip_queue_status(struct canchip_t *chip)
536 {
537         int retval;
538         struct usbcan_usb *dev=(struct usbcan_usb*)chip->hostdevice->sysdevptr.anydev;
539
540         retval = usb_control_msg(dev->udev,
541         usb_rcvctrlpipe(dev->udev, dev->ctl_in_endpointAddr),
542         USBCAN_VENDOR_CHECK_TX_STAT,
543         USB_TYPE_VENDOR,
544         0, chip->chip_idx,
545         dev->ctl_in_buffer, dev->ctl_in_size,
546         10000);
547
548         if (retval==1){
549                 if(dev->ctl_in_buffer[0]==1)
550                         return 1;
551                 if(dev->ctl_in_buffer[0]==0)
552                         return 0;
553         }
554         return -ENODEV;
555 }
556
557 /**
558  * usbcan_stop_chip: -  stops chip message processing
559  * @chip: pointer to chip state structure
560  *
561  * Return Value: negative value reports error.
562  * File: src/usbcan.c
563  */
564 int usbcan_stop_chip(struct canchip_t *chip)
565 {
566         int retval;
567         struct usbcan_usb *dev=(struct usbcan_usb*)chip->hostdevice->sysdevptr.anydev;
568
569         retval = usb_control_msg(dev->udev,
570         usb_rcvctrlpipe(dev->udev, dev->ctl_in_endpointAddr),
571         USBCAN_VENDOR_STOP_CHIP,
572         USB_TYPE_VENDOR,
573         0, chip->chip_idx,
574         dev->ctl_in_buffer, dev->ctl_in_size,
575         10000);
576
577         if (retval==1){
578                 if(dev->ctl_in_buffer[0]==1)
579                         return 0;
580         }
581         return -ENODEV;
582 }
583
584 /**
585  * usbcan_attach_to_chip: - attaches to the chip, setups registers and state
586  * @chip: pointer to chip state structure
587  *
588  * Return Value: negative value reports error.
589  * File: src/usbcan.c
590  */
591 int usbcan_attach_to_chip(struct canchip_t *chip)
592 {
593         return 0;
594 }
595
596 /**
597  * usbcan_release_chip: - called before chip structure removal if %CHIP_ATTACHED is set
598  * @chip: pointer to chip state structure
599  *
600  * Return Value: negative value reports error.
601  * File: src/usbcan.c
602  */
603 int usbcan_release_chip(struct canchip_t *chip)
604 {
605         usbcan_stop_chip(chip);
606         return 0;
607 }
608
609 /**
610  * usbcan_remote_request: - configures message object and asks for RTR message
611  * @chip: pointer to chip state structure
612  * @obj: pointer to message object structure
613  *
614  * Return Value: negative value reports error.
615  * File: src/usbcan.c
616  */
617 int usbcan_remote_request(struct canchip_t *chip, struct msgobj_t *obj)
618 {
619         CANMSG("usbcan_remote_request not implemented\n");
620         return -ENOSYS;
621 }
622
623 /**
624  * usbcan_standard_mask: - setup of mask for message filtering
625  * @chip: pointer to chip state structure
626  * @code: can message acceptance code
627  * @mask: can message acceptance mask
628  *
629  * Return Value: negative value reports error.
630  * File: src/usbcan.c
631  */
632 int usbcan_standard_mask(struct canchip_t *chip, unsigned short code,
633                 unsigned short mask)
634 {
635         CANMSG("usbcan_standard_mask not implemented\n");
636         return -ENOSYS;
637 }
638
639 /**
640  * usbcan_clear_objects: - clears state of all message object residing in chip
641  * @chip: pointer to chip state structure
642  *
643  * Return Value: negative value reports error.
644  * File: src/usbcan.c
645  */
646 int usbcan_clear_objects(struct canchip_t *chip)
647 {
648         CANMSG("usbcan_clear_objects not implemented\n");
649         return -ENOSYS;
650 }
651
652 /**
653  * usbcan_config_irqs: - tunes chip hardware interrupt delivery
654  * @chip: pointer to chip state structure
655  * @irqs: requested chip IRQ configuration
656  *
657  * Return Value: negative value reports error.
658  * File: src/usbcan.c
659  */
660 int usbcan_config_irqs(struct canchip_t *chip, short irqs)
661 {
662         CANMSG("usbcan_config_irqs not implemented\n");
663         return -ENOSYS;
664 }
665
666 /**
667  * usbcan_irq_write_handler: - part of ISR code responsible for transmit events
668  * @chip: pointer to chip state structure
669  * @obj: pointer to attached queue description
670  *
671  * The main purpose of this function is to read message from attached queues
672  * and transfer message contents into CAN controller chip.
673  * This subroutine is called by
674  * usbcan_irq_write_handler() for transmit events.
675  * File: src/usbcan.c
676  */
677 void usbcan_irq_write_handler(struct canchip_t *chip, struct msgobj_t *obj)
678 {
679         int cmd;
680
681         if(obj->tx_slot){
682                 // Do local transmitted message distribution if enabled
683                 if (processlocal){
684                         // fill CAN message timestamp
685                         can_filltimestamp(&obj->tx_slot->msg.timestamp);
686
687                         obj->tx_slot->msg.flags |= MSG_LOCAL;
688                         canque_filter_msg2edges(obj->qends, &obj->tx_slot->msg);
689                 }
690                 // Free transmitted slot
691                 canque_free_outslot(obj->qends, obj->tx_qedge, obj->tx_slot);
692                 obj->tx_slot=NULL;
693         }
694
695         can_msgobj_clear_fl(obj,TX_PENDING);
696         cmd=canque_test_outslot(obj->qends, &obj->tx_qedge, &obj->tx_slot);
697         if(cmd<0)
698                 return;
699         can_msgobj_set_fl(obj,TX_PENDING);
700
701         if (chip->chipspecops->pre_write_config(chip, obj, &obj->tx_slot->msg)) {
702                 obj->ret = -1;
703                 canque_notify_inends(obj->tx_qedge, CANQUEUE_NOTIFY_ERRTX_PREP);
704                 canque_free_outslot(obj->qends, obj->tx_qedge, obj->tx_slot);
705                 obj->tx_slot=NULL;
706                 return;
707         }
708         if (chip->chipspecops->send_msg(chip, obj, &obj->tx_slot->msg)) {
709                 obj->ret = -1;
710                 canque_notify_inends(obj->tx_qedge, CANQUEUE_NOTIFY_ERRTX_SEND);
711                 canque_free_outslot(obj->qends, obj->tx_qedge, obj->tx_slot);
712                 obj->tx_slot=NULL;
713                 return;
714         }
715 }
716
717 #define MAX_RETR 10
718
719 /**
720  * usbcan_irq_handler: - interrupt service routine
721  * @irq: interrupt vector number, this value is system specific
722  * @chip: pointer to chip state structure
723  *
724  * Interrupt handler is activated when state of CAN controller chip changes,
725  * there is message to be read or there is more space for new messages or
726  * error occurs. The receive events results in reading of the message from
727  * CAN controller chip and distribution of message through attached
728  * message queues.
729  * File: src/usbcan.c
730  */
731 int usbcan_irq_handler(int irq, struct canchip_t *chip)
732 {
733 /*      int irq_register, status, error_code;
734         struct msgobj_t *obj=chip->msgobj[0];
735         int loop_cnt=CHIP_MAX_IRQLOOP;
736
737         irq_register=can_read_reg(chip,SJAIR);
738 //      DEBUGMSG("sja1000_irq_handler: SJAIR:%02x\n",irq_register);
739 //      DEBUGMSG("sja1000_irq_handler: SJASR:%02x\n",
740 //                                      can_read_reg(chip,SJASR));
741
742         if ((irq_register & (sjaIR_BEI|sjaIR_EPI|sjaIR_DOI|sjaIR_EI|sjaIR_TI|sjaIR_RI)) == 0)
743                 return CANCHIP_IRQ_NONE;
744
745         if(!(chip->flags&CHIP_CONFIGURED)) {
746                 CANMSG("usbcan_irq_handler: called for non-configured device, irq_register 0x%02x\n", irq_register);
747                 return CANCHIP_IRQ_NONE;
748         }
749
750         status=can_read_reg(chip,SJASR);
751
752         do {
753
754                 if(!loop_cnt--) {
755                         CANMSG("usbcan_irq_handler IRQ %d stuck\n",irq);
756                         return CANCHIP_IRQ_STUCK;
757                 }
758
759                 // (irq_register & sjaIR_TI)
760                 //      old variant using SJAIR, collides with intended use with irq_accept
761                 if (((status & sjaSR_TBS) && can_msgobj_test_fl(obj,TX_PENDING))||
762                     (can_msgobj_test_fl(obj,TX_REQUEST))) {
763                         DEBUGMSG("sja1000_irq_handler: TI or TX_PENDING and TBS\n");
764                         obj->ret = 0;
765                         can_msgobj_set_fl(obj,TX_REQUEST);
766                         while(!can_msgobj_test_and_set_fl(obj,TX_LOCK)){
767                                 can_msgobj_clear_fl(obj,TX_REQUEST);
768
769                                 if (can_read_reg(chip, SJASR) & sjaSR_TBS)
770                                         usbcan_irq_write_handler(chip, obj);
771
772                                 can_msgobj_clear_fl(obj,TX_LOCK);
773                                 if(!can_msgobj_test_fl(obj,TX_REQUEST)) break;
774                                 DEBUGMSG("TX looping in sja1000_irq_handler\n");
775                         }
776                 }
777                 if ((irq_register & (sjaIR_EI|sjaIR_BEI|sjaIR_EPI|sjaIR_DOI)) != 0) {
778                         // Some error happened
779                         error_code=can_read_reg(chip,SJAECC);
780                         sja1000_report_error(chip, status, irq_register, error_code);
781 // FIXME: chip should be brought to usable state. Transmission cancelled if in progress.
782 // Reset flag set to 0 if chip is already off the bus. Full state report
783                         obj->ret=-1;
784
785                         if(error_code == 0xd9) {
786                                 obj->ret= -ENXIO;
787                                 // no such device or address - no ACK received
788                         }
789                         if(obj->tx_retry_cnt++>MAX_RETR) {
790                                 can_write_reg(chip, sjaCMR_AT, SJACMR); // cancel any transmition
791                                 obj->tx_retry_cnt = 0;
792                         }
793                         if(status&sjaSR_BS) {
794                                 CANMSG("bus-off, resetting usbcan\n");
795                                 can_write_reg(chip, 0, SJAMOD);
796                         }
797
798                         if(obj->tx_slot){
799                                 canque_notify_inends(obj->tx_qedge, CANQUEUE_NOTIFY_ERRTX_BUS);
800                                 //canque_free_outslot(obj->qends, obj->tx_qedge, obj->tx_slot);
801                                 //obj->tx_slot=NULL;
802                         }
803
804                 } else {
805                         if(sja1000_report_error_limit_counter)
806                                 sja1000_report_error_limit_counter--;
807                         obj->tx_retry_cnt=0;
808                 }
809
810                 irq_register=can_read_reg(chip,SJAIR);
811
812                 status=can_read_reg(chip,SJASR);
813
814                 if(((status & sjaSR_TBS) && can_msgobj_test_fl(obj,TX_PENDING)) ||
815                    (irq_register & sjaIR_TI))
816                          can_msgobj_set_fl(obj,TX_REQUEST);
817
818         } while((irq_register & (sjaIR_BEI|sjaIR_EPI|sjaIR_DOI|sjaIR_EI|sjaIR_RI)) ||
819                 (can_msgobj_test_fl(obj,TX_REQUEST) && !can_msgobj_test_fl(obj,TX_LOCK)) ||
820                 (status & sjaSR_RBS));
821 */
822         return CANCHIP_IRQ_HANDLED;
823 }
824
825 /**
826  * usbcan_wakeup_tx: - wakeups TX processing
827  * @chip: pointer to chip state structure
828  * @obj: pointer to message object structure
829  *
830  * Function is responsible for initiating message transmition.
831  * It is responsible for clearing of object TX_REQUEST flag
832  *
833  * Return Value: negative value reports error.
834  * File: src/usbcan.c
835  */
836 int usbcan_wakeup_tx(struct canchip_t *chip, struct msgobj_t *obj)
837 {
838
839         can_preempt_disable();
840
841         can_msgobj_set_fl(obj,TX_PENDING);
842         can_msgobj_set_fl(obj,TX_REQUEST);
843         while(!can_msgobj_test_and_set_fl(obj,TX_LOCK)){
844                 can_msgobj_clear_fl(obj,TX_REQUEST);
845
846                 if (!usbcan_chip_queue_status(chip)){
847                         obj->tx_retry_cnt=0;
848                         usbcan_irq_write_handler(chip, obj);
849                 }
850
851                 can_msgobj_clear_fl(obj,TX_LOCK);
852                 if(!can_msgobj_test_fl(obj,TX_REQUEST)) break;
853                 DEBUGMSG("TX looping in usbcan_wakeup_tx\n");
854         }
855
856         can_preempt_enable();
857         return 0;
858 }
859
860 int usbcan_chipregister(struct chipspecops_t *chipspecops)
861 {
862         CANMSG("initializing usbcan chip operations\n");
863         chipspecops->chip_config=usbcan_chip_config;
864         chipspecops->baud_rate=usbcan_baud_rate;
865         chipspecops->standard_mask=usbcan_standard_mask;
866         chipspecops->extended_mask=usbcan_extended_mask;
867         chipspecops->message15_mask=usbcan_extended_mask;
868         chipspecops->clear_objects=usbcan_clear_objects;
869         chipspecops->config_irqs=usbcan_config_irqs;
870         chipspecops->pre_read_config=usbcan_pre_read_config;
871         chipspecops->pre_write_config=usbcan_pre_write_config;
872         chipspecops->send_msg=usbcan_send_msg;
873         chipspecops->check_tx_stat=usbcan_check_tx_stat;
874         chipspecops->wakeup_tx=usbcan_wakeup_tx;
875         chipspecops->remote_request=usbcan_remote_request;
876         chipspecops->enable_configuration=usbcan_enable_configuration;
877         chipspecops->disable_configuration=usbcan_disable_configuration;
878         chipspecops->attach_to_chip=usbcan_attach_to_chip;
879         chipspecops->release_chip=usbcan_release_chip;
880         chipspecops->set_btregs=usbcan_set_btregs;
881         chipspecops->start_chip=usbcan_start_chip;
882         chipspecops->stop_chip=usbcan_stop_chip;
883         chipspecops->irq_handler=usbcan_irq_handler;
884         chipspecops->irq_accept=NULL;
885         return 0;
886 }
887
888 /**
889  * usbcan_fill_chipspecops - fills chip specific operations
890  * @chip: pointer to chip representation structure
891  *
892  * The function fills chip specific operations for sja1000 (PeliCAN) chip.
893  *
894  * Return Value: returns negative number in the case of fail
895  */
896 int usbcan_fill_chipspecops(struct canchip_t *chip)
897 {
898         chip->chip_type="usbcan";
899         chip->max_objects=1;
900         usbcan_chipregister(chip->chipspecops);
901         return 0;
902 }
903
904 /**
905  * usbcan_init_chip_data - Initialize chips
906  * @candev: Pointer to candevice/board structure
907  * @chipnr: Number of the CAN chip on the hardware card
908  *
909  * The function usbcan_init_chip_data() is used to initialize the hardware
910  * structure containing information about the CAN chips.
911  * %CHIP_TYPE represents the type of CAN chip. %CHIP_TYPE can be "i82527" or
912  * "sja1000".
913  * The @chip_base_addr entry represents the start of the 'official' memory map
914  * of the installed chip. It's likely that this is the same as the @io_addr
915  * argument supplied at module loading time.
916  * The @clock entry holds the chip clock value in Hz.
917  * The entry @sja_cdr_reg holds hardware specific options for the Clock Divider
918  * register. Options defined in the %sja1000.h file:
919  * %sjaCDR_CLKOUT_MASK, %sjaCDR_CLK_OFF, %sjaCDR_RXINPEN, %sjaCDR_CBP, %sjaCDR_PELICAN
920  * The entry @sja_ocr_reg holds hardware specific options for the Output Control
921  * register. Options defined in the %sja1000.h file:
922  * %sjaOCR_MODE_BIPHASE, %sjaOCR_MODE_TEST, %sjaOCR_MODE_NORMAL, %sjaOCR_MODE_CLOCK,
923  * %sjaOCR_TX0_LH, %sjaOCR_TX1_ZZ.
924  * The entry @int_clk_reg holds hardware specific options for the Clock Out
925  * register. Options defined in the %i82527.h file:
926  * %iCLK_CD0, %iCLK_CD1, %iCLK_CD2, %iCLK_CD3, %iCLK_SL0, %iCLK_SL1.
927  * The entry @int_bus_reg holds hardware specific options for the Bus
928  * Configuration register. Options defined in the %i82527.h file:
929  * %iBUS_DR0, %iBUS_DR1, %iBUS_DT1, %iBUS_POL, %iBUS_CBY.
930  * The entry @int_cpu_reg holds hardware specific options for the cpu interface
931  * register. Options defined in the %i82527.h file:
932  * %iCPU_CEN, %iCPU_MUX, %iCPU_SLP, %iCPU_PWD, %iCPU_DMC, %iCPU_DSC, %iCPU_RST.
933  * Return Value: The function always returns zero
934  * File: src/usbcan.c
935  */
936 int usbcan_init_chip_data(struct candevice_t *candev, int chipnr)
937 {
938         struct canchip_t *chip=candev->chip[chipnr];
939
940         usbcan_fill_chipspecops(chip);
941
942         candev->chip[chipnr]->flags|=CHIP_IRQ_CUSTOM;
943         candev->chip[chipnr]->chip_base_addr=0;
944         candev->chip[chipnr]->clock = 0;
945
946         return 0;
947 }
948
949
950
951 /* --------------------------------------------------------------------------------------------------- */
952
953 static void usbcan_rcv(struct urb *urb)
954 {
955         struct usbcan_usb *dev = urb->context;
956         int retval;
957
958         switch (urb->status) {
959         case 0:
960                 /* success */
961                 set_bit(USBCAN_DATA_READ,&dev->flags);
962                 wake_up(&dev->rcvthread.queue);
963                 return;
964         case -ECONNRESET:
965         case -ENOENT:
966         case -ESHUTDOWN:
967                 /* this urb is terminated, clean up */
968                 CANMSG("%s - urb shutting down with status: %d\n", __FUNCTION__, urb->status);
969                 set_bit(USBCAN_TERMINATE,&dev->flags);
970                 wake_up(&dev->rcvthread.queue);
971                 return;
972         default:
973                 CANMSG("%s - nonzero urb status received: %d\n", __FUNCTION__, urb->status);
974                 break;
975         }
976
977         retval = usb_submit_urb (urb, GFP_ATOMIC);
978         if (retval<0){
979                 CANMSG("%s - usb_submit_urb failed with result %d\n",
980                      __FUNCTION__, retval);
981                 set_bit(USBCAN_ERROR,&dev->flags);
982                 wake_up(&dev->rcvthread.queue);
983         }
984 }
985
986 void usbcan_read_kthread(kthread_t *kthread)
987 {
988         int retval;
989         struct usbcan_usb *dev=(struct usbcan_usb *)kthread->arg;
990         struct msgobj_t *obj;
991
992   /* setup the thread environment */
993   init_kthread(kthread, "usbcan");
994
995   /* this is normal work to do */
996   CANMSG ("usbcan thread started!\n");
997
998         dev->rcv = usb_alloc_urb(0, GFP_KERNEL);
999         if (!dev->rcv){
1000                 CANMSG("Error allocating usb urb\n");
1001                 goto error;
1002         }
1003         dev->rcv->dev = dev->udev;
1004         usb_fill_bulk_urb(dev->rcv, dev->udev,
1005                          usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr),
1006                          &dev->rcv_msg, sizeof(usbcan_canmsg_t),
1007                          usbcan_rcv, dev);
1008
1009   /* an endless loop in which we are doing our work */
1010   for(;;)
1011   {
1012                 retval=usb_submit_urb(dev->rcv, GFP_KERNEL);
1013                 if (retval){
1014                         CANMSG("URB error %d\n",retval);
1015                         break;
1016                 }
1017                 /* fall asleep */
1018                 wait_event_interruptible(kthread->queue,
1019                         test_bit(USBCAN_CHIP_DATA_READ,&chip_data->flags)
1020                         || test_bit(USBCAN_CHIP_TERMINATE,&chip_data->flags)
1021                         || test_bit(USBCAN_CHIP_ERROR,&chip_data->flags)
1022                 );
1023
1024                 /* We need to do a memory barrier here to be sure that
1025                 the flags are visible on all CPUs. */
1026                 mb();
1027
1028                 /* here we are back from sleep because we caught a signal. */
1029                 if (kthread->terminate)
1030                 {
1031                         /* we received a request to terminate ourself */
1032                         break;
1033                 }
1034
1035                 if (test_bit(USBCAN_CHIP_ERROR,&chip_data->flags)){
1036                         CANMSG("URB error %d\n",retval);
1037                         break;
1038                 }
1039
1040                 { /* Normal work to do */
1041                         if (test_bit(USBCAN_CHIP_DATA_READ,&chip_data->flags)){
1042                                 int i, len;
1043                                 clear_bit(USBCAN_CHIP_DATA_READ,&chip_data->flags);
1044
1045                                 if ((dev->candev->chip[dev->rcv_msg.chip_id])&&
1046                                         (dev->candev->chip[dev->rcv_msg.chip_id].flags & CHIP_CONFIGURED)){
1047
1048                                         obj=dev->candev->chip[dev->rcv_msg.chip_id]->msgobj[0];
1049                                         if (dev->rcv_msg.flags & MSG_EXT) {
1050                                                 obj->rx_msg.id =
1051                                                         (dev->rcv_msg.id[0]) +
1052                                                         (dev->rcv_msg.id[1]<<8) +
1053                                                         (dev->rcv_msg.id[2]<<16) +
1054                                                         (dev->rcv_msg.id[3]<<24);
1055                                         } else {
1056                                                 obj->rx_msg.id =
1057                                                         (dev->rcv_msg.id[0]) +
1058                                                         (dev->rcv_msg.id[1]<<8);
1059                                         }
1060                                         obj->rx_msg.flags = dev->rcv_msg.flags;
1061                                         len=dev->rcv_msg.length;
1062                                         if(len > CAN_MSG_LENGTH) len = CAN_MSG_LENGTH;
1063                                         obj->rx_msg.length = len;
1064                                         for(i=0; i< len; i++) {
1065                                                 obj->rx_msg.data[i]=obj->rx_msg.data[i];
1066                                         }
1067
1068                                         // fill CAN message timestamp
1069                                         can_filltimestamp(&obj->rx_msg.timestamp);
1070                                         canque_filter_msg2edges(obj->qends, &obj->rx_msg);
1071                                 }
1072                         }
1073     }
1074   }
1075   /* here we go only in case of termination of the thread */
1076 error:
1077   /* cleanup the thread, leave */
1078   CANMSG ("kernel thread terminated!\n");
1079   exit_kthread(kthread);
1080
1081   /* returning from the thread here calls the exit functions */
1082 }
1083
1084 static int usbcan_probe(struct usb_interface *interface, const struct usb_device_id *id)
1085 {
1086         struct usbcan_usb *dev;
1087         struct usb_host_interface *iface_desc;
1088         struct usb_endpoint_descriptor *endpoint;
1089         size_t buffer_size;
1090         int i;
1091         int retval = -ENOMEM;
1092
1093         /* allocate memory for our device state and initialize it */
1094         dev = (struct usbcan_usb *) can_checked_malloc(sizeof(struct usbcan_usb));
1095         if (!dev) {
1096                 err("Out of memory");
1097                 goto error;
1098         }
1099
1100         sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
1101         spin_lock_init(&dev->err_lock);
1102         init_usb_anchor(&dev->submitted);
1103
1104 //      dev->udev = usb_get_dev(interface_to_usbdev(interface));
1105         dev->udev = interface_to_usbdev(interface);
1106         dev->interface = interface;
1107
1108         /* set up the endpoint information */
1109         /* use only the first bulk-in and bulk-out endpoints */
1110         iface_desc = interface->cur_altsetting;
1111         for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1112                 endpoint = &iface_desc->endpoint[i].desc;
1113
1114                 if (!dev->bulk_in_endpointAddr &&
1115                     usb_endpoint_is_bulk_in(endpoint)) {
1116                         /* we found a bulk in endpoint */
1117                         buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
1118                         dev->bulk_in_size = buffer_size;
1119                         dev->bulk_in_endpointAddr = endpoint->bEndpointAddress;
1120                         dev->bulk_in_buffer = can_checked_malloc(buffer_size);
1121                         if (!dev->bulk_in_buffer) {
1122                                 err("Could not allocate bulk_in_buffer");
1123                                 goto error;
1124                         }
1125                 }
1126
1127                 if (!dev->bulk_out_endpointAddr &&
1128                     usb_endpoint_is_bulk_out(endpoint)) {
1129                         /* we found a bulk out endpoint */
1130                                 dev->bulk_out_endpointAddr = endpoint->bEndpointAddress;
1131                 }
1132
1133                 if (!dev->ctl_in_endpointAddr &&
1134                     usb_endpoint_xfer_control(endpoint) &&
1135                     usb_endpoint_dir_in(endpoint)) {
1136                         /* we found a bulk in endpoint */
1137                         buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
1138                         dev->ctl_in_size = buffer_size;
1139                         dev->ctl_in_endpointAddr = endpoint->bEndpointAddress;
1140                         dev->ctl_in_buffer = can_checked_malloc(buffer_size);
1141                         if (!dev->ctl_in_buffer) {
1142                                 err("Could not allocate bulk_in_buffer");
1143                                 goto error;
1144                         }
1145                 }
1146
1147                 if (!dev->ctl_out_endpointAddr &&
1148                     usb_endpoint_xfer_control(endpoint) &&
1149                     usb_endpoint_dir_out(endpoint)) {
1150                         /* we found a bulk out endpoint */
1151                                 dev->ctl_out_endpointAddr = endpoint->bEndpointAddress;
1152                 }
1153         }
1154         if (!(dev->bulk_in_endpointAddr && dev->bulk_out_endpointAddr)) {
1155                 err("Could not find all bulk-in and bulk-out endpoints");
1156                 goto error;
1157         }
1158
1159         /* save our data pointer in this interface device */
1160         usb_set_intfdata(interface, dev);
1161
1162         register_usbdev("usbcan",(void *) dev);
1163
1164         /* let the user know what node this device is now attached to */
1165         info("USB Skeleton device now attached");
1166         return 0;
1167
1168 error:
1169         usb_put_dev(dev->udev);
1170         if (dev->bulk_in_buffer)
1171                 can_checked_free(dev->bulk_in_buffer);
1172         if (dev->ctl_in_buffer)
1173                 can_checked_free(dev->ctl_in_buffer);
1174         if (dev->candev){
1175                 dev->candev->sysdevptr.anydev=NULL;
1176                 cleanup_usbdev(dev->candev);
1177         }
1178         can_checked_free(dev);
1179         return retval;
1180 }
1181
1182 // Physically disconnected device
1183 static void usbcan_disconnect(struct usb_interface *interface)
1184 {
1185         struct usbcan_usb *dev;
1186         int minor = interface->minor;
1187
1188         dev = usb_get_intfdata(interface);
1189         usb_set_intfdata(interface, NULL);
1190
1191         /* prevent more I/O from starting */
1192         mutex_lock(&dev->io_mutex);
1193         dev->interface = NULL;
1194         mutex_unlock(&dev->io_mutex);
1195
1196         //usb_kill_anchored_urbs(&dev->submitted);
1197
1198         usb_put_dev(dev->udev);
1199         if (dev->bulk_in_buffer)
1200                 can_checked_free(dev->bulk_in_buffer);
1201         if (dev->ctl_in_buffer)
1202                 can_checked_free(dev->ctl_in_buffer);
1203         if (dev->candev){
1204                 dev->candev->sysdevptr.anydev=NULL;
1205                 cleanup_usbdev(dev->candev);
1206         }
1207         can_checked_free(dev);
1208
1209         info("USB Skeleton now disconnected");
1210 }
1211
1212 int usbcan_init(void){
1213         return usb_register(&usbcan_driver);
1214 }
1215
1216 void usbcan_exit(void){
1217         usb_deregister(&usbcan_driver);
1218 }