[svn-commits] tzafrir: branch linux/tzafrir/sysfs r8359 - /linux/team/tzafrir/sysfs/drivers...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Mar 21 07:02:29 CDT 2010


Author: tzafrir
Date: Sun Mar 21 07:02:22 2010
New Revision: 8359

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8359
Log:
chan class is 'dahdi'. Use to generate dev files

* Remove code from dahdi-base.c to generate device files.
* Rename channels SysFS class to be 'dahdi'.
* Generate device files under it.
  - Still with dummy devices.
* We need the channo for proper destruction. Thus don't set it to
  -1 in dahdi_chan_unreg: wait till SysFS unregistration.

Modified:
    linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-base.c
    linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c

Modified: linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-base.c
URL: http://svnview.digium.com/svn/dahdi/linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-base.c?view=diff&rev=8359&r1=8358&r2=8359
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-base.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-base.c Sun Mar 21 07:02:22 2010
@@ -143,8 +143,6 @@
 EXPORT_SYMBOL(dahdi_hdlc_getbuf);
 EXPORT_SYMBOL(dahdi_hdlc_putbuf);
 EXPORT_SYMBOL(dahdi_alarm_channel);
-EXPORT_SYMBOL(dahdi_register_chardev);
-EXPORT_SYMBOL(dahdi_unregister_chardev);
 
 EXPORT_SYMBOL(dahdi_register_echocan_factory);
 EXPORT_SYMBOL(dahdi_unregister_echocan_factory);
@@ -184,14 +182,6 @@
 #else
 #define CLASS_DEV_DESTROY(class, devt) \
 	class_simple_device_remove(class, devt)
-#endif
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
-static struct class *dahdi_class = NULL;
-#else
-static struct class_simple *dahdi_class = NULL;
-#define class_create class_simple_create
-#define class_destroy class_simple_destroy
 #endif
 
 static int deftaps = 64;
@@ -1994,7 +1984,8 @@
 				chans[x]->confmode = 0;
 			}
 		}
-	chan->channo = -1;
+	/* FIXME: done in chan_device_unregister for now */
+	//chan->channo = -1;
 	write_unlock_irqrestore(&chan_lock, flags);
 }
 
@@ -5934,16 +5925,6 @@
 	}
 #endif
 
-	for (x = 0; x < span->channels; x++) {
-		if (span->chans[x]->channo < 250) {
-			char chan_name[32];
-			snprintf(chan_name, sizeof(chan_name), "dahdi!%d", 
-					span->chans[x]->channo);
-			CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, 
-					span->chans[x]->channo), NULL, chan_name);
-		}
-	}
-
 	if (debug) {
 		module_printk(KERN_NOTICE, "Registered Span %d ('%s') with "
 				"%d channels\n", span->spanno, span->name, span->channels);
@@ -6011,11 +5992,6 @@
 	snprintf(tempfile, sizeof(tempfile)-1, "dahdi/%d", span->spanno);
         remove_proc_entry(tempfile, NULL);
 #endif /* CONFIG_PROC_FS */
-
-	for (x = 0; x < span->channels; x++) {
-		if (span->chans[x]->channo < 250)
-			CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, span->chans[x]->channo));
-	}
 
 	spans[span->spanno] = NULL;
 	span->spanno = 0;
@@ -8624,30 +8600,6 @@
 
 #endif
 
-int dahdi_register_chardev(struct dahdi_chardev *dev)
-{
-	static const char *DAHDI_STRING = "dahdi!";
-	char *udevname;
-
-	udevname = kzalloc(strlen(dev->name) + sizeof(DAHDI_STRING) + 1,
-			   GFP_KERNEL);
-	if (!udevname)
-		return -ENOMEM;
-
-	strcpy(udevname, DAHDI_STRING);
-	strcat(udevname, dev->name);
-	CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, dev->minor), NULL, udevname);
-	kfree(udevname);
-	return 0;
-}
-
-int dahdi_unregister_chardev(struct dahdi_chardev *dev)
-{
-	CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, dev->minor));
-
-	return 0;
-}
-
 static int __init dahdi_init(void)
 {
 	int res = 0;
@@ -8668,12 +8620,6 @@
 		module_printk(KERN_ERR, "Error starting sysfs: %d\n", res);
 		return res;
 	}
-
-	dahdi_class = class_create(THIS_MODULE, "dahdi");
-	CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, 253), NULL, "dahdi!timer");
-	CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, 254), NULL, "dahdi!channel");
-	CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, 255), NULL, "dahdi!pseudo");
-	CLASS_DEV_CREATE(dahdi_class, MKDEV(DAHDI_MAJOR, 0), NULL, "dahdi!ctl");
 
 	module_printk(KERN_INFO, "Telephony Interface Registered on major %d\n", DAHDI_MAJOR);
 	module_printk(KERN_INFO, "Version: %s\n", DAHDI_VERSION);
@@ -8693,12 +8639,6 @@
 
 	coretimer_cleanup();
 
-	CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, 253)); /* timer */
-	CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, 254)); /* channel */
-	CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, 255)); /* pseudo */
-	CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, 0)); /* ctl */
-	class_destroy(dahdi_class);
-
 	unregister_chrdev(DAHDI_MAJOR, "dahdi");
 
 #ifdef CONFIG_PROC_FS

Modified: linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c
URL: http://svnview.digium.com/svn/dahdi/linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c?view=diff&rev=8359&r1=8358&r2=8359
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c Sun Mar 21 07:02:22 2010
@@ -37,6 +37,44 @@
 #include <linux/workqueue.h>
 #include <linux/delay.h>	/* for msleep() to debug */
 #include <dahdi/kernel.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
+#define device_create(class, parent, devt, drvdata, fmt, ...) \
+	device_create(class, parent, devt, fmt, ## __VA_ARGS__)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
+#define device_create(class, parent, devt, drvdata, fmt, ...) \
+	class_device_create(class, parent, devt, fmt, ## __VA_ARGS__)
+#else
+/* FIXME: is using class for 'class_simple' OK? Casting required? */
+#define device_create(class, parent, devt, drvdata, fmt, ...) \
+	class_simple_device_add(class, parent, devt, fmt, ## __VA_ARGS__)
+#endif
+#endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
+#define device_destroy(class, devt) \
+	class_device_create(class, devt)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 9)
+/* FIXME: is using class for 'class_simple' OK? Casting required? */
+#define device_destroy(class, devt) \
+	class_simple_device_remove(devt)
+#else
+#define device_destroy(class, devt) \
+	class_simple_device_remove(class, devt)
+#endif
+#endif
+
+/* FIXME: make sure drvdata is always NULL. Otherwise this will
+ * break our silly macro above for older kernels.
+ */
+#define create_dev_file(class, devnum, name, ...) \
+	device_create(class, NULL, MKDEV(DAHDI_MAJOR, devnum), NULL, \
+			name, ## __VA_ARGS__);
+
+#define destroy_dev_file(class, devnum) \
+	device_destroy(class, MKDEV(DAHDI_MAJOR, devnum));
 
 /*
  * Hotplug replaced with uevent in 2.6.16
@@ -103,7 +141,14 @@
 	__ATTR_NULL,
 };
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
 static struct class *chan_class;
+#else
+static struct class_simple *chan_class;
+#define class_create class_simple_create
+#define class_destroy class_simple_destroy
+#endif
+
 
 static void chan_release(struct device *dev)
 {
@@ -136,6 +181,10 @@
 				__func__, res);
 		return res;
 	}
+	if (chan->channo < 250)
+		create_dev_file(chan_class, chan->channo, "dahdi!%d",
+				chan->channo);
+
 	return 0;
 }
 
@@ -144,28 +193,53 @@
 	struct device	*dev = &chan->chan_device;
 
 	chan_dbg(DEVICES, chan, "SYSFS\n");
+	chan_dbg(DEVICES, chan, "Destroying channel %d\n", chan->channo);
+	if (chan->channo < 250)
+		destroy_dev_file(chan_class, chan->channo);
 	dev = &chan->chan_device;
 	if (!dev_get_drvdata(dev))
 		return;
 	BUG_ON(dev_get_drvdata(dev) != chan);
 	device_unregister(dev);
 	dev_set_drvdata(dev, NULL);
-}
+	/* FIXME: should have been done earlier in dahdi_chan_unreg */
+	chan->channo = -1;
+}
+
+int dahdi_register_chardev(struct dahdi_chardev *dev)
+{
+	/* FIXME: Error handling */
+	create_dev_file(chan_class, dev->minor, "dahdi!%s", dev->name);
+	return 0;
+}
+EXPORT_SYMBOL(dahdi_register_chardev);
+
+int dahdi_unregister_chardev(struct dahdi_chardev *dev)
+{
+	destroy_dev_file(chan_class, dev->minor);
+	return 0;
+}
+EXPORT_SYMBOL(dahdi_unregister_chardev);
 
 /*--------- Sysfs Device handling ----*/
-
 int __init dahdi_driver_chan_init(void)
 {
 	int	res;
 
 	dahdi_dbg(DEVICES, "SYSFS\n");
-	chan_class = class_create(THIS_MODULE, "dahdi_chan");
+	chan_class = class_create(THIS_MODULE, "dahdi");
 	if (IS_ERR(chan_class)) {
 		res = PTR_ERR(chan_class);
 		dahdi_err("%s: class_create(dahi_chan) failed. Error: %d\n",
 			__func__, res);
 		return res;
 	}
+	/* NULL parent, NULL drvdata */
+	/* FIXME: error handling */
+	create_dev_file(chan_class, 253, "dahdi!timer");
+	create_dev_file(chan_class, 254, "dahdi!channel");
+	create_dev_file(chan_class, 255, "dahdi!pseudo");
+	create_dev_file(chan_class, 0,   "dahdi!ctl");
 	chan_class->dev_attrs = chan_dev_attrs;
 	return 0;
 }
@@ -174,6 +248,10 @@
 void dahdi_driver_chan_exit(void)
 {
 	dahdi_dbg(DEVICES, "SYSFS\n");
+	destroy_dev_file(chan_class, 0);
+	destroy_dev_file(chan_class, 255);
+	destroy_dev_file(chan_class, 254);
+	destroy_dev_file(chan_class, 253);
 	class_unregister(chan_class);
 }
 EXPORT_SYMBOL(dahdi_driver_chan_exit);




More information about the svn-commits mailing list