[svn-commits] tzafrir: branch linux/tzafrir/sysfs r8386 - in /linux/team/tzafrir/sysfs: dri...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Mar 22 14:01:19 CDT 2010


Author: tzafrir
Date: Mon Mar 22 14:01:16 2010
New Revision: 8386

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8386
Log:
A single but separate major number for DAHDI channels

DAHDI relies on the minor number to tell the channel number. Let's not
fix that just yet.

* Allocate a separate major number dynamicaly for channels.
* Special devices still use major number 196 as before.
* Regular devices use <new-major>:<chan-number>

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

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=8386&r1=8385&r2=8386
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-base.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-base.c Mon Mar 22 14:01:16 2010
@@ -8612,7 +8612,7 @@
 		return res;
 	}
 
-	res = dahdi_driver_init();
+	res = dahdi_driver_init(&dahdi_fops);
 	if (res != 0) {
 		// TODO: Remove this. dahdi_driver_init should report
 		// errors.

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=8386&r1=8385&r2=8386
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c Mon Mar 22 14:01:16 2010
@@ -32,6 +32,7 @@
 #define DAHDI_PRINK_MACROS_USE_debug
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/cdev.h>
 #include <linux/errno.h>
 #include <linux/proc_fs.h>
 #include <linux/workqueue.h>
@@ -105,6 +106,8 @@
 
 extern int debug;
 
+static dev_t dahdi_channels_devt;
+static struct cdev dahdi_channels_cdev;
 
 /*--------- Sysfs channel handling ----*/
 
@@ -170,7 +173,7 @@
 	BUG_ON(!chan);
 	span = chan->span;
 	BUG_ON(!span);
-	devt = span->first_devt + chan->chanpos - 1;
+	devt = MKDEV(MAJOR(dahdi_channels_devt), chan->channo);
 	chan_dbg(DEVICES, chan, "SYSFS\n");
 	dev = &chan->chan_device;
 	dev->devt = devt;
@@ -222,7 +225,8 @@
 EXPORT_SYMBOL(dahdi_unregister_chardev);
 
 /*--------- Sysfs Device handling ----*/
-int __init dahdi_driver_chan_init(void)
+
+int __init dahdi_driver_chan_init(const struct file_operations *fops)
 {
 	int	res;
 
@@ -234,6 +238,25 @@
 			__func__, res);
 		return res;
 	}
+	res = alloc_chrdev_region(&dahdi_channels_devt, 0, DAHDI_MAX_CHANNELS,
+			"dahdi-channels");
+	if (res) {
+		dahdi_err("%s: Failed allocating chrdev for %d channels (%d)",
+			__func__, DAHDI_MAX_CHANNELS, res);
+		class_unregister(chan_class);
+		return res;
+	}
+	cdev_init(&dahdi_channels_cdev, fops);
+	res = cdev_add(&dahdi_channels_cdev, dahdi_channels_devt,
+			DAHDI_MAX_CHANNELS);
+	if (res) {
+		dahdi_err("%s: cdev_add() failed (%d)", __func__, res);
+		unregister_chrdev_region(dahdi_channels_devt,
+				DAHDI_MAX_CHANNELS);
+		class_unregister(chan_class);
+		return res;
+	}
+
 	/* NULL parent, NULL drvdata */
 	/* FIXME: error handling */
 	create_dev_file(chan_class, MKDEV(DAHDI_MAJOR, DAHDI_TIMER),
@@ -256,6 +279,8 @@
 	destroy_dev_file(chan_class, MKDEV(DAHDI_MAJOR, DAHDI_PSEUDO));
 	destroy_dev_file(chan_class, MKDEV(DAHDI_MAJOR, DAHDI_CHANNEL));
 	destroy_dev_file(chan_class, MKDEV(DAHDI_MAJOR, DAHDI_TIMER));
+	cdev_del(&dahdi_channels_cdev);
+	unregister_chrdev_region(dahdi_channels_devt, DAHDI_MAX_CHANNELS);
 	class_unregister(chan_class);
 }
 EXPORT_SYMBOL(dahdi_driver_chan_exit);

Modified: linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c
URL: http://svnview.digium.com/svn/dahdi/linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c?view=diff&rev=8386&r1=8385&r2=8386
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c Mon Mar 22 14:01:16 2010
@@ -300,8 +300,6 @@
 		struct dahdi_chan *chan = span->chans[x];
 		chan_device_unregister(chan);
 	}
-	if (span->channels)
-		unregister_chrdev_region(span->first_devt, span->channels);
 	if (!dev_get_drvdata(span_device))
 		return;
 	BUG_ON(dev_get_drvdata(span_device) != span);
@@ -315,7 +313,6 @@
 	struct device	*span_device;
 	int		res = 0;
 	int		x;
-	int		first_devt = 0;
 
 	BUG_ON(!span);
 	span_device = &span->span_device;
@@ -336,12 +333,6 @@
 		goto err_device_register;
 	}
 
-	res = alloc_chrdev_region(&first_devt, 0, span->channels, span->name);
-	if (res) {
-		span_notice(span, "Failed registering chrdev region (%d)", res);
-		goto err_alloc_chrdev_region;
-	}
-	span->first_devt = first_devt;
 	for (x = 0; x < span->channels; x++) {
 		struct dahdi_chan *chan = span->chans[x];
 		res = chan_device_register(chan);
@@ -359,19 +350,16 @@
 		struct dahdi_chan *chan = span->chans[x];
 		chan_device_unregister(chan);
 	}
-	unregister_chrdev_region(first_devt, span->channels);
-err_alloc_chrdev_region:
 	device_unregister(span_device);
 err_device_register:
 	dev_set_drvdata(span_device, NULL);
 	span_device->class = NULL;
 	span_device->parent = NULL;
-	span->first_devt = 0;
 	return res;
 }
 EXPORT_SYMBOL(span_sysfs_create);
 
-int __init dahdi_driver_init(void)
+int __init dahdi_driver_init(const struct file_operations *fops)
 {
 	int	res;
 
@@ -396,7 +384,7 @@
 			__func__, dev_name(&toplevel_device), res);
 		goto failed_busdevice;
 	}
-	res = dahdi_driver_chan_init();
+	res = dahdi_driver_chan_init(fops);
 	if (res < 0)
 		goto failed_chan_bus;
 	return 0;

Modified: linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.h
URL: http://svnview.digium.com/svn/dahdi/linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.h?view=diff&rev=8386&r1=8385&r2=8386
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.h (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.h Mon Mar 22 14:01:16 2010
@@ -1,7 +1,7 @@
 /* Global */
-int __init dahdi_driver_init(void);
+int __init dahdi_driver_init(const struct file_operations *fops);
 void dahdi_driver_exit(void);
-int __init dahdi_driver_chan_init(void);
+int __init dahdi_driver_chan_init(const struct file_operations *fops);
 void dahdi_driver_chan_exit(void);
 
 /* per-span */

Modified: linux/team/tzafrir/sysfs/include/dahdi/kernel.h
URL: http://svnview.digium.com/svn/dahdi/linux/team/tzafrir/sysfs/include/dahdi/kernel.h?view=diff&rev=8386&r1=8385&r2=8386
==============================================================================
--- linux/team/tzafrir/sysfs/include/dahdi/kernel.h (original)
+++ linux/team/tzafrir/sysfs/include/dahdi/kernel.h Mon Mar 22 14:01:16 2010
@@ -863,7 +863,6 @@
 	 */
 	struct device *parent_device; /*!< Location in the devices tree */
 #define dev_to_span(dev)  container_of(dev, struct dahdi_span, span_device)
-	dev_t first_devt;		/* Device number of first channel */
 	int spanno;			/*!< Span number for DAHDI */
 	int offset;			/*!< Offset within a given card */
 	int lastalarms;		/*!< Previous alarms */




More information about the svn-commits mailing list