Sysfs device creation for kernels >= 2.6.26. stable-1.4
authorFlorian Pose <fp@igh-essen.com>
Fri, 19 Jun 2009 11:48:42 +0000
branchstable-1.4
changeset 1700 86648ba63030
parent 1699 89ba41136b21
child 1701 ec5542b4f62a
Sysfs device creation for kernels >= 2.6.26.
master/master.c
master/master.h
--- a/master/master.c	Fri Jun 19 11:46:53 2009 +0000
+++ b/master/master.c	Fri Jun 19 11:48:42 2009 +0000
@@ -188,14 +188,22 @@
     if (ec_cdev_init(&master->cdev, master, device_number))
         goto out_clear_fsm;
     
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 15)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
+    master->class_device = device_create(class, NULL,
+            MKDEV(MAJOR(device_number), master->index), NULL,
+            "EtherCAT%u", master->index);
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
+    master->class_device = device_create(class, NULL,
+            MKDEV(MAJOR(device_number), master->index),
+            "EtherCAT%u", master->index);
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15)
+    master->class_device = class_device_create(class, NULL,
+            MKDEV(MAJOR(device_number), master->index), NULL,
+            "EtherCAT%u", master->index);
+#else
     master->class_device = class_device_create(class,
-            MKDEV(MAJOR(device_number), master->index),
-            NULL, "EtherCAT%u", master->index);
-#else
-    master->class_device = class_device_create(class, NULL,
-            MKDEV(MAJOR(device_number), master->index),
-            NULL, "EtherCAT%u", master->index);
+            MKDEV(MAJOR(device_number), master->index), NULL,
+            "EtherCAT%u", master->index);
 #endif
     if (IS_ERR(master->class_device)) {
         EC_ERR("Failed to create class device!\n");
@@ -225,7 +233,12 @@
         ec_master_t *master /**< EtherCAT master */
         )
 {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
+    device_unregister(master->class_device);
+#else
     class_device_unregister(master->class_device);
+#endif
+
     ec_cdev_clear(&master->cdev);
 #ifdef EC_EOE
     ec_master_clear_eoe_handlers(master);
--- a/master/master.h	Fri Jun 19 11:46:53 2009 +0000
+++ b/master/master.h	Fri Jun 19 11:48:42 2009 +0000
@@ -34,11 +34,16 @@
 #ifndef __EC_MASTER_H__
 #define __EC_MASTER_H__
 
+#include <linux/version.h>
 #include <linux/list.h>
 #include <linux/timer.h>
 #include <linux/wait.h>
 #include <linux/kthread.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
+#include <linux/semaphore.h>
+#else
 #include <asm/semaphore.h>
+#endif
 
 #include "device.h"
 #include "domain.h"
@@ -81,7 +86,11 @@
     unsigned int reserved; /**< \a True, if the master is in use. */
 
     ec_cdev_t cdev; /**< Master character device. */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
+    struct device *class_device; /**< Master class device. */
+#else
     struct class_device *class_device; /**< Master class device. */
+#endif
     struct semaphore master_sem; /**< Master semaphore. */
 
     ec_device_t main_device; /**< EtherCAT main device. */