From 835642526e9310d435cc718cdb69f2fcd7a53b84 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Tue, 19 Jul 2016 15:24:48 +0200 Subject: [PATCH] greybus: interface: make attributes type dependent 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 Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/interface.c | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/staging/greybus/interface.c b/drivers/staging/greybus/interface.c index 1d50bd4..c27b18b 100644 --- a/drivers/staging/greybus/interface.c +++ b/drivers/staging/greybus/interface.c @@ -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, }; -- 2.7.4