[zaptel-commits] tzafrir: branch tzafrir/sysfs r3150 - /team/tzafrir/sysfs/
SVN commits to the Zaptel project
zaptel-commits at lists.digium.com
Wed Oct 17 04:52:14 CDT 2007
Author: tzafrir
Date: Wed Oct 17 04:52:12 2007
New Revision: 3150
URL: http://svn.digium.com/view/zaptel?view=rev&rev=3150
Log:
Move new sysfs stuff to a separate source file. a 220kb source file is
no fun.
Modified:
team/tzafrir/sysfs/Makefile.kernel26
team/tzafrir/sysfs/zaptel-base.c
Modified: team/tzafrir/sysfs/Makefile.kernel26
URL: http://svn.digium.com/view/zaptel/team/tzafrir/sysfs/Makefile.kernel26?view=diff&rev=3150&r1=3149&r2=3150
==============================================================================
--- team/tzafrir/sysfs/Makefile.kernel26 (original)
+++ team/tzafrir/sysfs/Makefile.kernel26 Wed Oct 17 04:52:12 2007
@@ -12,7 +12,7 @@
EXTRA_CFLAGS+=-Drw_lock_t=rwlock_t
endif
-zaptel-objs := zaptel-base.o
+zaptel-objs := zaptel-base.o zaptel-sysfs.o
ifeq ($(HPEC_PRESENT),yes)
ifeq ($(ARCH),i386)
Modified: team/tzafrir/sysfs/zaptel-base.c
URL: http://svn.digium.com/view/zaptel/team/tzafrir/sysfs/zaptel-base.c?view=diff&rev=3150&r1=3149&r2=3150
==============================================================================
--- team/tzafrir/sysfs/zaptel-base.c (original)
+++ team/tzafrir/sysfs/zaptel-base.c Wed Oct 17 04:52:12 2007
@@ -82,12 +82,14 @@
#ifdef STANDALONE_ZAPATA
#include "zaptel.h"
#include "zap_dbg.h"
+#include "zaptel-base.h"
#else
#include <zaptel/zaptel.h>
#endif
#ifdef LINUX26
#include <linux/moduleparam.h>
+#include "zaptel-sysfs.h"
#endif
/* Get helper arithmetic */
@@ -230,7 +232,7 @@
};
#endif
-static int debug;
+int debug;
/* states for transmit signalling */
typedef enum {ZT_TXSTATE_ONHOOK,ZT_TXSTATE_OFFHOOK,ZT_TXSTATE_START,
@@ -254,7 +256,7 @@
static sumtype *conf_sums;
static sumtype *conf_sums_prev;
-static struct zt_span *master;
+struct zt_span *master;
static struct file_operations zt_fops;
struct file_operations *zt_transcode_fops = NULL;
@@ -638,270 +640,6 @@
return len;
}
#endif
-
-/****************************************************
- *
- * Device Model Stuff
- *
- */
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
-# warning "This module is tested only with 2.6 kernels"
-#endif
-
-#include <linux/device.h>
-#include "zap_dbg.h"
-
-
-/* Kernel versions... */
-/*
- * Hotplug replaced with uevent in 2.6.16
- */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
-#define OLD_HOPLUG_SUPPORT // for older kernels
-#endif
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
-#define DEVICE_ATTR_FUNC(name,dev,buf) \
- ssize_t name(struct device *dev, struct device_attribute *attr, char *buf)
-#else
-#define DEVICE_ATTR_FUNC(name,dev,buf) \
- ssize_t name(struct device *dev, char *buf)
-#endif
-
-#ifdef ZAP_DEVICE_MODEL
-
-/* Always match, because the zaptel core handles all devices. */
-static int zap_bus_match(struct device *dev, struct device_driver *driver)
-{
- zap_dbg("dev->bus_id = %s, driver->name = %s\n", dev->bus_id, driver->name);
- return 1;
-}
-
-#ifdef OLD_HOPLUG_SUPPORT
-static int zap_bus_hotplug(struct device *dev, char **envp, int envnum, char *buff, int bufsize)
-{
- struct zt_span *span;
-
- if(!dev)
- return -ENODEV;
- span = dev_to_span(dev);
- envp[0] = buff;
- if(snprintf(buff, bufsize, "XBUS_NAME=%s", span->name) >= bufsize)
- return -ENOMEM;
- envp[1] = NULL;
- return 0;
-}
-#else
-
-#define SPAN_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 zap_bus_uevent(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
-{
- struct zt_span *span;
- int i = 0;
- int len = 0;
-
- if(!dev)
- return -ENODEV;
- span = dev_to_span(dev);
- zap_dbg("bus_id=%s span=%s\n", dev->bus_id, span->name);
- SPAN_ADD_UEVENT_VAR("SPAN_NUM=%02d", span->spanno);
- SPAN_ADD_UEVENT_VAR("SPAN_NAME=%s", span->name);
- envp[i] = NULL;
- return 0;
-}
-#endif
-
-static void zap_bus_release(struct device *dev)
-{
- zap_dbg("\n");
-}
-
-static void zap_dev_release(struct device *dev)
-{
- struct zt_span *span;
-
- BUG_ON(!dev);
- span = dev_to_span(dev);
- zap_dbg_span(span, "\n");
-}
-
-static struct bus_type zap_bus_type = {
- .name = "zaptel",
- .match = zap_bus_match,
-#ifdef OLD_HOPLUG_SUPPORT
- .hotplug = zap_bus_hotplug,
-#else
- .uevent = zap_bus_uevent,
-#endif
-};
-
-static struct device zap_bus = {
- .bus_id = "zapbus",
- .release = zap_bus_release
-};
-
-static struct device_driver zap_driver = {
- .name = "zapdrv",
- .bus = &zap_bus_type,
-#ifndef OLD_HOPLUG_SUPPORT
- .owner = THIS_MODULE
-#endif
-};
-
-static int register_zap_bus(void)
-{
- int ret;
-
- if((ret = bus_register(&zap_bus_type)) < 0) {
- zap_err("%s: bus_register failed. Error number %d", __FUNCTION__, ret);
- goto failed_bus;
- }
- if((ret = device_register(&zap_bus)) < 0) {
- zap_err("%s: registration of zap_bus failed. Error number %d",
- __FUNCTION__, ret);
- goto failed_busdevice;
- }
- if((ret = driver_register(&zap_driver)) < 0) {
- zap_err("%s: driver_register failed. Error number %d", __FUNCTION__, ret);
- goto failed_driver;
- }
- return 0;
-failed_driver:
- device_unregister(&zap_bus);
-failed_busdevice:
- bus_unregister(&zap_bus_type);
-failed_bus:
- return ret;
-}
-
-static void unregister_zap_bus(void)
-{
- driver_unregister(&zap_driver);
- device_unregister(&zap_bus);
- bus_unregister(&zap_bus_type);
-}
-
-/*--------- Sysfs Device handling ----*/
-static DEVICE_ATTR_FUNC(digital_coding_show, dev, buf)
-{
- struct zt_span *span = dev_to_span(dev);
- int lineconfig = span->lineconfig;
- char* name;
-
- lineconfig &= ~(ZT_CONFIG_AMI | ZT_CONFIG_B8ZS | ZT_CONFIG_HDB3 );
- switch (lineconfig) {
- case ZT_CONFIG_AMI: name="ami"; break;
- case ZT_CONFIG_B8ZS: name="b8zf"; break;
- case ZT_CONFIG_HDB3: name="hdb3"; break;
- default: name="unknown"; break;
- }
- return snprintf(buf, PAGE_SIZE, "%s\n", name);
-}
-static DEVICE_ATTR(digital_coding, S_IRUGO, digital_coding_show, NULL);
-
-static DEVICE_ATTR_FUNC(digital_framing_show, dev, buf)
-{
- struct zt_span *span = dev_to_span(dev);
- int lineconfig = span->lineconfig;
- char* name;
-
- lineconfig &= ~(ZT_CONFIG_D4 | ZT_CONFIG_ESF | ZT_CONFIG_CCS);
- switch (lineconfig) {
- case 0: name="cas"; break;
- case ZT_CONFIG_D4: name="d4"; break;
- case ZT_CONFIG_ESF: name="esf"; break;
- case ZT_CONFIG_CCS: name="ccs"; break;
- default: name="unknown"; break;
- }
- return snprintf(buf, PAGE_SIZE, "%s\n", name);
-}
-static DEVICE_ATTR(digital_framing, S_IRUGO, digital_framing_show, NULL);
-
-static DEVICE_ATTR_FUNC(flags_show, dev, buf)
-{
- struct zt_span *span = dev_to_span(dev);
- return snprintf(buf, PAGE_SIZE, "%x\n", span->flags);
-}
-static DEVICE_ATTR(flags, S_IRUGO, flags_show, NULL);
-
-static DEVICE_ATTR_FUNC(name_show, dev, buf)
-{
- struct zt_span *span = dev_to_span(dev);
- return snprintf(buf, PAGE_SIZE, "%s\n", span->name);
-}
-static DEVICE_ATTR(name, S_IRUGO, name_show, NULL);
-
-static DEVICE_ATTR_FUNC(sync_master_show, dev, buf)
-{
- struct zt_span *span = dev_to_span(dev);
- return snprintf(buf, PAGE_SIZE, "%s\n", (span == master) ? "Y":"N");
-}
-static DEVICE_ATTR(sync_master, S_IRUGO, sync_master_show, NULL);
-
-static void span_sysfs_remove(struct zt_span *span)
-{
- struct device *device;
-
- 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);
- device_remove_file(&span->device, &dev_attr_name);
- device_remove_file(&span->device, &dev_attr_sync_master);
- device_unregister(&span->device);
-}
-
-#define span_add_attribute(name) \
- ret = device_create_file(device, &dev_attr_##name); \
- if(ret) { \
- zap_err_span(span, "%s: device_create_file failed (flags): %d\n", __FUNCTION__, ret); \
- goto out; \
- }
-static int span_sysfs_create(struct zt_span *span)
-{
- struct device *device;
- int ret = 0;
-
- BUG_ON(!span);
- device = &span->device;
- BUG_ON(!device);
- zap_dbg_span(span, "\n");
- device_initialize(device);
- device->bus = &zap_bus_type;
- device->parent = &zap_bus;
- snprintf(device->bus_id, BUS_ID_SIZE, "span-%02d", span->spanno);
- device->driver_data = NULL; /* FIXME: add some usefull data */
- device->release = zap_dev_release;
- ret = device_register(device);
- if(ret) {
- zap_err_span(span, "%s: device_add failed: %d\n", __FUNCTION__, ret);
- goto out;
- }
- span_add_attribute(digital_coding);
- span_add_attribute(digital_framing);
- span_add_attribute(flags);
- span_add_attribute(name);
- span_add_attribute(sync_master);
-out:
- return ret;
-}
-/*
- * End device Model Stuff
- *
- ****************************************************/
-#endif /* ZAP_DEVICE_MODEL */
static int zt_first_empty_alias(void)
{
More information about the zaptel-commits
mailing list