[svn-commits] tzafrir: branch linux/tzafrir/sysfs r8595 - in /linux/team/tzafrir/sysfs: bui...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon May 3 10:13:38 CDT 2010


Author: tzafrir
Date: Mon May  3 10:13:34 2010
New Revision: 8595

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8595
Log:
Partial switch: class to bus. Builds with 2.6.18

* Spans now reside under /sys/bus/dahdi_spans.
* Channels are represented as /sys/bus/dahdi_chans .
* The name of a channel device is /dev/dahdi/spans/$SPAN_NUM/$CHAN_INDEX
  (chan_index: numbering of channel in span).
* UDEV rules adjusted.
* Note that /dev/dahdi/N are now symlinks generated by those udev rules.
* /sys/class/dahdi only holds the standard device files.

Modified:
    linux/team/tzafrir/sysfs/build_tools/genudevrules
    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/drivers/dahdi/xpp/xpp_dahdi.c

Modified: linux/team/tzafrir/sysfs/build_tools/genudevrules
URL: http://svnview.digium.com/svn/dahdi/linux/team/tzafrir/sysfs/build_tools/genudevrules?view=diff&rev=8595&r1=8594&r2=8595
==============================================================================
--- linux/team/tzafrir/sysfs/build_tools/genudevrules (original)
+++ linux/team/tzafrir/sysfs/build_tools/genudevrules Mon May  3 10:13:34 2010
@@ -37,5 +37,6 @@
 
 # DAHDI devices with ownership/permissions for running as non-root
 SUBSYSTEM${match}"dahdi",  OWNER="asterisk", GROUP="asterisk", MODE="0660"
-SUBSYSTEM${match}"dahdi",  PROGRAM="/usr/share/dahdi/dahdi_symlinks" SYMLINK+="\$result"
+SUBSYSTEM${match}"dahdi_chans",  OWNER="asterisk", GROUP="asterisk", MODE="0660"
+SUBSYSTEM${natch}"dahdi_chans",  SYMLINK+="dahdi/\$env{MINOR}"
 EOF

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=8595&r1=8594&r2=8595
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c Mon May  3 10:13:34 2010
@@ -32,75 +32,12 @@
 #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>
 #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, devnum, NULL, name, ## __VA_ARGS__)
-
-#define destroy_dev_file(class, devnum) \
-	device_destroy(class, devnum)
-
-/*
- * Hotplug replaced with uevent in 2.6.16
- */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
-#define	OLD_HOTPLUG_SUPPORT	/* for older kernels */
-#endif
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
-#define	DEVICE_ATTR_READER(name, dev, buf)	\
-		ssize_t name(struct device *dev, \
-				struct device_attribute *attr, char *buf)
-#define	DEVICE_ATTR_WRITER(name, dev, buf, count)	\
-		ssize_t name(struct device *dev, \
-				struct device_attribute *attr, \
-				const char *buf, size_t count)
-#define BUS_ATTR_READER(name, dev, buf) \
-   ssize_t name(struct device *dev, struct device_attribute *attr, char *buf)
-#else
-#define	DEVICE_ATTR_READER(name, dev, buf)	\
-		ssize_t name(struct device *dev, char *buf)
-#define	DEVICE_ATTR_WRITER(name, dev, buf, count)	\
-		ssize_t name(struct device *dev, const char *buf, size_t count)
-#define BUS_ATTR_READER(name, dev, buf) \
-   ssize_t name(struct device *dev, char *buf)
-#endif
+#include <linux/cdev.h>
+#include "dahdi-sysfs.h"
 
 static const char rcsid[] = "$Id$";
 
@@ -108,6 +45,28 @@
 
 static dev_t dahdi_channels_devt;
 static struct cdev dahdi_channels_cdev;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
+#define create_dev_file(class, devt, name, ...) \
+	device_create(class, NULL, devt, NULL, name, ## __VA_ARGS__)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
+#define create_dev_file(class, devt, name, ...) \
+	device_create(class, NULL, devt, name, ## __VA_ARGS__)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
+#define create_dev_file(class, devt, name, ...) \
+	device_create(class, NULL, devt, NULL, name, ## __VA_ARGS__)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
+#define create_dev_file(class, devt, name, ...) \
+	class_device_create(class, NULL, devt, NULL, name, ## __VA_ARGS__)
+#endif
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
+#define destroy_dev_file(class, devt) \
+	device_destroy(class, devt)
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
+#define destroy_dev_file(class, devt) \
+	class_device_destroy(class, devt)
+#endif
 
 /*--------- Sysfs channel handling ----*/
 
@@ -190,7 +149,48 @@
 	chan_dbg(DEVICES, chan, "SYSFS\n");
 }
 
-int chan_device_register(struct dahdi_chan *chan)
+static int chan_match(struct device *dev, struct device_driver *driver)
+{
+	struct dahdi_chan	*chan;
+
+	chan = dev_to_chan(dev);
+	chan_dbg(DEVICES, chan, "%s: SYSFS\n", __func__);
+	return 1;
+}
+
+static struct bus_type chan_bus_type = {
+	.name           = "dahdi_chans",
+	.match          = chan_match,
+	.dev_attrs	= chan_dev_attrs,
+};
+
+static int chan_probe(struct device *dev)
+{
+	struct dahdi_chan	*chan;
+
+	chan = dev_to_chan(dev);
+	return 0;
+}
+
+static int chan_remove(struct device *dev)
+{
+	struct dahdi_chan	*chan;
+
+	chan = dev_to_chan(dev);
+	return 0;
+}
+
+static struct device_driver	chan_driver = {
+	.name = "generic_chan",
+	.bus = &chan_bus_type,
+#ifndef OLD_HOTPLUG_SUPPORT
+	.owner = THIS_MODULE,
+#endif
+	.probe = chan_probe,
+	.remove = chan_remove
+};
+
+int chan_sysfs_create(struct dahdi_chan *chan)
 {
 	struct device		*dev = &chan->chan_device;
 	struct dahdi_span	*span;
@@ -204,9 +204,13 @@
 	chan_dbg(DEVICES, chan, "SYSFS\n");
 	dev = &chan->chan_device;
 	dev->devt = devt;
-	dev->class = chan_class;
+	dev->class = NULL;
+	dev->bus = &chan_bus_type;
 	dev->parent = &span->span_device;
-	dev_set_name(dev, "dahdi!%d", chan->channo);
+	/*
+	 * WARNING: the name cannot be longer than KOBJ_NAME_LEN
+	 */
+	dev_set_name(dev, "dahdi!spans!%03d!%02d", span->spanno, chan->chanpos);
 	dev_set_drvdata(dev, chan);
 	dev->release = chan_release;
 	res = device_register(dev);
@@ -215,11 +219,10 @@
 				__func__, res);
 		return res;
 	}
-
-	return 0;
-}
-
-void chan_device_unregister(struct dahdi_chan *chan)
+	return 0;
+}
+
+void chan_sysfs_remove(struct dahdi_chan *chan)
 {
 	struct device	*dev = &chan->chan_device;
 
@@ -258,12 +261,24 @@
 	int	res;
 
 	dahdi_dbg(DEVICES, "SYSFS\n");
+	res = bus_register(&chan_bus_type);
+	if (res != 0) {
+		dahdi_err("%s: bus_register(%s) failed. Error number %d",
+			__func__, chan_bus_type.name, res);
+		goto failed_bus;
+	}
+	res = driver_register(&chan_driver);
+	if (res < 0) {
+		dahdi_err("%s: driver_register(%s) failed. Error number %d",
+			__func__, chan_driver.name, res);
+		goto failed_driver;
+	}
 	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;
+		goto failed_class;
 	}
 	res = alloc_chrdev_region(&dahdi_channels_devt, 0, DAHDI_MAX_CHANNELS,
 			"dahdi-channels");
@@ -271,17 +286,15 @@
 		dahdi_err("%s: Failed allocating chrdev for %d channels (%d)",
 			__func__, DAHDI_MAX_CHANNELS, res);
 		class_unregister(chan_class);
-		return res;
+		driver_unregister(&chan_driver);
+		goto failed_chrdev_region;
 	}
 	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;
+		goto failed_cdev_add;
 	}
 
 	/* NULL parent, NULL drvdata */
@@ -294,8 +307,18 @@
 			"dahdi!pseudo");
 	create_dev_file(chan_class, MKDEV(DAHDI_MAJOR, DAHDI_CTL),
 			"dahdi!ctl");
-	chan_class->dev_attrs = chan_dev_attrs;
-	return 0;
+	return 0;
+
+failed_cdev_add:
+	unregister_chrdev_region(dahdi_channels_devt, DAHDI_MAX_CHANNELS);
+failed_chrdev_region:
+	class_unregister(chan_class);
+failed_class:
+	driver_unregister(&chan_driver);
+failed_driver:
+	bus_unregister(&chan_bus_type);
+failed_bus:
+	return res;
 }
 //EXPORT_SYMBOL(dahdi_driver_chan_init);
 
@@ -309,5 +332,7 @@
 	cdev_del(&dahdi_channels_cdev);
 	unregister_chrdev_region(dahdi_channels_devt, DAHDI_MAX_CHANNELS);
 	class_unregister(chan_class);
-}
-EXPORT_SYMBOL(dahdi_driver_chan_exit);
+	driver_unregister(&chan_driver);
+	bus_unregister(&chan_bus_type);
+}
+//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=8595&r1=8594&r2=8595
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c Mon May  3 10:13:34 2010
@@ -33,38 +33,11 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/errno.h>
-#include <linux/proc_fs.h>
 #include <linux/workqueue.h>
 #include <linux/delay.h>	/* for msleep() to debug */
 #include <dahdi/kernel.h>
 #include "dahdi-sysfs.h"
 
-/*
- * Hotplug replaced with uevent in 2.6.16
- */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
-#define	OLD_HOTPLUG_SUPPORT	/* for older kernels */
-#endif
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
-#define	DEVICE_ATTR_READER(name, dev, buf)	\
-		ssize_t name(struct device *dev, \
-				struct device_attribute *attr, char *buf)
-#define	DEVICE_ATTR_WRITER(name, dev, buf, count)	\
-		ssize_t name(struct device *dev, \
-				struct device_attribute *attr, \
-				const char *buf, size_t count)
-#define BUS_ATTR_READER(name, dev, buf) \
-   ssize_t name(struct device *dev, struct device_attribute *attr, char *buf)
-#else
-#define	DEVICE_ATTR_READER(name, dev, buf)	\
-		ssize_t name(struct device *dev, char *buf)
-#define	DEVICE_ATTR_WRITER(name, dev, buf, count)	\
-		ssize_t name(struct device *dev, const char *buf, size_t count)
-#define BUS_ATTR_READER(name, dev, buf) \
-   ssize_t name(struct device *dev, char *buf)
-#endif
-
 static const char rcsid[] = "$Id$";
 
 /* Command line parameters */
@@ -73,6 +46,87 @@
 static char *initdir = "/usr/share/dahdi";
 module_param(initdir, charp, 0644);
 
+static int span_match(struct device *dev, struct device_driver *driver)
+{
+	dev_info(dev, "SYSFS MATCH: driver->name = %s\n", driver->name);
+	return 1;
+}
+
+#ifdef OLD_HOTPLUG_SUPPORT
+static int span_hotplug(struct device *dev, char **envp, int envnum,
+		char *buff, int bufsize)
+{
+	struct dahdi_span *span;
+
+	if (!dev)
+		return -ENODEV;
+	span = dev_to_span(dev);
+	envp[0] = buff;
+	if (snprintf(buff, bufsize, "SPAN_NAME=%s", span->name) >= bufsize)
+		return -ENOMEM;
+	envp[1] = NULL;
+	return 0;
+}
+#else
+
+#define	SPAN_VAR_BLOCK	\
+	do {		\
+		DAHDI_ADD_UEVENT_VAR("DAHDI_INIT_DIR=%s", initdir);	\
+		DAHDI_ADD_UEVENT_VAR("SPAN_NUM=%03d", span->spanno);	\
+		DAHDI_ADD_UEVENT_VAR("SPAN_NAME=%s", span->name);	\
+	} while (0)
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
+#define DAHDI_ADD_UEVENT_VAR(fmt, val...)			\
+	do {							\
+		int err = add_uevent_var(envp, num_envp, &i,	\
+				buffer, buffer_size, &len,	\
+				fmt, val);			\
+		if (err)					\
+			return err;				\
+	} while (0)
+
+static int span_uevent(struct device *dev, char **envp, int num_envp,
+		char *buffer, int buffer_size)
+{
+	struct dahdi_span	*span;
+	int			i = 0;
+	int			len = 0;
+
+	if (!dev)
+		return -ENODEV;
+	span = dev_to_span(dev);
+	dahdi_dbg(GENERAL, "SYFS dev_name=%s span=%s\n",
+			dev_name(dev), span->name);
+	SPAN_VAR_BLOCK;
+	envp[i] = NULL;
+	return 0;
+}
+
+#else
+#define DAHDI_ADD_UEVENT_VAR(fmt, val...)			\
+	do {							\
+		int err = add_uevent_var(kenv, fmt, val);	\
+		if (err)					\
+			return err;				\
+	} while (0)
+
+static int span_uevent(struct device *dev, struct kobj_uevent_env *kenv)
+{
+	struct dahdi_span *span;
+
+	if (!dev)
+		return -ENODEV;
+	span = dev_to_span(dev);
+	dahdi_dbg(GENERAL, "SYFS dev_name=%s span=%s\n",
+			dev_name(dev), span->name);
+	SPAN_VAR_BLOCK;
+	return 0;
+}
+
+#endif
+
+#endif	/* OLD_HOTPLUG_SUPPORT */
 
 #define span_attr(field, format_string)				\
 static BUS_ATTR_READER(field##_show, dev, buf)			\
@@ -140,82 +194,6 @@
 };
 
 
-#ifdef OLD_HOTPLUG_SUPPORT
-static int span_hotplug(struct device *dev, char **envp, int envnum,
-		char *buff, int bufsize)
-{
-	struct dahdi_span *span;
-
-	if (!dev)
-		return -ENODEV;
-	span = dev_to_span(dev);
-	envp[0] = buff;
-	if (snprintf(buff, bufsize, "SPAN_NAME=%s", span->name) >= bufsize)
-		return -ENOMEM;
-	envp[1] = NULL;
-	return 0;
-}
-#else
-
-#define	SPAN_VAR_BLOCK	\
-	do {		\
-		XBUS_ADD_UEVENT_VAR("DAHDI_INIT_DIR=%s", initdir);	\
-		XBUS_ADD_UEVENT_VAR("SPAN_NUM=%03d", span->spanno);	\
-		XBUS_ADD_UEVENT_VAR("SPAN_NAME=%s", span->name);	\
-	} while (0)
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
-#define XBUS_ADD_UEVENT_VAR(fmt, val...)			\
-	do {							\
-		int err = add_uevent_var(envp, num_envp, &i,	\
-				buffer, buffer_size, &len,	\
-				fmt, val);			\
-		if (err)					\
-			return err;				\
-	} while (0)
-
-static int span_uevent(struct device *dev, char **envp, int num_envp,
-		char *buffer, int buffer_size)
-{
-	struct dahdi_span *span;
-	int			i = 0;
-	int			len = 0;
-
-	if (!dev)
-		return -ENODEV;
-	span = dev_to_span(dev);
-	dahdi_dbg(GENERAL, "SYFS dev_name=%s span=%s\n",
-			dev_name(dev), span->name);
-	SPAN_VAR_BLOCK;
-	envp[i] = NULL;
-	return 0;
-}
-
-#else
-#define XBUS_ADD_UEVENT_VAR(fmt, val...)			\
-	do {							\
-		int err = add_uevent_var(kenv, fmt, val);	\
-		if (err)					\
-			return err;				\
-	} while (0)
-
-static int span_uevent(struct device *dev, struct kobj_uevent_env *kenv)
-{
-	struct dahdi_span *span;
-
-	if (!dev)
-		return -ENODEV;
-	span = dev_to_span(dev);
-	dahdi_dbg(GENERAL, "SYFS dev_name=%s span=%s\n",
-			dev_name(dev), span->name);
-	SPAN_VAR_BLOCK;
-	return 0;
-}
-
-#endif
-
-#endif	/* OLD_HOTPLUG_SUPPORT */
-
 #if 0
 void span_uevent_send(xbus_t *xbus, enum kobject_action act)
 {
@@ -246,6 +224,52 @@
 
 #endif
 
+static struct driver_attribute dahdi_attrs[] = {
+	__ATTR_NULL,
+};
+
+static struct bus_type spans_bus_type = {
+	.name           = "dahdi_spans",
+	.match          = span_match,
+#ifdef OLD_HOTPLUG_SUPPORT
+	.hotplug	= span_hotplug,
+#else
+	.uevent         = span_uevent,
+#endif
+	.dev_attrs	= span_dev_attrs,
+	.drv_attrs	= dahdi_attrs,
+};
+
+
+static int span_probe(struct device *dev)
+{
+	struct dahdi_span *span;
+
+	span = dev_to_span(dev);
+	dev_info(dev, "span %d\n", span->spanno);
+	return 0;
+}
+
+static int span_remove(struct device *dev)
+{
+	struct dahdi_span *span;
+
+	span = dev_to_span(dev);
+	dev_info(dev, "span %d\n", span->spanno);
+	return 0;
+}
+
+static struct device_driver dahdi_driver = {
+	.name		= "generic_lowlevel",
+	.bus		= &spans_bus_type,
+	.probe		= span_probe,
+	.remove		= span_remove,
+#ifndef OLD_HOTPLUG_SUPPORT
+	.owner		= THIS_MODULE
+#endif
+};
+
+
 static void span_uevent_send(struct dahdi_span *span, enum kobject_action act)
 {
 	struct kobject	*kobj;
@@ -275,21 +299,10 @@
 #endif
 }
 
-static void dahdi_release(struct device *dev)
-{
-	dahdi_dbg(DEVICES, "SYSFS %s\n", dev_name(dev));
-}
-
 static void span_release(struct device *dev)
 {
-}
-
-static struct class *span_class;
-
-static struct device toplevel_device = {
-	.release	= dahdi_release
-};
-
+	dahdi_dbg(DEVICES, "%s: %s\n", __func__, dev_name(dev));
+}
 
 void span_sysfs_remove(struct dahdi_span *span)
 {
@@ -302,7 +315,7 @@
 	BUG_ON(!span_device);
 	for (x = 0; x < span->channels; x++) {
 		struct dahdi_chan *chan = span->chans[x];
-		chan_device_unregister(chan);
+		chan_sysfs_remove(chan);
 	}
 	if (!dev_get_drvdata(span_device))
 		return;
@@ -310,7 +323,6 @@
 	span_uevent_send(span, KOBJ_OFFLINE);
 	device_unregister(&span->span_device);
 }
-EXPORT_SYMBOL(span_sysfs_remove);
 
 int span_sysfs_create(struct dahdi_span *span)
 {
@@ -323,7 +335,7 @@
 	BUG_ON(!span_device);
 	span_dbg(DEVICES, span, "\n");
 
-	span_device->class = span_class;
+	span_device->bus = &spans_bus_type;
 	span_device->parent = (span->parent_device)
 		? span->parent_device
 		: NULL;
@@ -339,7 +351,7 @@
 
 	for (x = 0; x < span->channels; x++) {
 		struct dahdi_chan *chan = span->chans[x];
-		res = chan_device_register(chan);
+		res = chan_sysfs_create(chan);
 		if (res) {
 			chan_err(chan, "Failed registering in sysfs: %d.\n",
 					res);
@@ -350,62 +362,50 @@
 	return res;
 
 err_chan_device_register:
-	for (; x >= 0; x--) {
+	for (--x; x >= 0; x--) {
 		struct dahdi_chan *chan = span->chans[x];
-		chan_device_unregister(chan);
+		chan_sysfs_remove(chan);
 	}
 	device_unregister(span_device);
 err_device_register:
 	dev_set_drvdata(span_device, NULL);
-	span_device->class = NULL;
 	span_device->parent = NULL;
 	return res;
 }
-EXPORT_SYMBOL(span_sysfs_create);
 
 int __init dahdi_driver_init(const struct file_operations *fops)
 {
 	int	res;
 
 	dahdi_dbg(DEVICES, "SYSFS\n");
-	span_class = class_create(THIS_MODULE, "dahdi_span");
-	if (IS_ERR(span_class)) {
-		res = PTR_ERR(span_class);
-		dahdi_err("%s: class_create(dahdi_span) failed. Error: %d\n",
-			__func__, res);
-		goto failed_class_create;
-	}
-#ifdef OLD_HOTPLUG_SUPPORT
-	span_class->hotplug = span_hotplug;
-#else
-	span_class->dev_uevent = span_uevent;
-#endif
-	span_class->dev_attrs = span_dev_attrs;
-	dev_set_name(&toplevel_device, "dahdi_top");
-	res = device_register(&toplevel_device);
+	res = bus_register(&spans_bus_type);
+	if (res != 0) {
+		dahdi_err("%s: bus_register(%s) failed. Error number %d",
+			__func__, spans_bus_type.name, res);
+		goto failed_bus;
+	}
+	res = driver_register(&dahdi_driver);
 	if (res < 0) {
-		dahdi_err("%s: device_register(%s) failed. Error number %d",
-			__func__, dev_name(&toplevel_device), res);
-		goto failed_busdevice;
+		dahdi_err("%s: driver_register(%s) failed. Error number %d",
+			__func__, dahdi_driver.name, res);
+		goto failed_driver;
 	}
 	res = dahdi_driver_chan_init(fops);
 	if (res < 0)
 		goto failed_chan_bus;
 	return 0;
 failed_chan_bus:
-	device_unregister(&toplevel_device);
-failed_busdevice:
-	class_destroy(span_class);
-failed_class_create:
+	driver_unregister(&dahdi_driver);
+failed_driver:
+	bus_unregister(&spans_bus_type);
+failed_bus:
 	return res;
 }
-//EXPORT_SYMBOL(dahdi_driver_init);
 
 void dahdi_driver_exit(void)
 {
 	dahdi_dbg(DEVICES, "SYSFS\n");
 	dahdi_driver_chan_exit();
-	device_unregister(&toplevel_device);
-	class_unregister(span_class);
-}
-EXPORT_SYMBOL(dahdi_driver_exit);
+	driver_unregister(&dahdi_driver);
+	bus_unregister(&spans_bus_type);
+}

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=8595&r1=8594&r2=8595
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.h (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.h Mon May  3 10:13:34 2010
@@ -1,3 +1,34 @@
+#ifndef	DAHDI_SYSFS_H
+#define	DAHDI_SYSFS_H
+
+/*
+ * Hotplug replaced with uevent in 2.6.16
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
+#define	OLD_HOTPLUG_SUPPORT	/* for older kernels */
+#endif
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
+#define	DEVICE_ATTR_READER(name, dev, buf)	\
+		ssize_t name(struct device *dev, struct device_attribute *attr,\
+				char *buf)
+#define	DEVICE_ATTR_WRITER(name, dev, buf, count)	\
+		ssize_t name(struct device *dev, struct device_attribute *attr,\
+				const char *buf, size_t count)
+#define BUS_ATTR_READER(name, dev, buf) \
+   ssize_t name(struct device *dev, struct device_attribute *attr, char *buf)
+#else
+#define	DEVICE_ATTR_READER(name, dev, buf)	\
+		ssize_t name(struct device *dev, char *buf)
+#define	DEVICE_ATTR_WRITER(name, dev, buf, count)	\
+		ssize_t name(struct device *dev, const char *buf, size_t count)
+#define BUS_ATTR_READER(name, dev, buf) \
+   ssize_t name(struct device *dev, char *buf)
+#endif
+
+#define	DRIVER_ATTR_READER(name, drv, buf)	\
+		ssize_t name(struct device_driver *drv, char * buf)
+
 /* Global */
 int __init dahdi_driver_init(const struct file_operations *fops);
 void dahdi_driver_exit(void);
@@ -9,5 +40,7 @@
 void span_sysfs_remove(struct dahdi_span *span);
 
 /* For use in dahdi-base only: */
-int chan_device_register(struct dahdi_chan *chan);
-void chan_device_unregister(struct dahdi_chan *chan);
+int chan_sysfs_create(struct dahdi_chan *chan);
+void chan_sysfs_remove(struct dahdi_chan *chan);
+
+#endif	/* DAHDI_SYSFS_H */

Modified: linux/team/tzafrir/sysfs/drivers/dahdi/xpp/xpp_dahdi.c
URL: http://svnview.digium.com/svn/dahdi/linux/team/tzafrir/sysfs/drivers/dahdi/xpp/xpp_dahdi.c?view=diff&rev=8595&r1=8594&r2=8595
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/xpp/xpp_dahdi.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/xpp/xpp_dahdi.c Mon May  3 10:13:34 2010
@@ -1114,10 +1114,10 @@
 		xpd->type_name);
 	/* The location is: <Connector>!<XPD-Number> */
 	snprintf(span->location, sizeof(span->location) - 1, "%s!%d%d",
-			xbus->connector, xpd->addr.unit,
-			xpd->addr.subunit); 
-	snprintf(span->hardware_id, sizeof(span->hardware_id) - 1, "%s",
-		xbus->label);
+			xbus->connector, xpd->addr.unit, xpd->addr.subunit);
+	/* The hardware_id is: <Label>!<XPD-Number> */
+	snprintf(span->hardware_id, sizeof(span->hardware_id) - 1, "%s!%d%d",
+			xbus->label, xpd->addr.unit, xpd->addr.subunit);
 	span->hardware_port = xpd->addr.unit * 10 + xpd->addr.subunit;
 	/*
 	 * Who said a span and irq have 1-1 relationship?




More information about the svn-commits mailing list