greybus: gpbridge: Expose protocol_id in sysfs
authorViresh Kumar <viresh.kumar@linaro.org>
Thu, 12 May 2016 06:50:02 +0000 (12:20 +0530)
committerGreg Kroah-Hartman <gregkh@google.com>
Fri, 13 May 2016 10:02:57 +0000 (12:02 +0200)
Right now, userspace doesn't have any way to find what protocol does a
gpbridge device implement. And this is essential for the scripts to
know, to expect what kind of device will be present inside the gpbN
directory.

Expose 'protocol_id' in sysfs to fix that.

Tested by checking that the field appears with GP module on EVT 1.5.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/gpbridge.c

index 993cfac..64ab8dd 100644 (file)
@@ -26,6 +26,22 @@ struct gpbridge_host {
 
 static DEFINE_IDA(gpbridge_id);
 
+static ssize_t protocol_id_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       struct gpbridge_device *gpbdev = to_gpbridge_dev(dev);
+
+       return sprintf(buf, "0x%02x\n", gpbdev->cport_desc->protocol_id);
+}
+static DEVICE_ATTR_RO(protocol_id);
+
+static struct attribute *gpbdev_attrs[] = {
+       &dev_attr_protocol_id.attr,
+       NULL,
+};
+
+ATTRIBUTE_GROUPS(gpbdev);
+
 static void gpbdev_release(struct device *dev)
 {
        struct gpbridge_device *gpbdev = to_gpbridge_dev(dev);
@@ -190,7 +206,7 @@ static struct gpbridge_device *gb_gpbridge_create_dev(struct gb_bundle *bundle,
        gpbdev->dev.parent = &bundle->dev;
        gpbdev->dev.bus = &gpbridge_bus_type;
        gpbdev->dev.release = gpbdev_release;
-       gpbdev->dev.groups = NULL;
+       gpbdev->dev.groups = gpbdev_groups;
        gpbdev->dev.dma_mask = bundle->dev.dma_mask;
        dev_set_name(&gpbdev->dev, "gpb%d", id);