From: Johan Hovold Date: Tue, 19 Jul 2016 13:24:46 +0000 (+0200) Subject: greybus: interface: add interface-type attribute X-Git-Tag: v4.9.8~1233^2~378^2~21^2~144 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1bb61840c4db64e27f0077dcfc5389e662022d40;p=platform%2Fkernel%2Flinux-rpi3.git greybus: interface: add interface-type attribute Add an interface-type string attribute that represents the detected interface type as either "dummy", "unipro", "greybus", or "unknown". Signed-off-by: Johan Hovold Reviewed-by: Viresh Kumar Reviewed-by: Sandeep Patil Reviewed-by: Bryan O'Donoghue Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/Documentation/sysfs-bus-greybus b/drivers/staging/greybus/Documentation/sysfs-bus-greybus index 8605d70..721010e 100644 --- a/drivers/staging/greybus/Documentation/sysfs-bus-greybus +++ b/drivers/staging/greybus/Documentation/sysfs-bus-greybus @@ -82,6 +82,14 @@ Contact: Greg Kroah-Hartman 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 +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 diff --git a/drivers/staging/greybus/interface.c b/drivers/staging/greybus/interface.c index b3bd96e..1d50877 100644 --- a/drivers/staging/greybus/interface.c +++ b/drivers/staging/greybus/interface.c @@ -491,6 +491,27 @@ static ssize_t power_now_show(struct device *dev, } 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, @@ -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_interface_type.attr, NULL, }; ATTRIBUTE_GROUPS(interface); @@ -721,6 +743,8 @@ static int gb_interface_activate_operation(struct gb_interface *intf) return ret; } + intf->type = type; + 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); + intf->type = GB_SVC_INTF_TYPE_UNKNOWN; return -ENODEV; } diff --git a/drivers/staging/greybus/interface.h b/drivers/staging/greybus/interface.h index 8796c55..05a3909 100644 --- a/drivers/staging/greybus/interface.h +++ b/drivers/staging/greybus/interface.h @@ -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 type; u32 ddbl1_manufacturer_id; u32 ddbl1_product_id;