[svn-commits] tzafrir: branch linux/tzafrir/sysfs r5445 - in /linux/team/tzafrir/sysfs: dri...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Sat Dec 6 16:41:32 CST 2008
Author: tzafrir
Date: Sat Dec 6 16:41:31 2008
New Revision: 5445
URL: http://svn.digium.com/view/dahdi?view=rev&rev=5445
Log:
Add support for driver-specific span attributes.
* wcfxo inclues two sample attributes.
* Slightly better error handling at registration.
* More renaming cleanups.
Modified:
linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c
linux/team/tzafrir/sysfs/drivers/dahdi/wcfxo.c
linux/team/tzafrir/sysfs/include/dahdi/kernel.h
Modified: linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c
URL: http://svn.digium.com/view/dahdi/linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c?view=diff&rev=5445&r1=5444&r2=5445
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/dahdi-sysfs.c Sat Dec 6 16:41:31 2008
@@ -25,8 +25,6 @@
# warning "This module is tested only with 2.6 kernels"
#endif
-#define dev_to_span(dev) container_of(dev, struct dahdi_span, span_device)
-#define dev_to_chan(dev) container_of(dev, struct dahdi_chan, chan_device)
#include <linux/kernel.h>
#include <linux/module.h>
@@ -68,7 +66,7 @@
#define PRINTK(level, category, fmt, ...) \
printk(KERN_ ## level "%s%s-%s: " fmt, #level, category, THIS_MODULE->name, ## __VA_ARGS__)
#define SPAN_PRINTK(level, category, span, fmt, ...) \
- printk(KERN_ ## level "%s%s-%s: %d: " fmt, #level, \
+ printk(KERN_ ## level "%s%s-%s: span-%d: " fmt, #level, \
category, THIS_MODULE->name, (span)->spanno, ## __VA_ARGS__)
#define CHAN_PRINTK(level, category, chan, fmt, ...) \
printk(KERN_ ## level "%s%s-%s: %d: " fmt, #level, \
@@ -228,7 +226,7 @@
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
-#define xbus_attr(field, format_string) \
+#define span_attr(field, format_string) \
static ssize_t \
field##_show(struct device *dev, struct device_attribute *attr, char *buf) \
{ \
@@ -238,7 +236,7 @@
return sprintf (buf, format_string, span->field); \
}
#else
-#define xbus_attr(field, format_string) \
+#define span_attr(field, format_string) \
static ssize_t \
field##_show(struct device *dev, char *buf) \
{ \
@@ -249,12 +247,12 @@
}
#endif
-xbus_attr(name, "%s\n");
-xbus_attr(desc, "%s\n");
-xbus_attr(spantype, "%s\n");
-xbus_attr(manufacturer, "%s\n");
-xbus_attr(devicetype, "%s\n");
-xbus_attr(location, "%s\n");
+span_attr(name, "%s\n");
+span_attr(desc, "%s\n");
+span_attr(spantype, "%s\n");
+span_attr(manufacturer, "%s\n");
+span_attr(devicetype, "%s\n");
+span_attr(location, "%s\n");
static struct device_attribute span_dev_attrs[] = {
__ATTR_RO(name),
@@ -678,6 +676,48 @@
/*--------- Sysfs Device handling ----*/
+/* Register the dev_attrs of the span in sysfs as extra attributes
+ to the device
+
+ FIXME: Both this and the following function use internal fields
+ of struct device_attribute (.attr.name).
+*/
+int reg_custom_span_attr(struct dahdi_span *span) {
+ struct device *device = &span->span_device;
+ struct device_attribute *dev_attrs = span->dev_attrs;
+ int res = 0;
+ int i;
+
+ if (!dev_attrs)
+ return 0;
+
+ for (i = 0; dev_attrs[i].attr.name != NULL; i++) {
+ res = device_create_file(device, &dev_attrs[i]);
+ if (res) {
+ SPAN_ERR(span, "Failed registering attribute %s: %d\n",
+ dev_attrs[i].attr.name, res);
+ for (i--; i>=0; i--)
+ device_remove_file(device, &dev_attrs[i]);
+ return res;
+ }
+ }
+
+ return res;
+}
+
+void unreg_custom_span_attr(struct dahdi_span *span)
+{
+ struct device *device = &span->span_device;
+ struct device_attribute *dev_attrs = span->dev_attrs;
+ int i;
+
+ if (!dev_attrs)
+ return;
+
+ for (i = 0; dev_attrs[i].attr.name != NULL; i++)
+ device_remove_file(device, &dev_attrs[i]);
+}
+
void span_sysfs_remove(struct dahdi_span *span)
{
struct device *span_device;
@@ -685,12 +725,13 @@
BUG_ON(!span);
SPAN_DBG(DEVICES, span, "\n");
+ span_device = &span->span_device;
+ BUG_ON(!span_device);
for (x = 0; x < span->channels; x++) {
struct dahdi_chan *chan = span->chans[x];
chan_device_unregister(chan);
}
- span_device = &span->span_device;
- BUG_ON(!span_device);
+ unreg_custom_span_attr(span);
if(!span_device->driver_data)
return;
BUG_ON(span_device->driver_data != span);
@@ -719,6 +760,9 @@
span_device->driver_data = NULL;
return res;
}
+ res = reg_custom_span_attr(span);
+ if (res)
+ goto err_span_attr;
for (x = 0; x < span->channels; x++) {
struct dahdi_chan *chan = span->chans[x];
@@ -731,6 +775,11 @@
}
}
return res;
+
+err_span_attr:
+ if (span_device && span_device->driver_data)
+ device_unregister(span_device);
+ return res;
}
EXPORT_SYMBOL(span_sysfs_create);
Modified: linux/team/tzafrir/sysfs/drivers/dahdi/wcfxo.c
URL: http://svn.digium.com/view/dahdi/linux/team/tzafrir/sysfs/drivers/dahdi/wcfxo.c?view=diff&rev=5445&r1=5444&r2=5445
==============================================================================
--- linux/team/tzafrir/sysfs/drivers/dahdi/wcfxo.c (original)
+++ linux/team/tzafrir/sysfs/drivers/dahdi/wcfxo.c Sat Dec 6 16:41:31 2008
@@ -240,6 +240,44 @@
Greece, Iceland, Ireland, Italy, Luxembourg, Netherlands,
Norway, Portugal, Spain, Sweden, Switzerland, and UK */
};
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
+#define fxo_pvt_attr(field, format_string) \
+static ssize_t \
+field##_show(struct device *dev, struct device_attribute *attr, char *buf) \
+{ \
+ struct dahdi_span *span; \
+ struct wcfxo *pvt; \
+ \
+ span = dev_to_span(dev); \
+ pvt = (struct wcfxo*)(span->pvt); \
+ return sprintf(buf, format_string, pvt->field); \
+}
+
+#else
+#define span_attr(field, format_string) \
+static ssize_t \
+field##_show(struct device *dev, char *buf) \
+{ \
+ struct dahdi_span *span; \
+ struct wcfxo *pvt; \
+ \
+ span = dev_to_span(dev); \
+ pvt = (struct wcfxo*)(span->pvt); \
+ return sprintf(buf, format_string, pvt->field); \
+}
+#endif
+
+/* A number of sample attributes */
+fxo_pvt_attr(offhook, "%d\n");
+fxo_pvt_attr(battery, "%d\n");
+
+static struct device_attribute span_dev_attrs[] = {
+ __ATTR_RO(battery),
+ __ATTR_RO(offhook),
+ __ATTR_NULL,
+};
+
static inline void wcfxo_transmitprep(struct wcfxo *wc, unsigned char ints)
{
@@ -654,6 +692,7 @@
wc->span.flags = DAHDI_FLAG_RBS;
wc->span.deflaw = DAHDI_LAW_MULAW;
wc->span.watchdog = wcfxo_watchdog;
+ wc->span.dev_attrs = span_dev_attrs;
#ifdef ENABLE_TASKLETS
tasklet_init(&wc->wcfxo_tlet, wcfxo_tasklet, (unsigned long)wc);
#endif
Modified: linux/team/tzafrir/sysfs/include/dahdi/kernel.h
URL: http://svn.digium.com/view/dahdi/linux/team/tzafrir/sysfs/include/dahdi/kernel.h?view=diff&rev=5445&r1=5444&r2=5445
==============================================================================
--- linux/team/tzafrir/sysfs/include/dahdi/kernel.h (original)
+++ linux/team/tzafrir/sysfs/include/dahdi/kernel.h Sat Dec 6 16:41:31 2008
@@ -335,6 +335,7 @@
unsigned char *lin2x;
#endif
struct device chan_device; /*!< Kernel object for this span (TODO: rename) */
+#define dev_to_chan(dev) container_of(dev, struct dahdi_chan, chan_device)
};
#ifdef CONFIG_DAHDI_NET
@@ -555,6 +556,8 @@
/*! Opt: Enable maintenance modes */
int (*maint)(struct dahdi_span *span, int mode);
+ /*! Opt: NULL-terminated Array of custom sysfs device attributes */
+ struct device_attribute * dev_attrs;
#ifdef DAHDI_SYNC_TICK
/*! Opt: send sync to spans */
int (*sync_tick)(struct dahdi_span *span, int is_master);
@@ -606,6 +609,7 @@
/* Used by DAHDI only -- no user servicable parts inside */
struct device span_device; /*!< Kernel object for this span (TODO: rename) */
+#define dev_to_span(dev) container_of(dev, struct dahdi_span, span_device)
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