Create class device with device_number information in sysfs.
authorFlorian Pose <fp@igh-essen.com>
Tue, 17 Jun 2008 12:49:06 +0000
changeset 1013 52256b75f975
parent 1012 89f87a901ce5
child 1014 d39d430cfdc4
Create class device with device_number information in sysfs.
master/master.c
master/master.h
master/module.c
--- a/master/master.c	Tue Jun 17 12:19:17 2008 +0000
+++ b/master/master.c	Tue Jun 17 12:49:06 2008 +0000
@@ -76,7 +76,8 @@
         unsigned int index, /**< master index */
         const uint8_t *main_mac, /**< MAC address of main device */
         const uint8_t *backup_mac, /**< MAC address of backup device */
-        dev_t device_number /**< Character device number. */
+        dev_t device_number, /**< Character device number. */
+        struct class *class /**< Device class. */
         )
 {
     unsigned int i;
@@ -170,9 +171,19 @@
     // init character device
     if (ec_cdev_init(&master->cdev, master, device_number))
         goto out_clear_fsm;
+    
+    master->class_device = class_device_create(class,
+            MKDEV(MAJOR(device_number), master->index),
+            NULL, "EtherCAT%u", master->index);
+    if (IS_ERR(master->class_device)) {
+        EC_ERR("Failed to create class device!\n");
+        goto out_clear_cdev;
+    }
 
     return 0;
 
+out_clear_cdev:
+    ec_cdev_clear(&master->cdev);
 out_clear_fsm:
     ec_fsm_master_clear(&master->fsm);
     ec_datagram_clear(&master->fsm_datagram);
@@ -192,6 +203,7 @@
         ec_master_t *master /**< EtherCAT master */
         )
 {
+    class_device_unregister(master->class_device);
     ec_cdev_clear(&master->cdev);
 #ifdef EC_EOE
     ec_master_clear_eoe_handlers(master);
--- a/master/master.h	Tue Jun 17 12:19:17 2008 +0000
+++ b/master/master.h	Tue Jun 17 12:49:06 2008 +0000
@@ -84,6 +84,7 @@
     unsigned int reserved; /**< non-zero, if the master is reserved for RT */
 
     ec_cdev_t cdev; /**< Master character device. */
+    struct class_device *class_device; /**< Master class device. */
 
     ec_device_t main_device; /**< EtherCAT device */
     const uint8_t *main_mac; /**< MAC address of main device */
@@ -167,7 +168,7 @@
 
 // master creation/deletion
 int ec_master_init(ec_master_t *, unsigned int, const uint8_t *,
-        const uint8_t *, dev_t);
+        const uint8_t *, dev_t, struct class *);
 void ec_master_clear(ec_master_t *);
 
 // mode transitions
--- a/master/module.c	Tue Jun 17 12:19:17 2008 +0000
+++ b/master/module.c	Tue Jun 17 12:49:06 2008 +0000
@@ -144,7 +144,7 @@
     
     for (i = 0; i < master_count; i++) {
         if (ec_master_init(&masters[i], i, macs[i][0], macs[i][1],
-                    device_number)) {
+                    device_number, class)) {
             ret = -ENOMEM;
             goto out_free_masters;
         }