From 193c9e59a8c2b5f6a0519fa0c5bbe5766bea5e15 Mon Sep 17 00:00:00 2001 From: Oron Peled Date: Mon, 17 Mar 2014 12:35:39 -0400 Subject: [PATCH] xpp: new xbus attribute: dahdi_registration XPP devices have implicit support for device registration and unregistration. Even though it is only used for the legacy (non-hotplug) configuration case, we still prefer to make it explicit. This attribute would later allow a simpler implementation of the user space (xpp-specific) tool dahdi_registration. Signed-off-by: Tzafrir Cohen --- drivers/dahdi/xpp/xbus-sysfs.c | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/dahdi/xpp/xbus-sysfs.c b/drivers/dahdi/xpp/xbus-sysfs.c index 24dcda2..c92ccb7 100644 --- a/drivers/dahdi/xpp/xbus-sysfs.c +++ b/drivers/dahdi/xpp/xbus-sysfs.c @@ -302,6 +302,42 @@ field##_show(struct device *dev, struct device_attribute *attr, char *buf) \ xbus_attr(connector, "%s\n"); xbus_attr(label, "%s\n"); +static DEVICE_ATTR_WRITER(dahdi_registration_store, dev, buf, count) +{ + xbus_t *xbus; + int dahdi_reg; + int ret; + + xbus = dev_to_xbus(dev); + if (!xbus) + return -ENODEV; + ret = sscanf(buf, "%d", &dahdi_reg); + if (ret != 1) + return -EINVAL; + if (dahdi_reg) { + ret = xbus_register_dahdi_device(xbus); + if (ret < 0) { + XBUS_ERR(xbus, + "xbus_register_dahdi_device() failed (ret = %d)\n", + ret); + return ret; + } + } else { + xbus_unregister_dahdi_device(xbus); + } + return count; +} + +static DEVICE_ATTR_READER(dahdi_registration_show, dev, buf) +{ + xbus_t *xbus; + int len; + + xbus = dev_to_xbus(dev); + len = sprintf(buf, "%d\n", xbus_is_registered(xbus)); + return len; +} + static struct device_attribute xbus_dev_attrs[] = { __ATTR_RO(connector), __ATTR_RO(label), @@ -316,6 +352,9 @@ static struct device_attribute xbus_dev_attrs[] = { #ifdef SAMPLE_TICKS __ATTR(samples, S_IWUSR | S_IRUGO, samples_show, samples_store), #endif + __ATTR(dahdi_registration, S_IRUGO | S_IWUSR, + dahdi_registration_show, + dahdi_registration_store), __ATTR_NULL, };