]> rtime.felk.cvut.cz Git - lincan.git/blob - lincan/src/main.c
Embedded code and LinCAN driver now working
[lincan.git] / lincan / src / main.c
1 /* main.c
2  * Linux CAN-bus device driver.
3  * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4  * Rewritten for new CAN queues by Pavel Pisa - OCERA team member
5  * email:pisa@cmp.felk.cvut.cz
6  * This software is released under the GPL-License.
7  * Version lincan-0.3  17 Jun 2004
8  */
9
10 #ifndef EXPORT_SYMTAB
11 #define EXPORT_SYMTAB
12 #endif
13
14 #include <linux/autoconf.h>
15
16 #include <linux/module.h>
17
18 #include <linux/kernel.h>
19 #include <linux/fs.h>
20 #include <linux/sched.h>
21 #include <linux/poll.h>
22 #include <linux/version.h>
23 #include <linux/autoconf.h>
24 #include <linux/interrupt.h>
25
26 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
27  #include <linux/wrapper.h>
28 #else
29  #include <linux/device.h>
30  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
31   static struct class *can_class;
32  #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
33   static struct class_simple *can_class;
34   #define class_create class_simple_create
35   #define class_device_create class_simple_device_add
36   #define class_device_destroy(a,b) class_simple_device_remove(b)
37   #define class_destroy class_simple_destroy
38  #endif
39 #endif
40
41 #if !defined (__GENKSYMS__)
42 #if (defined (MODVERSIONS) && !defined(NOVER))
43 #include <linux/modversions.h>
44 /*#include "../include/main.ver"*/
45 #endif
46 #endif
47
48 /*#undef CONFIG_DEVFS_FS*/
49
50 #ifdef CONFIG_DEVFS_FS
51 #include <linux/devfs_fs_kernel.h>
52 #include <linux/miscdevice.h>
53 #endif
54
55 #include "../include/can.h"
56 #include "../include/can_sysdep.h"
57 #include "../include/main.h"
58 #include "../include/modparms.h"
59 #include "../include/devcommon.h"
60 #include "../include/setup.h"
61 #include "../include/proc.h"
62 #include "../include/open.h"
63 #include "../include/close.h"
64 #include "../include/read.h"
65 #include "../include/select.h"
66 #include "../include/irq.h"
67 #include "../include/ioctl.h"
68 #include "../include/write.h"
69 #include "../include/finish.h"
70 #include "../include/fasync.h"
71
72 #ifdef CAN_WITH_RTL
73 #include <rtl_posixio.h>
74 #include "../include/can_iortl.h"
75 #endif /*CAN_WITH_RTL*/
76
77 #if defined(CONFIG_OC_LINCAN_CARD_usbcan)
78         #include "../include/usbcan.h"
79 #endif
80
81 can_spinlock_t canuser_manipulation_lock;
82
83 int major=CAN_MAJOR;
84 int minor[MAX_TOT_CHIPS]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
85 int extended=0;
86 int pelican=0;
87 int baudrate[MAX_TOT_CHIPS];
88 char *hw[MAX_HW_CARDS]={NULL,};
89 int irq[MAX_IRQ]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
90 unsigned long io[MAX_HW_CARDS]={-1,-1,-1,-1,-1,-1,-1,-1};
91 int stdmask=0;
92 int extmask=0;
93 int mo15mask=0;
94 int processlocal=0;
95
96 unsigned int minor_specified;
97 unsigned int baudrate_specified;
98 unsigned int hw_specified;
99 unsigned int irq_specified;
100 unsigned int io_specified;
101
102 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
103 /* Module parameters, some must be supplied at module loading time */
104 MODULE_PARM(major,"1i");
105 /*MODULE_PARM(minor, "1-" __MODULE_STRING(MAX_TOT_CHIPS)"i");*/
106 MODULE_PARM(minor, "1-" __MODULE_STRING(MAX_TOT_CHIPS_STR)"i");
107 MODULE_PARM(extended,"1i");
108 MODULE_PARM(pelican,"1i");
109 MODULE_PARM(baudrate, "1-" __MODULE_STRING(MAX_TOT_CHIPS_STR)"i");
110 MODULE_PARM(hw, "1-" __MODULE_STRING(MAX_HW_CARDS)"s");
111 MODULE_PARM(irq, "1-" __MODULE_STRING(MAX_IRQ)"i");
112 MODULE_PARM(io, "1-" __MODULE_STRING(MAX_HW_CARDS)"i");
113 MODULE_PARM(stdmask, "1i");
114 MODULE_PARM(extmask, "1i");
115 MODULE_PARM(mo15mask, "1i");
116 MODULE_PARM(processlocal, "1i");
117
118 #else /* LINUX_VERSION_CODE >= 2,6,0 */
119 module_param(major, int, 0);
120 module_param_array(minor, int, &minor_specified, 0);
121 module_param(extended, int, 0);
122 module_param(pelican, int, 0);
123 module_param_array(baudrate, int, &baudrate_specified, 0);
124 module_param_array(hw, charp, &hw_specified, 0);
125 module_param_array(irq, int, &irq_specified, 0);
126 module_param_array(io, int, &io_specified, 0);
127 module_param(stdmask, int, 0);
128 module_param(extmask, int, 0);
129 module_param(mo15mask, int, 0);
130 module_param(processlocal, int, 0);
131 #endif /* LINUX_VERSION_CODE >= 2,6,0 */
132
133 MODULE_PARM_DESC(major,"can be used to change default major [" __MODULE_STRING(CAN_MAJOR) "]");
134 MODULE_PARM_DESC(minor,"can be used to change default starting minor for each channel");
135 MODULE_PARM_DESC(extended,"enables automatic switching to extended format if ID>2047,"
136                         " selects extended frames reception for i82527");
137 MODULE_PARM_DESC(pelican,"unused parameter, PeliCAN used by default for sja1000p chips");
138 MODULE_PARM_DESC(baudrate,"baudrate for each channel in step of 1kHz");
139 MODULE_PARM_DESC(hw,"list of boards types to initialize - virtual,pip5,...");
140 MODULE_PARM_DESC(irq,"list of iterrupt signal numbers, most ISA has one per chip, no value for PCI or virtual");
141 MODULE_PARM_DESC(io,"IO address for each board, use 0 for PCI or virtual");
142 MODULE_PARM_DESC(stdmask,"default standard mask for i82527 chips");
143 MODULE_PARM_DESC(extmask,"default extended mask for i82527 chips");
144 MODULE_PARM_DESC(mo15mask,"mask for communication object 15 of i82527 chips");
145 MODULE_PARM_DESC(processlocal,"select postprocessing/loopback of transmitted messages - "
146                 "0 .. disabled, 1 .. can be enabled by FIFO filter, 2 .. enabled by default");
147
148 #ifdef CAN_WITH_RTL
149 int can_rtl_priority=-1;
150 MODULE_PARM(can_rtl_priority, "1i");
151 MODULE_PARM_DESC(can_rtl_priority,"select priority of chip worker thread");
152 #endif /*CAN_WITH_RTL*/
153
154 /* Other module attributes */
155 #ifdef MODULE_SUPPORTED_DEVICE
156 MODULE_SUPPORTED_DEVICE("can");
157 #endif
158 #ifdef MODULE_LICENSE
159 MODULE_LICENSE("GPL");
160 #endif
161 #ifdef MODULE_DESCRIPTION
162 MODULE_DESCRIPTION("Universal Linux CAN-bus device driver");
163 #endif
164 #ifdef MODULE_AUTHOR
165 MODULE_AUTHOR("Pavel Pisa <pisa@cmp.felk.cvut.cz>, Arnaud Westenberg");
166 #endif
167
168 /* Global structures, used to describe the installed hardware. */
169 struct canhardware_t canhardware;
170 struct canhardware_t *hardware_p=&canhardware;
171 struct canchip_t *chips_p[MAX_TOT_CHIPS];
172 struct msgobj_t *objects_p[MAX_TOT_MSGOBJS];
173 #ifdef CONFIG_DEVFS_FS
174 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
175 devfs_handle_t  devfs_handles[MAX_TOT_MSGOBJS];
176 #endif
177 #endif
178
179 /* Pointers to dynamically allocated memory are maintained in a linked list
180  * to ease memory deallocation.
181  */
182 struct mem_addr *mem_head=NULL;
183
184 struct file_operations can_fops=
185 {
186  #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0))
187         owner:          THIS_MODULE,
188  #endif
189         read:           can_read,
190         write:          can_write,
191         poll:           can_poll,
192         ioctl:          can_ioctl,
193         open:           can_open,
194         release:        can_close,
195   #ifdef CAN_ENABLE_KERN_FASYNC
196         fasync:         can_fasync
197   #endif /*CAN_ENABLE_KERN_FASYNC*/
198 };
199
200 EXPORT_SYMBOL(can_fops);
201
202
203 #ifdef CAN_WITH_RTL
204 struct rtl_file_operations can_fops_rtl = {
205         llseek:         NULL,
206         read:           can_read_rtl_posix,
207         write:          can_write_rtl_posix,
208         ioctl:          can_ioctl_rtl_posix,
209         mmap:           NULL,
210         open:           can_open_rtl_posix,
211         release:        can_release_rtl_posix
212 };
213 #endif /*CAN_WITH_RTL*/
214
215
216 /*
217  2.6 kernel attributes for sysfs
218
219 static ssize_t show_xxx(struct class_device *cdev, char *buf)
220 {
221         return sprintf(buf, "xxxx\n");
222 }
223
224 static ssize_t store_xxx(struct class_device *cdev, const char * buf, size_t count)
225 {
226 }
227
228 static CLASS_DEVICE_ATTR(xxx, S_IRUGO, show_xxx, store_xxx/NULL);
229
230 ret = class_device_create_file(class_dev, class_device_attr_xxx);
231 if (ret)
232         goto err_unregister;
233
234 */
235
236 int init_module(void)
237 {
238         int res=0,i=0, j;
239         struct candevice_t *candev;
240         struct canchip_t *chip;
241
242         if (parse_mod_parms())
243                 return -EINVAL;
244
245         can_spin_lock_init(&canuser_manipulation_lock);
246         canqueue_kern_initialize();
247
248         if (init_hw_struct())
249                 return -ENODEV;
250
251         #ifdef CAN_DEBUG
252                 list_hw();
253         #endif
254
255         res=register_chrdev(major,DEVICE_NAME, &can_fops);
256         if (res<0) {
257                 CANMSG("Error registering driver.\n");
258                 goto register_error;
259         }
260
261         #ifdef CAN_WITH_RTL
262         can_spin_lock_init(&can_irq_manipulation_lock);
263         canqueue_rtl_initialize();
264         res=rtl_register_rtldev(major,DEVICE_NAME,&can_fops_rtl);
265         if (res<0) {
266                 CANMSG("Error registering RT-Linux major number.\n");
267                 goto rtldev_error;
268         }
269         #endif /*CAN_WITH_RTL*/
270
271         for (i=0; i<hardware_p->nr_boards; i++) {
272                 candev=hardware_p->candevice[i];
273                 if (candev->hwspecops->request_io(candev))
274                         goto request_io_error;
275                 candev->flags|=CANDEV_IO_RESERVED;
276         }
277
278         for (i=0; i<hardware_p->nr_boards; i++) {
279                 candev=hardware_p->candevice[i];
280                 if (candev->hwspecops->reset(candev))
281                         goto reset_error;
282         }
283
284         can_spin_lock_init(&hardware_p->rtr_lock);
285         hardware_p->rtr_queue=NULL;
286
287         for (i=0; i<hardware_p->nr_boards; i++) {
288                 candev=hardware_p->candevice[i];
289                 for(j=0; j<candev->nr_all_chips; j++) {
290                         if((chip=candev->chip[j])==NULL)
291                                 continue;
292
293                         if(chip->chipspecops->attach_to_chip(chip)<0) {
294                                 CANMSG("Initial attach to the chip HW failed\n");
295                                 goto interrupt_error;
296                         }
297
298                         chip->flags |= CHIP_ATTACHED;
299
300                         if(can_chip_setup_irq(chip)<0) {
301                                 CANMSG("Error to setup chip IRQ\n");
302                                 goto interrupt_error;
303                         }
304                 }
305
306                 if (candev->flags & CANDEV_PROGRAMMABLE_IRQ)
307                         if (candev->hwspecops->program_irq(candev)){
308                                 CANMSG("Error to program board interrupt\n");
309                                 goto interrupt_error;
310                         }
311         }
312
313 #ifdef CONFIG_PROC_FS
314         if (can_init_procdir())
315                 goto proc_error;
316 #endif
317
318 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
319         can_class=class_create(THIS_MODULE, "can");
320 #endif
321
322 #if defined(CONFIG_DEVFS_FS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
323         {
324             #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
325                 char dev_name[32];
326             #else
327                 struct class_device *this_dev;
328             #endif
329                 int dev_minor;
330                 for(i=0;i<MAX_TOT_MSGOBJS;i++) {
331                         if(!objects_p[i]) continue;
332                         dev_minor=objects_p[i]->minor;
333                     #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
334                         sprintf (dev_name, "can%d", dev_minor);
335                         devfs_handles[i]=devfs_register(NULL, dev_name,
336                                 DEVFS_FL_DEFAULT, major, dev_minor,
337                                 S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
338                                 &can_fops, (void*)objects_p[i]);
339                     #else
340                       #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,14))
341                         this_dev=class_device_create(can_class, MKDEV(major, dev_minor), NULL,  "can%d", dev_minor);
342                       #else /* >= 2.6.15 */
343                         this_dev=class_device_create(can_class, NULL, MKDEV(major, dev_minor), NULL,  "can%d", dev_minor);
344                       #endif /* >= 2.6.15 */
345                         if(IS_ERR(this_dev)){
346                                 CANMSG("problem to create device \"can%d\" in the class \"can\"\n", dev_minor);
347                         }else{
348                                 /*this_dev->class_data=objects_p[i];*/
349                                 class_set_devdata(this_dev,objects_p[i]);
350                         }
351                       #ifdef CONFIG_DEVFS_FS
352                         devfs_mk_cdev(MKDEV(major, dev_minor), S_IFCHR | S_IRUGO | S_IWUGO, "can%d", dev_minor);
353                       #endif
354                     #endif
355                 }
356         }
357 #endif
358
359 #if defined(CONFIG_OC_LINCAN_CARD_usbcan)
360         res = usbcan_init();
361         if (res){
362                 CANMSG("usb_register for usbcan failed. Error number %d.\n", res);
363                 return -ENODEV;
364         }
365 #endif
366
367         return 0;
368
369 #ifdef CONFIG_PROC_FS
370         proc_error: ;
371                 CANMSG("Error registering /proc entry.\n");
372                 goto memory_error;
373 #endif
374
375         interrupt_error: ;
376                 goto memory_error;
377
378         reset_error: ;
379                 CANMSG("Error resetting device.\n");
380                 goto memory_error;
381
382         request_io_error: ;
383                 CANMSG("Error to request IO resources for device.\n");
384                 goto memory_error;
385
386         memory_error: ;
387                 canhardware_done(hardware_p);
388
389                 #ifdef CAN_WITH_RTL
390                 rtl_unregister_rtldev(major,DEVICE_NAME);
391         rtldev_error:
392                 canqueue_rtl_done();
393                 #endif /*CAN_WITH_RTL*/
394
395                 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0))
396                 unregister_chrdev(major,DEVICE_NAME);
397                 #else /*LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)*/
398                 res=unregister_chrdev(major,DEVICE_NAME);
399                 if (res<0)
400                         CANMSG("Error unloading CAN driver, error: %d\n",res);
401                 else
402                         CANMSG("No CAN devices or driver setup error.\n");
403                 #endif /*LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)*/
404
405         register_error:
406                 if ( can_del_mem_list() )
407                         CANMSG("Error deallocating memory\n");
408
409                 return -ENODEV;
410 }
411
412
413
414
415
416 struct candevice_t* register_usbdev(const char *hwname,void *anydev){
417         int i=0, j, board=0;
418         struct candevice_t *candev;
419         struct canchip_t *chip;
420         struct boardtype_t *brp;
421
422         while ( (hw[board] != NULL) && (board < MAX_HW_CARDS) )
423                 board++;
424         if (board>=MAX_HW_CARDS){
425                 CANMSG("Maximum number of devices has been reached, no space for new device");
426                 return NULL;
427         }
428         brp = boardtype_find(hwname);
429         if(!brp) {
430                 CANMSG("Sorry, hardware \"%s\" is currently not supported.\n",hw[board]);
431                 return NULL;
432         }
433         if (board==MAX_HW_CARDS){
434                         CANMSG("Device \"%s\" could not be registered due to internal limits.\n",hw[board]);
435                         return NULL;
436         }
437         hw[board]=brp->boardtype;
438
439         if (init_new_hw_struct(board))
440                 return NULL;
441
442         #ifdef CAN_DEBUG
443                 list_hw();
444         #endif
445
446         candev=hardware_p->candevice[board];
447
448         /* Adding link to usb device structure into can device */
449         candev->sysdevptr.anydev=anydev;
450
451         if (candev->hwspecops->request_io(candev))
452                 goto request_io_error;
453         candev->flags|=CANDEV_IO_RESERVED;
454
455         if (candev->hwspecops->reset(candev))
456                 goto reset_error;
457
458         for(j=0; j<candev->nr_all_chips; j++) {
459                 if((chip=candev->chip[j])==NULL)
460                         continue;
461
462                 if(chip->chipspecops->attach_to_chip(chip)<0) {
463                         CANMSG("Initial attach to the chip HW failed\n");
464                         goto interrupt_error;
465                 }
466
467                 chip->flags |= CHIP_ATTACHED;
468
469                 if(can_chip_setup_irq(chip)<0) {
470                         CANMSG("Error to setup chip IRQ\n");
471                         goto interrupt_error;
472                 }
473         }
474
475         if (candev->flags & CANDEV_PROGRAMMABLE_IRQ)
476                 if (candev->hwspecops->program_irq(candev)){
477                         CANMSG("Error to program board interrupt\n");
478                         goto interrupt_error;
479                 }
480
481 #ifdef CONFIG_PROC_FS
482         if (can_init_procentry(board))
483                 goto proc_error;
484 #endif
485
486 #if defined(CONFIG_DEVFS_FS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
487         {
488                 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
489                 char dev_name[32];
490                 #else
491                 struct class_device *this_dev;
492                 #endif
493                 int dev_minor;
494                 for(i=0;i<MAX_TOT_MSGOBJS;i++) {
495                         if(!objects_p[i]) continue;
496                         if(objects_p[i]->hostchip->hostdevice != candev) continue;
497
498                         dev_minor=objects_p[i]->minor;
499                         #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
500                         sprintf (dev_name, "can%d", dev_minor);
501                         devfs_handles[i]=devfs_register(NULL, dev_name,
502                         DEVFS_FL_DEFAULT, major, dev_minor,
503                         S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
504                         &can_fops, (void*)objects_p[i]);
505                         #else
506                         #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,14))
507                         this_dev=class_device_create(can_class, MKDEV(major, dev_minor), NULL,  "can%d", dev_minor);
508                         #else /* >= 2.6.15 */
509                         this_dev=class_device_create(can_class, NULL, MKDEV(major, dev_minor), NULL,  "can%d", dev_minor);
510                         #endif /* >= 2.6.15 */
511                         if(IS_ERR(this_dev)){
512                                 CANMSG("problem to create device \"can%d\" in the class \"can\"\n", dev_minor);
513                         }else{
514                                 /*this_dev->class_data=objects_p[i];*/
515                                 class_set_devdata(this_dev,objects_p[i]);
516                         }
517                         #ifdef CONFIG_DEVFS_FS
518                         devfs_mk_cdev(MKDEV(major, dev_minor), S_IFCHR | S_IRUGO | S_IWUGO, "can%d", dev_minor);
519                         #endif
520                         #endif
521                 }
522         }
523 #endif
524         return candev;
525
526 #ifdef CONFIG_PROC_FS
527         proc_error: ;
528                 CANMSG("Error registering /proc entry.\n");
529                 goto memory_error;
530 #endif
531
532         interrupt_error: ;
533                 goto memory_error;
534
535         reset_error: ;
536                 CANMSG("Error resetting device.\n");
537                 goto memory_error;
538
539         request_io_error: ;
540                 CANMSG("Error to request IO resources for device.\n");
541                 goto memory_error;
542
543         memory_error: ;
544
545                 #ifdef CAN_WITH_RTL
546         rtldev_error:
547                 #endif /*CAN_WITH_RTL*/
548
549 //      register_error:
550                 if ( can_del_mem_list() )
551                         CANMSG("Error deallocating memory\n");
552
553                 return NULL;
554 }
555
556
557
558
559
560
561
562 void cleanup_usbdev(struct candevice_t *dev)
563 {
564         int i=0;
565         int dev_minor;
566
567         if (!dev)
568                 return;
569
570 #ifdef CONFIG_PROC_FS
571         if (can_delete_procentry(dev))
572                 CANMSG("Error unregistering /proc/can entry.\n");
573 #endif
574
575 #if defined(CONFIG_DEVFS_FS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
576         for(i=0;i<MAX_TOT_MSGOBJS;i++) {
577                 if(!objects_p[i]) continue;
578                 if(objects_p[i]->hostchip->hostdevice != dev) continue;
579                 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
580                 if(devfs_handles[i])
581                         devfs_unregister(devfs_handles[i]);
582                 #else
583                 dev_minor=objects_p[i]->minor;
584                 if(dev_minor>=0){
585                         #ifdef CONFIG_DEVFS_FS
586                         devfs_remove("can%d", dev_minor);
587                         #endif
588                         class_device_destroy(can_class, MKDEV(major, dev_minor));
589                 }
590                 #endif
591         }
592 #endif
593
594         for(i=0;i<MAX_TOT_CHIPS;i++){
595                 if(!chips_p[i]) continue;
596                 if(chips_p[i]->hostdevice != dev) continue;
597                 chips_p[i]=NULL;
598         }
599
600         hardware_p->candevice[dev->candev_idx]=NULL;
601         hardware_p->nr_boards--;
602         hw[dev->candev_idx]=NULL;
603
604         candevice_done(dev);
605         can_checked_free(dev);
606 }
607
608
609
610
611 void cleanup_module(void)
612 {
613         int res=0,i=0;
614
615 #if defined(CONFIG_OC_LINCAN_CARD_usbcan)
616         usbcan_exit();
617 #endif
618
619 #ifdef CONFIG_PROC_FS
620         if (can_delete_procdir())
621                 CANMSG("Error unregistering /proc/can entry.\n");
622 #endif
623
624 #if defined(CONFIG_DEVFS_FS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
625         for(i=0;i<MAX_TOT_MSGOBJS;i++) {
626             #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
627                 if(devfs_handles[i])
628                         devfs_unregister(devfs_handles[i]);
629             #else
630                 int dev_minor;
631                 if(!objects_p[i]) continue;
632                 dev_minor=objects_p[i]->minor;
633                 if(minor>=0){
634                     #ifdef CONFIG_DEVFS_FS
635                         devfs_remove("can%d", dev_minor);
636                     #endif
637                         class_device_destroy(can_class, MKDEV(major, dev_minor));
638                 }
639             #endif
640         }
641 #endif
642
643 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
644         class_destroy(can_class);
645 #endif
646
647         canhardware_done(hardware_p);
648
649         #ifdef CAN_WITH_RTL
650         rtl_unregister_rtldev(major,DEVICE_NAME);
651         canqueue_rtl_done();
652         #endif /*CAN_WITH_RTL*/
653
654         if ( can_del_mem_list() )
655                 CANMSG("Error deallocating memory\n");
656
657         #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0))
658         unregister_chrdev(major,DEVICE_NAME);
659         #else /*LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)*/
660         res=unregister_chrdev(major,DEVICE_NAME);
661         if (res<0)
662                 CANMSG("Error unregistering CAN driver, error: %d\n",res);
663         #endif /*LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)*/
664 }