]> rtime.felk.cvut.cz Git - lincan.git/blobdiff - lincan/src/main.c
Updates to compile with 2.6.26 Linux kernel.
[lincan.git] / lincan / src / main.c
index 2a55355c67ff31cd863ff32b066319c4d9e1df4c..7e8181f3e264affa523d1772158b7ef7dbb314e1 100644 (file)
@@ -97,7 +97,7 @@ unsigned int irq_specified;
 unsigned int io_specified;
 unsigned int clockfreq_specified;
 
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12))
 /* Module parameters, some must be supplied at module loading time */
 MODULE_PARM(major,"1i");
 /*MODULE_PARM(minor, "1-" __MODULE_STRING(MAX_TOT_CHIPS)"i");*/
@@ -114,7 +114,7 @@ MODULE_PARM(extmask, "1i");
 MODULE_PARM(mo15mask, "1i");
 MODULE_PARM(processlocal, "1i");
 
-#else /* LINUX_VERSION_CODE >= 2,6,0 */
+#else /* LINUX_VERSION_CODE >= 2,6,12 */
 module_param(major, int, 0);
 module_param_array(minor, int, &minor_specified, 0);
 module_param(extended, int, 0);
@@ -128,7 +128,7 @@ module_param(stdmask, int, 0);
 module_param(extmask, int, 0);
 module_param(mo15mask, int, 0);
 module_param(processlocal, int, 0);
-#endif /* LINUX_VERSION_CODE >= 2,6,0 */
+#endif /* LINUX_VERSION_CODE >= 2,6,12 */
 
 MODULE_PARM_DESC(major,"can be used to change default major [" __MODULE_STRING(CAN_MAJOR) "]");
 MODULE_PARM_DESC(minor,"can be used to change default starting minor for each channel");
@@ -324,8 +324,10 @@ int init_module(void)
         {
            #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,0))
                char dev_name[32];
-           #else
+           #elif  LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25) /* >= 2.6.15 */
                struct class_device *this_dev;
+           #else
+               struct device *this_dev;
            #endif
                int dev_minor;
                for(i=0;i<MAX_TOT_MSGOBJS;i++) {
@@ -340,14 +342,18 @@ int init_module(void)
                    #else
                      #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,14))
                        this_dev=class_device_create(can_class, MKDEV(major, dev_minor), NULL,  "can%d", dev_minor);
-                     #else /* >= 2.6.15 */
+                     #elif  LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25) /* >= 2.6.15 */
                        this_dev=class_device_create(can_class, NULL, MKDEV(major, dev_minor), NULL,  "can%d", dev_minor);
-                     #endif /* >= 2.6.15 */
+                     #else /* >= 2.6.26 */
+                       this_dev=device_create_drvdata(can_class, NULL, MKDEV(major, dev_minor), objects_p[i],  "can%d", dev_minor);
+                     #endif /* >= 2.6.26 */
                        if(IS_ERR(this_dev)){
                                CANMSG("problem to create device \"can%d\" in the class \"can\"\n", dev_minor);
+                     #if  LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25)
                        }else{
                                /*this_dev->class_data=objects_p[i];*/
                                class_set_devdata(this_dev,objects_p[i]);
+                     #endif /* <= 2.6.25 */
                        }
                      #ifdef CONFIG_DEVFS_FS
                        devfs_mk_cdev(MKDEV(major, dev_minor), S_IFCHR | S_IRUGO | S_IWUGO, "can%d", dev_minor);
@@ -384,11 +390,8 @@ int init_module(void)
                canqueue_rtl_done();
                #endif /*CAN_WITH_RTL*/
 
-               res=unregister_chrdev(major,DEVICE_NAME);
-               if (res<0)
-                       CANMSG("Error unloading CAN driver, error: %d\n",res);
-               else
-                       CANMSG("No CAN devices or driver setup error.\n");
+               unregister_chrdev(major,DEVICE_NAME);
+               CANMSG("No CAN devices or driver setup error.\n");
 
        register_error:
                if ( can_del_mem_list() ) 
@@ -399,7 +402,9 @@ int init_module(void)
 
 void cleanup_module(void)
 {
-       int res=0,i=0;
+#if defined(CONFIG_DEVFS_FS) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
+       int i=0;
+#endif
 
 #ifdef CONFIG_PROC_FS
        if (can_delete_procdir())
@@ -419,7 +424,11 @@ void cleanup_module(void)
                    #ifdef CONFIG_DEVFS_FS
                        devfs_remove("can%d", dev_minor);
                    #endif
+                   #if  LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,25)
                        class_device_destroy(can_class, MKDEV(major, dev_minor));
+                   #else /* >= 2.6.26 */
+                       device_destroy(can_class, MKDEV(major, dev_minor));
+                   #endif /* >= 2.6.26 */
                }
            #endif
                }
@@ -439,7 +448,5 @@ void cleanup_module(void)
        if ( can_del_mem_list() ) 
                CANMSG("Error deallocating memory\n");
 
-       res=unregister_chrdev(major,DEVICE_NAME);
-       if (res<0)
-               CANMSG("Error unregistering CAN driver, error: %d\n",res);
+       unregister_chrdev(major,DEVICE_NAME);
 }