greybus: interface: add interface-type attribute
authorJohan Hovold <johan@hovoldconsulting.com>
Tue, 19 Jul 2016 13:24:46 +0000 (15:24 +0200)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 20 Jul 2016 02:03:32 +0000 (19:03 -0700)
Add an interface-type string attribute that represents the detected
interface type as either "dummy", "unipro", "greybus", or "unknown".

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Sandeep Patil <sspatil@google.com>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/Documentation/sysfs-bus-greybus
drivers/staging/greybus/interface.c
drivers/staging/greybus/interface.h

index 8605d70..721010e 100644 (file)
@@ -82,6 +82,14 @@ Contact:     Greg Kroah-Hartman <greg@kroah.com>
 Description:
                The ID of a Greybus interface.
 
 Description:
                The ID of a Greybus interface.
 
+What:          /sys/bus/greybus/devices/N-M.I/interface_type
+Date:          June 2016
+KernelVersion: 4.XX
+Contact:       Greg Kroah-Hartman <greg@kroah.com>
+Description:
+               The type of a Greybus interface; "dummy", "unipro", "greybus",
+               or "unknown".
+
 What:          /sys/bus/greybus/devices/N-M.I/power_now
 Date:          March 2016
 KernelVersion: 4.XX
 What:          /sys/bus/greybus/devices/N-M.I/power_now
 Date:          March 2016
 KernelVersion: 4.XX
index b3bd96e..1d50877 100644 (file)
@@ -491,6 +491,27 @@ static ssize_t power_now_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(power_now);
 
 }
 static DEVICE_ATTR_RO(power_now);
 
+static const char *gb_interface_type_string(struct gb_interface *intf)
+{
+       static const char * const types[] = {
+               [GB_SVC_INTF_TYPE_UNKNOWN] = "unknown",
+               [GB_SVC_INTF_TYPE_DUMMY] = "dummy",
+               [GB_SVC_INTF_TYPE_UNIPRO] = "unipro",
+               [GB_SVC_INTF_TYPE_GREYBUS] = "greybus",
+       };
+
+       return types[intf->type];
+}
+
+static ssize_t interface_type_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       struct gb_interface *intf = to_gb_interface(dev);
+
+       return sprintf(buf, "%s\n", gb_interface_type_string(intf));
+}
+static DEVICE_ATTR_RO(interface_type);
+
 static struct attribute *interface_attrs[] = {
        &dev_attr_ddbl1_manufacturer_id.attr,
        &dev_attr_ddbl1_product_id.attr,
 static struct attribute *interface_attrs[] = {
        &dev_attr_ddbl1_manufacturer_id.attr,
        &dev_attr_ddbl1_product_id.attr,
@@ -501,6 +522,7 @@ static struct attribute *interface_attrs[] = {
        &dev_attr_voltage_now.attr,
        &dev_attr_current_now.attr,
        &dev_attr_power_now.attr,
        &dev_attr_voltage_now.attr,
        &dev_attr_current_now.attr,
        &dev_attr_power_now.attr,
+       &dev_attr_interface_type.attr,
        NULL,
 };
 ATTRIBUTE_GROUPS(interface);
        NULL,
 };
 ATTRIBUTE_GROUPS(interface);
@@ -721,6 +743,8 @@ static int gb_interface_activate_operation(struct gb_interface *intf)
                return ret;
        }
 
                return ret;
        }
 
+       intf->type = type;
+
        switch (type) {
        case GB_SVC_INTF_TYPE_DUMMY:
                dev_info(&intf->dev, "dummy interface detected\n");
        switch (type) {
        case GB_SVC_INTF_TYPE_DUMMY:
                dev_info(&intf->dev, "dummy interface detected\n");
@@ -734,6 +758,7 @@ static int gb_interface_activate_operation(struct gb_interface *intf)
                break;
        default:
                dev_err(&intf->dev, "unknown interface type: %u\n", type);
                break;
        default:
                dev_err(&intf->dev, "unknown interface type: %u\n", type);
+               intf->type = GB_SVC_INTF_TYPE_UNKNOWN;
                return -ENODEV;
        }
 
                return -ENODEV;
        }
 
index 8796c55..05a3909 100644 (file)
@@ -26,6 +26,7 @@ struct gb_interface {
        u8 interface_id;        /* Physical location within the Endo */
        u8 device_id;
        u8 features;            /* Feature flags set in the manifest */
        u8 interface_id;        /* Physical location within the Endo */
        u8 device_id;
        u8 features;            /* Feature flags set in the manifest */
+       u8 type;
 
        u32 ddbl1_manufacturer_id;
        u32 ddbl1_product_id;
 
        u32 ddbl1_manufacturer_id;
        u32 ddbl1_product_id;