greybus: interface: move vendor and product strings to control device
authorJohan Hovold <johan@hovoldconsulting.com>
Wed, 13 Apr 2016 17:19:04 +0000 (19:19 +0200)
committerGreg Kroah-Hartman <gregkh@google.com>
Thu, 21 Apr 2016 01:09:03 +0000 (10:09 +0900)
The control device is an abstraction of the control connection over
which a greybus manifest is retrieved. As interfaces switch modes (e.g.
after boot-over-unipro) they expose new manifests, which can contain
different vendor and product strings.

Eventually control devices will be deregistered and recreated after an
interface mode switch, while the interface itself remains registered.

Note that only interfaces of type greybus will have control devices.
Specifically, dummy interfaces will not.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/Documentation/sysfs-bus-greybus
drivers/staging/greybus/control.c
drivers/staging/greybus/control.h
drivers/staging/greybus/interface.c
drivers/staging/greybus/interface.h
drivers/staging/greybus/manifest.c

index d8bf30e..4831efb 100644 (file)
@@ -52,13 +52,6 @@ Contact:     Greg Kroah-Hartman <greg@kroah.com>
 Description:
                Product ID of a Greybus interface.
 
-What:          /sys/bus/greybus/device/N-I/product_string
-Date:          October 2015
-KernelVersion: 4.XX
-Contact:       Greg Kroah-Hartman <greg@kroah.com>
-Description:
-               Product ID string of a Greybus interface.
-
 What:          /sys/bus/greybus/device/N-I/vendor_id
 Date:          October 2015
 KernelVersion: 4.XX
@@ -66,13 +59,6 @@ Contact:     Greg Kroah-Hartman <greg@kroah.com>
 Description:
                Vendor ID of a Greybus interface.
 
-What:          /sys/bus/greybus/device/N-I/vendor_string
-Date:          October 2015
-KernelVersion: 4.XX
-Contact:       Greg Kroah-Hartman <greg@kroah.com>
-Description:
-               Vendor ID string of a Greybus interface block.
-
 What:          /sys/bus/greybus/device/N-I/version
 Date:          October 2015
 KernelVersion: 4.XX
@@ -110,6 +96,20 @@ Description:
                A bundle B on the Interface I, B is replaced by a 1-byte
                number representing the bundle.
 
+What:          /sys/bus/greybus/device/N-I.ctrl/product_string
+Date:          October 2015
+KernelVersion: 4.XX
+Contact:       Greg Kroah-Hartman <greg@kroah.com>
+Description:
+               Product ID string of a Greybus interface.
+
+What:          /sys/bus/greybus/device/N-I.ctrl/vendor_string
+Date:          October 2015
+KernelVersion: 4.XX
+Contact:       Greg Kroah-Hartman <greg@kroah.com>
+Description:
+               Vendor ID string of a Greybus interface.
+
 What:          /sys/bus/greybus/device/N-I.B/bundle_class
 Date:          October 2015
 KernelVersion: 4.XX
index 6063619..58a3d60 100644 (file)
@@ -213,12 +213,40 @@ int gb_control_timesync_authoritative(struct gb_control *control,
                                 NULL, 0);
 }
 
+static ssize_t vendor_string_show(struct device *dev,
+                       struct device_attribute *attr, char *buf)
+{
+       struct gb_control *control = to_gb_control(dev);
+
+       return scnprintf(buf, PAGE_SIZE, "%s\n", control->vendor_string);
+}
+static DEVICE_ATTR_RO(vendor_string);
+
+static ssize_t product_string_show(struct device *dev,
+                       struct device_attribute *attr, char *buf)
+{
+       struct gb_control *control = to_gb_control(dev);
+
+       return scnprintf(buf, PAGE_SIZE, "%s\n", control->product_string);
+}
+static DEVICE_ATTR_RO(product_string);
+
+static struct attribute *control_attrs[] = {
+       &dev_attr_vendor_string.attr,
+       &dev_attr_product_string.attr,
+       NULL,
+};
+ATTRIBUTE_GROUPS(control);
+
 static void gb_control_release(struct device *dev)
 {
        struct gb_control *control = to_gb_control(dev);
 
        gb_connection_destroy(control->connection);
 
+       kfree(control->vendor_string);
+       kfree(control->product_string);
+
        kfree(control);
 }
 
@@ -249,6 +277,7 @@ struct gb_control *gb_control_create(struct gb_interface *intf)
        control->dev.parent = &intf->dev;
        control->dev.bus = &greybus_bus_type;
        control->dev.type = &greybus_control_type;
+       control->dev.groups = control_groups;
        control->dev.dma_mask = intf->dev.dma_mask;
        device_initialize(&control->dev);
        dev_set_name(&control->dev, "%s.ctrl", dev_name(&intf->dev));
index 102e937..56fa259 100644 (file)
@@ -20,6 +20,9 @@ struct gb_control {
        u8 protocol_minor;
 
        bool has_bundle_version;
+
+       char *vendor_string;
+       char *product_string;
 };
 #define to_gb_control(d) container_of(d, struct gb_control, dev)
 
index e0e0873..ed56f2d 100644 (file)
@@ -249,8 +249,6 @@ gb_interface_attr(ddbl1_product_id, "0x%08x");
 gb_interface_attr(interface_id, "%u");
 gb_interface_attr(vendor_id, "0x%08x");
 gb_interface_attr(product_id, "0x%08x");
-gb_interface_attr(vendor_string, "%s");
-gb_interface_attr(product_string, "%s");
 gb_interface_attr(serial_number, "0x%016llx");
 
 static ssize_t version_show(struct device *dev, struct device_attribute *attr,
@@ -326,8 +324,6 @@ static struct attribute *interface_attrs[] = {
        &dev_attr_interface_id.attr,
        &dev_attr_vendor_id.attr,
        &dev_attr_product_id.attr,
-       &dev_attr_vendor_string.attr,
-       &dev_attr_product_string.attr,
        &dev_attr_serial_number.attr,
        &dev_attr_version.attr,
        &dev_attr_voltage_now.attr,
@@ -356,9 +352,6 @@ static void gb_interface_release(struct device *dev)
 {
        struct gb_interface *intf = to_gb_interface(dev);
 
-       kfree(intf->product_string);
-       kfree(intf->vendor_string);
-
        if (intf->control)
                gb_control_put(intf->control);
 
index 15c687f..567b6c8 100644 (file)
@@ -25,10 +25,6 @@ struct gb_interface {
        u8 interface_id;        /* Physical location within the Endo */
        u8 device_id;
 
-       /* Information taken from the manifest descriptor */
-       char *vendor_string;
-       char *product_string;
-
        u32 ddbl1_manufacturer_id;
        u32 ddbl1_product_id;
        u32 vendor_id;
index cca4592..886c5fb 100644 (file)
@@ -384,18 +384,19 @@ static bool gb_manifest_parse_interface(struct gb_interface *intf,
                                        struct manifest_desc *interface_desc)
 {
        struct greybus_descriptor_interface *desc_intf = interface_desc->data;
+       struct gb_control *control = intf->control;
        char *str;
 
        /* Handle the strings first--they can fail */
        str = gb_string_get(intf, desc_intf->vendor_stringid);
        if (IS_ERR(str))
                return false;
-       intf->vendor_string = str;
+       control->vendor_string = str;
 
        str = gb_string_get(intf, desc_intf->product_stringid);
        if (IS_ERR(str))
                goto out_free_vendor_string;
-       intf->product_string = str;
+       control->product_string = str;
 
        /* Release the interface descriptor, now that we're done with it */
        release_manifest_descriptor(interface_desc);
@@ -408,11 +409,11 @@ static bool gb_manifest_parse_interface(struct gb_interface *intf,
 
        return true;
 out_err:
-       kfree(intf->product_string);
-       intf->product_string = NULL;
+       kfree(control->product_string);
+       control->product_string = NULL;
 out_free_vendor_string:
-       kfree(intf->vendor_string);
-       intf->vendor_string = NULL;
+       kfree(control->vendor_string);
+       control->vendor_string = NULL;
 
        return false;
 }