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