[zaptel-commits] tzafrir: branch tzafrir/sysfs r2835 - /team/tzafrir/sysfs/

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Tue Aug 14 17:46:18 CDT 2007


Author: tzafrir
Date: Tue Aug 14 17:46:18 2007
New Revision: 2835

URL: http://svn.digium.com/view/zaptel?view=rev&rev=2835
Log:
Doesn't work, but it compiles. and the debug macro are in place.

Modified:
    team/tzafrir/sysfs/   (props changed)
    team/tzafrir/sysfs/zap_dbg.h
    team/tzafrir/sysfs/zaptel-base.c
    team/tzafrir/sysfs/zaptel.h

Propchange: team/tzafrir/sysfs/
------------------------------------------------------------------------------
    svnmerge-integrated = /branches/1.4:1-2825

Modified: team/tzafrir/sysfs/zap_dbg.h
URL: http://svn.digium.com/view/zaptel/team/tzafrir/sysfs/zap_dbg.h?view=diff&rev=2835&r1=2834&r2=2835
==============================================================================
--- team/tzafrir/sysfs/zap_dbg.h (original)
+++ team/tzafrir/sysfs/zap_dbg.h Tue Aug 14 17:46:18 2007
@@ -36,20 +36,20 @@
 		THIS_MODULE->name, (chan)->span->name, (xpd)->xpdname, ## __VA_ARGS__)
 
 #define	zap_dbg(fmt, ...)	\
-	((void)((print_dbg) && zap_printk(DEBUG, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__)))
+	((void)((debug) && zap_printk(DEBUG, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__)))
 #define	zap_info(fmt, ...)		zap_printk(INFO, fmt, ## __VA_ARGS__)
 #define	zap_notice(fmt, ...)		zap_printk(NOTICE, fmt, ## __VA_ARGS__)
 #define	zap_warn(fmt, ...)		zap_printk(WARNING, fmt, ## __VA_ARGS__)
 #define	zap_err(fmt, ...)		zap_printk(ERR, fmt, ## __VA_ARGS__)
 
 #define	zap_dbg_span(span, fmt, ...)	\
-			((void)((print_dbg) && zap_printk_span(DEBUG, span, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__)))
+			((void)((debug) && zap_printk_span(DEBUG, span, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__)))
 #define	zap_info_span(span, fmt, ...)	zap_printk_span(INFO, span, fmt, ## __VA_ARGS__)
 #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, ...)	\
-		((void)((print_dbg) && zap_printk_chan(DEBUG, chan, "%s: " fmt, __FUNCTION__, ## __VA_ARGS__)))
+		((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__)
 #define	zap_warn_chan(chan, fmt, ...)	zap_printk_chan(WARNING, 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=2835&r1=2834&r2=2835
==============================================================================
--- team/tzafrir/sysfs/zaptel-base.c (original)
+++ team/tzafrir/sysfs/zaptel-base.c Tue Aug 14 17:46:18 2007
@@ -79,6 +79,7 @@
 
 #ifdef STANDALONE_ZAPATA
 #include "zaptel.h"
+#include "zap_dbg.h"
 #else
 #include <zaptel/zaptel.h>
 #endif
@@ -633,6 +634,234 @@
 	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
+
+/*--------- Sysfs Bus handling ----*/
+
+/* 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 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 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);
+	XBUS_ADD_UEVENT_VAR("XBUS_NUM=%02d", span->spanno);
+	XBUS_ADD_UEVENT_VAR("XBUS_NAME=%s", span->name);
+	envp[i] = NULL;
+	return 0;
+}
+#endif
+
+static void zap_bus_release(struct device *dev)
+{
+	zap_dbg("\n");
+}
+
+static void xpp_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           = "spans",
+	.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		= "xppbus",
+	.release	= zap_bus_release
+};
+
+static struct device_driver xpp_driver = {
+	.name		= "xppdrv",
+	.bus		= &zap_bus_type,
+#ifndef OLD_HOPLUG_SUPPORT
+	.owner		= THIS_MODULE
+#endif
+};
+
+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(&xpp_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;
+}
+
+void unregister_zap_bus(void)
+{
+	driver_unregister(&xpp_driver);
+	device_unregister(&zap_bus);
+	bus_unregister(&zap_bus_type);
+}
+
+/*--------- Sysfs Device handling ----*/
+static DEVICE_ATTR_FUNC(connector_show, dev, buf)
+{
+	struct zt_span	*span;
+	int	ret;
+
+	span = dev_to_span(dev);
+	ret = snprintf(buf, PAGE_SIZE, "%s\n", span->desc);
+	return ret;
+}
+
+/* FIXME: replace this attribute with something more useful */
+static DEVICE_ATTR_FUNC(status_show, dev, buf)
+{
+	struct zt_span	*span;
+	int	ret;
+
+	span = dev_to_span(dev);
+	ret = snprintf(buf, PAGE_SIZE, "%s\n", "connected");
+	return ret;
+}
+
+static	DEVICE_ATTR(connector, S_IRUGO, connector_show, NULL);
+static	DEVICE_ATTR(status, S_IRUGO, status_show, NULL);
+
+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_status);
+	device_remove_file(&span->device, &dev_attr_connector);
+	device_unregister(&span->device);
+}
+
+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 = xpp_dev_release;
+	ret = device_register(device);
+	if(ret) {
+		zap_err_span(span, "%s: device_add failed: %d\n", __FUNCTION__, ret);
+		goto out;
+	}
+	ret = device_create_file(device, &dev_attr_connector);
+	if(ret) {
+		zap_err_span(span, "%s: device_create_file failed: %d\n", __FUNCTION__, ret);
+		goto out;
+	}
+	ret = device_create_file(device, &dev_attr_status);
+	if(ret) {
+		zap_err_span(span, "%s: device_create_file failed: %d\n", __FUNCTION__, ret);
+		goto out;
+	}
+out:
+	return ret;
+}
+/*
+ * End device Model Stuff
+ *
+ ****************************************************/
+
 
 static int zt_first_empty_alias(void)
 {

Modified: team/tzafrir/sysfs/zaptel.h
URL: http://svn.digium.com/view/zaptel/team/tzafrir/sysfs/zaptel.h?view=diff&rev=2835&r1=2834&r2=2835
==============================================================================
--- team/tzafrir/sysfs/zaptel.h (original)
+++ team/tzafrir/sysfs/zaptel.h Tue Aug 14 17:46:18 2007
@@ -49,6 +49,7 @@
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 #define LINUX26
+#include <linux/device.h>
 #endif
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
@@ -1447,6 +1448,10 @@
 	int spanno;			/* Span number for zaptel */
 	int offset;			/* Offset within a given card */
 	int lastalarms;		/* Previous alarms */
+#ifdef LINUX26
+        struct device device;  /* Device model object. For e.g. sysfs */
+#define dev_to_span(dev)        container_of(dev, struct zt_span, device)
+#endif
 
 #ifdef CONFIG_DEVFS_FS
 	devfs_handle_t dhandle;  /* Directory name */




More information about the zaptel-commits mailing list