[svn-commits] tzafrir: branch linux/tzafrir/sysfs r8366 - in /linux/team/tzafrir/sysfs: dri...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Sun Mar 21 15:02:14 CDT 2010
Author: tzafrir
Date: Sun Mar 21 15:02:10 2010
New Revision: 8366
URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8366
Log:
SysFS chan objects create /dev/dahdi/N. For any N
* Rather than use Major number 196 and minor number N for /dev/dahdi/N,
allocate a range of major/minors for each span.
- Thus we are not limited by up to 249 devices.
- And no holes.
* Instead of dummy devices, use our existing SysFS objects of channels.
- Sadly they have to be named 'dahdi!N' .
This now provides basic infrastructure for dialing by channel name at
the DAHDI kernel level.
Modified:
linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c
linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c
linux/team/tzafrir/sysfs/include/dahdi/kernel.h
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=8366&r1=8365&r2=8366
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs-chan.c Sun Mar 21 15:02:10 2010
@@ -70,11 +70,10 @@
* 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__);
+ device_create(class, NULL, devnum, NULL, name, ## __VA_ARGS__)
#define destroy_dev_file(class, devnum) \
- device_destroy(class, MKDEV(DAHDI_MAJOR, devnum));
+ device_destroy(class, devnum)
/*
* Hotplug replaced with uevent in 2.6.16
@@ -120,6 +119,7 @@
chan_attr(name, "%s\n");
chan_attr(channo, "%d\n");
+chan_attr(chanpos, "%d\n");
chan_attr(sig, "0x%x\n");
chan_attr(sigcap, "0x%x\n");
chan_attr(chan_alarms, "%d\n");
@@ -131,6 +131,7 @@
static struct device_attribute chan_dev_attrs[] = {
__ATTR_RO(name),
__ATTR_RO(channo),
+ __ATTR_RO(chanpos),
__ATTR_RO(sig),
__ATTR_RO(sigcap),
__ATTR_RO(chan_alarms),
@@ -164,15 +165,18 @@
struct device *dev = &chan->chan_device;
struct dahdi_span *span;
int res;
+ dev_t devt;
BUG_ON(!chan);
span = chan->span;
BUG_ON(!span);
+ devt = span->first_devt + chan->chanpos - 1;
chan_dbg(DEVICES, chan, "SYSFS\n");
dev = &chan->chan_device;
+ dev->devt = devt;
dev->class = chan_class;
dev->parent = &span->span_device;
- dev_set_name(dev, "%03d:%02d", span->spanno, chan->chanpos);
+ dev_set_name(dev, "dahdi!%d", chan->channo);
dev_set_drvdata(dev, chan);
dev->release = chan_release;
res = device_register(dev);
@@ -181,9 +185,6 @@
__func__, res);
return res;
}
- if (chan->channo < 250)
- create_dev_file(chan_class, chan->channo, "dahdi!%d",
- chan->channo);
return 0;
}
@@ -194,8 +195,6 @@
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;
@@ -209,14 +208,15 @@
int dahdi_register_chardev(struct dahdi_chardev *dev)
{
/* FIXME: Error handling */
- create_dev_file(chan_class, dev->minor, "dahdi!%s", dev->name);
+ create_dev_file(chan_class, MKDEV(DAHDI_MAJOR, 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);
+ destroy_dev_file(chan_class, MKDEV(DAHDI_MAJOR, dev->minor));
return 0;
}
EXPORT_SYMBOL(dahdi_unregister_chardev);
@@ -236,10 +236,10 @@
}
/* 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");
+ create_dev_file(chan_class, MKDEV(DAHDI_MAJOR, 253), "dahdi!timer");
+ create_dev_file(chan_class, MKDEV(DAHDI_MAJOR, 254), "dahdi!channel");
+ create_dev_file(chan_class, MKDEV(DAHDI_MAJOR, 255), "dahdi!pseudo");
+ create_dev_file(chan_class, MKDEV(DAHDI_MAJOR, 0), "dahdi!ctl");
chan_class->dev_attrs = chan_dev_attrs;
return 0;
}
@@ -248,10 +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);
+ destroy_dev_file(chan_class, MKDEV(DAHDI_MAJOR, 0));
+ destroy_dev_file(chan_class, MKDEV(DAHDI_MAJOR, 255));
+ destroy_dev_file(chan_class, MKDEV(DAHDI_MAJOR, 254));
+ destroy_dev_file(chan_class, MKDEV(DAHDI_MAJOR, 253));
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=8366&r1=8365&r2=8366
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c Sun Mar 21 15:02:10 2010
@@ -300,6 +300,8 @@
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);
@@ -313,6 +315,7 @@
struct device *span_device;
int res = 0;
int x;
+ int first_devt = 0;
BUG_ON(!span);
span_device = &span->span_device;
@@ -331,28 +334,41 @@
if (res) {
span_err(span, "%s: device_register failed: %d\n", __func__,
res);
- dev_set_drvdata(span_device, NULL);
- return res;
- }
- if (res)
- goto err_span_attr;
-
+ 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);
if (res) {
chan_err(chan, "Failed registering in sysfs: %d.\n",
res);
- chan_err(chan, "And sadly no error handling yet.\n");
+ goto err_chan_device_register;
return res;
}
}
span_uevent_send(span, KOBJ_ONLINE);
return res;
-err_span_attr:
- if (span_device && dev_get_drvdata(span_device))
- device_unregister(span_device);
+err_chan_device_register:
+ for (; x >= 0; x--) {
+ 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);
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=8366&r1=8365&r2=8366
==============================================================================
--- linux/team/tzafrir/sysfs/include/dahdi/kernel.h (original)
+++ linux/team/tzafrir/sysfs/include/dahdi/kernel.h Sun Mar 21 15:02:10 2010
@@ -863,6 +863,7 @@
*/
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