[zaptel-commits] tzafrir: branch tzafrir/sysfs r3181 - /team/tzafrir/sysfs/
SVN commits to the Zaptel project
zaptel-commits at lists.digium.com
Sat Oct 20 21:45:38 CDT 2007
Author: tzafrir
Date: Sat Oct 20 21:45:38 2007
New Revision: 3181
URL: http://svn.digium.com/view/zaptel?view=rev&rev=3181
Log:
* sysfs now also has channels (under the spans).
* We probably need a different driver for channels, though.
* Remove some more xpd remains.
* But do include attribution.
Modified:
team/tzafrir/sysfs/zap_dbg.h
team/tzafrir/sysfs/zaptel-base.c
team/tzafrir/sysfs/zaptel-sysfs.c
team/tzafrir/sysfs/zaptel-sysfs.h
team/tzafrir/sysfs/zaptel.h
Modified: team/tzafrir/sysfs/zap_dbg.h
URL: http://svn.digium.com/view/zaptel/team/tzafrir/sysfs/zap_dbg.h?view=diff&rev=3181&r1=3180&r2=3181
==============================================================================
--- team/tzafrir/sysfs/zap_dbg.h (original)
+++ team/tzafrir/sysfs/zap_dbg.h Sat Oct 20 21:45:38 2007
@@ -33,7 +33,7 @@
#define zap_printk_chan(level, chan, fmt, ...) \
printk(KERN_ ## level "%s-%s: %s/%s: " fmt, #level, \
- THIS_MODULE->name, (chan)->span->name, (xpd)->xpdname, ## __VA_ARGS__)
+ THIS_MODULE->name, (chan)->span->name, (chan)->name, ## __VA_ARGS__)
#define zap_dbg(fmt, ...) \
((void)((debug) && zap_printk(DEBUG, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__)))
@@ -48,7 +48,7 @@
#define zap_notice_span(span, fmt, ...) zap_printk_span(NOTICE, span, fmt, ## __VA_ARGS__)
#define zap_err_span(span, fmt, ...) zap_printk_span(ERR, span, fmt, ## __VA_ARGS__)
-#define zap_dbg_chan(xpd, fmt, ...) \
+#define zap_dbg_chan(chan, fmt, ...) \
((void)((debug) && zap_printk_chan(DEBUG, chan, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__)))
#define zap_info_chan(chan, fmt, ...) zap_printk_chan(INFO, chan, fmt, ## __VA_ARGS__)
#define zap_notice_chan(chan, fmt, ...) zap_printk_chan(NOTICE, chan, fmt, ## __VA_ARGS__)
Modified: team/tzafrir/sysfs/zaptel-base.c
URL: http://svn.digium.com/view/zaptel/team/tzafrir/sysfs/zaptel-base.c?view=diff&rev=3181&r1=3180&r2=3181
==============================================================================
--- team/tzafrir/sysfs/zaptel-base.c (original)
+++ team/tzafrir/sysfs/zaptel-base.c Sat Oct 20 21:45:38 2007
@@ -4724,10 +4724,16 @@
#endif
#ifdef ZAP_DEVICE_MODEL
/* Device-Model */
+
+ zap_dbg_span(span, "Registering device nodes in sysfs.\n");
if((ret = span_sysfs_create(span)) < 0) {
zap_err_span(span, "%s: span_sysfs_create() failed: %d\n", __FUNCTION__, ret);
goto err;
}
+ /* FIXME: error handling */
+ for (x=0;x<span->channels;x++)
+ chan_sysfs_create(&span->chans[x]);
+ span_sysfs_create_done(span);
#endif /* ZAP_DEVICE_MODEL */
#ifdef CONFIG_DEVFS_FS
@@ -4804,6 +4810,10 @@
proc_entries[span->spanno] = NULL;
#endif /* CONFIG_PROC_FS */
#ifdef ZAP_DEVICE_MODEL
+ if (span->channels > 0)
+ zap_info_span(span, "Removing sysfs channels for span.\n");
+ for (x = 0; x < span->channels; x++)
+ chan_sysfs_remove(&span->chans[x]);
zap_info_span(span, "Removing sysfs for span.\n");
span_sysfs_remove(span);
#endif /* ZAP_DEVICE_MODEL */
Modified: team/tzafrir/sysfs/zaptel-sysfs.c
URL: http://svn.digium.com/view/zaptel/team/tzafrir/sysfs/zaptel-sysfs.c?view=diff&rev=3181&r1=3180&r2=3181
==============================================================================
--- team/tzafrir/sysfs/zaptel-sysfs.c (original)
+++ team/tzafrir/sysfs/zaptel-sysfs.c Sat Oct 20 21:45:38 2007
@@ -1,5 +1,6 @@
/*
* Written by Tzafrir Cohen <tzafrir.cohen at xorcom.com>
+ * Based on xpp-sysfs.c by Oron Peled <oron at actcom.co.il>
* Copyright (C) 2007, Xorcom
*
* All rights reserved.
@@ -41,7 +42,7 @@
#include "zaptel-sysfs.h"
#include "zaptel-base.h"
-static const char rcsid[] = "$Id";
+static const char rcsid[] = "$Id$";
/* Kernel versions... */
/*
@@ -75,7 +76,7 @@
return -ENODEV;
span = dev_to_span(dev);
envp[0] = buff;
- if(snprintf(buff, bufsize, "XBUS_NAME=%s", span->name) >= bufsize)
+ if(snprintf(buff, bufsize, "SPAN_NAME=%s", span->name) >= bufsize)
return -ENOMEM;
envp[1] = NULL;
return 0;
@@ -242,7 +243,6 @@
BUG_ON(!span);
zap_dbg_span(span, "\n");
device = &span->device;
- BUG_ON(!device);
device_remove_file(&span->device, &dev_attr_digital_coding);
device_remove_file(&span->device, &dev_attr_digital_framing);
device_remove_file(&span->device, &dev_attr_flags);
@@ -264,7 +264,6 @@
BUG_ON(!span);
device = &span->device;
- BUG_ON(!device);
zap_dbg_span(span, "\n");
device_initialize(device);
device->bus = &zap_bus_type;
@@ -285,9 +284,87 @@
out:
return ret;
}
-/*
- * End device Model Stuff
- *
- ****************************************************/
-
-
+
+/* Send a uevent to userspace to inform that span generation is complete.
+ * FIXME: to be implemented.
+ */
+void span_sysfs_create_done(struct zt_span *span)
+{
+ BUG_ON(!span);
+ zap_dbg_span(span, "\n");
+}
+
+
+#define CHAN_ATTR_SIMPLE(name, format) \
+ static DEVICE_ATTR_FUNC(chan_show_##name, dev, buf) \
+ { \
+ struct zt_chan *chan = dev_to_chan(dev); \
+ return snprintf(buf, PAGE_SIZE, format, chan->name); \
+ } \
+ static DEVICE_ATTR(chan_##name, S_IRUGO, chan_show_##name, NULL);
+
+CHAN_ATTR_SIMPLE(chanpos, "%d\n");
+CHAN_ATTR_SIMPLE(echocancel, "%d\n");
+CHAN_ATTR_SIMPLE(name, "%s\n");
+CHAN_ATTR_SIMPLE(sig, "%X\n");
+CHAN_ATTR_SIMPLE(sigcap, "%X\n");
+CHAN_ATTR_SIMPLE(tonezone, "%d\n");
+
+void chan_sysfs_remove(struct zt_chan *chan)
+{
+ struct device *device;
+
+ BUG_ON(!chan);
+ zap_dbg_chan(chan, "\n");
+ device = &chan->device;
+ device_remove_file(&chan->device, &dev_attr_chan_chanpos);
+ device_remove_file(&chan->device, &dev_attr_chan_echocancel);
+ device_remove_file(&chan->device, &dev_attr_chan_name);
+ device_remove_file(&chan->device, &dev_attr_chan_sig);
+ device_remove_file(&chan->device, &dev_attr_chan_sigcap);
+ device_remove_file(&chan->device, &dev_attr_chan_tonezone);
+ device_unregister(&chan->device);
+}
+
+#define chan_add_attribute(name) \
+ ret = device_create_file(device, &dev_attr_chan_##name); \
+ if(ret) { \
+ zap_err_chan(chan, "%s: device_create_file failed (flags): %d\n", \
+ __FUNCTION__, ret); \
+ goto out; \
+ }
+int chan_sysfs_create(struct zt_chan *chan)
+{
+ struct device *device;
+ struct zt_span *span;
+ int ret = 0;
+
+ BUG_ON(!chan);
+ span = chan->span;
+ BUG_ON(!span);
+ device = &chan->device;
+ zap_dbg_chan(chan, "\n");
+ device_initialize(device);
+ device->bus = &zap_bus_type;
+ device->parent = &span->device;
+ snprintf(device->bus_id, BUS_ID_SIZE, "chan-%02d-%02d",
+ span->spanno, chan->chanpos);
+ device->driver_data = NULL; /* FIXME: add some usefull data */
+ device->release = zap_dev_release;
+ ret = device_register(device);
+ if(ret) {
+ zap_err_chan(chan, "%s: device_add failed: %d\n",
+ __FUNCTION__, ret);
+ goto out;
+ }
+ chan_add_attribute(chanpos);
+ chan_add_attribute(echocancel);
+ chan_add_attribute(name);
+ chan_add_attribute(sig);
+ chan_add_attribute(sigcap);
+ chan_add_attribute(tonezone);
+out:
+ return ret;
+}
+
+
Modified: team/tzafrir/sysfs/zaptel-sysfs.h
URL: http://svn.digium.com/view/zaptel/team/tzafrir/sysfs/zaptel-sysfs.h?view=diff&rev=3181&r1=3180&r2=3181
==============================================================================
--- team/tzafrir/sysfs/zaptel-sysfs.h (original)
+++ team/tzafrir/sysfs/zaptel-sysfs.h Sat Oct 20 21:45:38 2007
@@ -1,8 +1,16 @@
#ifndef _ZAPTEL_SYSFS_H
-int span_sysfs_create(struct zt_span *span);
-void span_sysfs_remove(struct zt_span *span);
+/* global bus registration/deregistration */
int register_zap_bus(void);
void unregister_zap_bus(void);
+/* span registration / unregistration */
+int span_sysfs_create(struct zt_span *span);
+void span_sysfs_create_done(struct zt_span *span);
+void span_sysfs_remove(struct zt_span *span);
+
+/* The channel device is a child of the span device: */
+int chan_sysfs_create(struct zt_chan *chan);
+void chan_sysfs_remove(struct zt_chan *chan);
+
#endif /* _ZAPTEL_SYSFS_H */
Modified: team/tzafrir/sysfs/zaptel.h
URL: http://svn.digium.com/view/zaptel/team/tzafrir/sysfs/zaptel.h?view=diff&rev=3181&r1=3180&r2=3181
==============================================================================
--- team/tzafrir/sysfs/zaptel.h (original)
+++ team/tzafrir/sysfs/zaptel.h Sat Oct 20 21:45:38 2007
@@ -1342,6 +1342,10 @@
devfs_handle_t fhandle; /* File handle in devfs for the channel */
devfs_handle_t fhandle_symlink;
#endif /* CONFIG_DEVFS_FS */
+#ifdef LINUX26
+ struct device device; /* Device model object. For e.g. sysfs */
+#define dev_to_chan(dev) container_of(dev, struct zt_chan, device)
+#endif
};
/* defines for transmit signalling */
More information about the zaptel-commits
mailing list