greybus: interface: make attributes type dependent
authorJohan Hovold <johan@hovoldconsulting.com>
Tue, 19 Jul 2016 13:24:48 +0000 (15:24 +0200)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 20 Jul 2016 02:06:34 +0000 (19:06 -0700)
Make most interface attributes type dependent (e.g only UniPro and
Greybus interfaces should have a DDBL1 Manufacturer ID attribute).

Note that the power attributes (e.g. current_now) will only be visible
for UniPro- and Greybus-type interfaces (i.e. interfaces that can draw
power).

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/interface.c

index 1d50bd4..c27b18b 100644 (file)
@@ -538,15 +538,62 @@ static struct attribute *interface_common_attrs[] = {
        NULL
 };
 
+static umode_t interface_unipro_is_visible(struct kobject *kobj,
+                                               struct attribute *attr, int n)
+{
+       struct device *dev = container_of(kobj, struct device, kobj);
+       struct gb_interface *intf = to_gb_interface(dev);
+
+       switch (intf->type) {
+       case GB_SVC_INTF_TYPE_UNIPRO:
+       case GB_SVC_INTF_TYPE_GREYBUS:
+               return attr->mode;
+       default:
+               return 0;
+       }
+}
+
+static umode_t interface_greybus_is_visible(struct kobject *kobj,
+                                               struct attribute *attr, int n)
+{
+       struct device *dev = container_of(kobj, struct device, kobj);
+       struct gb_interface *intf = to_gb_interface(dev);
+
+       switch (intf->type) {
+       case GB_SVC_INTF_TYPE_GREYBUS:
+               return attr->mode;
+       default:
+               return 0;
+       }
+}
+
+static umode_t interface_power_is_visible(struct kobject *kobj,
+                                               struct attribute *attr, int n)
+{
+       struct device *dev = container_of(kobj, struct device, kobj);
+       struct gb_interface *intf = to_gb_interface(dev);
+
+       switch (intf->type) {
+       case GB_SVC_INTF_TYPE_UNIPRO:
+       case GB_SVC_INTF_TYPE_GREYBUS:
+               return attr->mode;
+       default:
+               return 0;
+       }
+}
+
 static const struct attribute_group interface_unipro_group = {
+       .is_visible     = interface_unipro_is_visible,
        .attrs          = interface_unipro_attrs,
 };
 
 static const struct attribute_group interface_greybus_group = {
+       .is_visible     = interface_greybus_is_visible,
        .attrs          = interface_greybus_attrs,
 };
 
 static const struct attribute_group interface_power_group = {
+       .is_visible     = interface_power_is_visible,
        .attrs          = interface_power_attrs,
 };