]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
greybus: control: drop legacy-protocol dependency
authorJohan Hovold <johan@hovoldconsulting.com>
Tue, 19 Jan 2016 11:51:14 +0000 (12:51 +0100)
committerGreg Kroah-Hartman <gregkh@google.com>
Tue, 19 Jan 2016 20:17:13 +0000 (12:17 -0800)
Drop dependency on the legacy protocol abstraction.

Instead implement the protocol-specific version request directly, and
use the new interface for managing the control connection.

Note that the version request is being removed from most protocols, but
we need to keep the current request for the control protocol as-is
indefinitely to maintain backwards compatibility (e.g. with the ES2/ES3
bootrom).

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

index d79807c10b98d0d51f2e2b8eda6bafc06ef7941a..30779402b368af2ec3ac8693aaa0e683d9d73c28 100644 (file)
 #define GB_CONTROL_VERSION_MINOR       1
 
 
+int gb_control_get_version(struct gb_control *control)
+{
+       struct gb_interface *intf = control->connection->intf;
+       struct gb_control_version_request request;
+       struct gb_control_version_response response;
+       int ret;
+
+       request.major = GB_CONTROL_VERSION_MAJOR;
+       request.minor = GB_CONTROL_VERSION_MINOR;
+
+       ret = gb_operation_sync(control->connection,
+                               GB_CONTROL_TYPE_VERSION,
+                               &request, sizeof(request), &response,
+                               sizeof(response));
+       if (ret) {
+               dev_err(&intf->dev,
+                               "failed to get control-protocol version: %d\n",
+                               ret);
+               return ret;
+       }
+
+       if (response.major > request.major) {
+               dev_err(&intf->dev,
+                               "unsupported major control-protocol version (%u > %u)\n",
+                               response.major, request.major);
+               return -ENOTSUPP;
+       }
+
+       control->protocol_major = response.major;
+       control->protocol_minor = response.minor;
+
+       dev_dbg(&intf->dev, "%s - %u.%u\n", __func__, response.major,
+                       response.minor);
+
+       return 0;
+}
+
 /* Get Manifest's size from the interface */
 int gb_control_get_manifest_size_operation(struct gb_interface *intf)
 {
@@ -121,7 +158,7 @@ int gb_control_enable(struct gb_control *control)
 
        dev_dbg(&control->connection->intf->dev, "%s\n", __func__);
 
-       ret = gb_connection_legacy_init(control->connection);
+       ret = gb_connection_enable_tx(control->connection);
        if (ret) {
                dev_err(&control->connection->intf->dev,
                                "failed to enable control connection: %d\n",
@@ -129,14 +166,23 @@ int gb_control_enable(struct gb_control *control)
                return ret;
        }
 
+       ret = gb_control_get_version(control);
+       if (ret)
+               goto err_disable_connection;
+
        return 0;
+
+err_disable_connection:
+       gb_connection_disable(control->connection);
+
+       return ret;
 }
 
 void gb_control_disable(struct gb_control *control)
 {
        dev_dbg(&control->connection->intf->dev, "%s\n", __func__);
 
-       gb_connection_legacy_exit(control->connection);
+       gb_connection_disable(control->connection);
 }
 
 void gb_control_destroy(struct gb_control *control)
@@ -144,25 +190,3 @@ void gb_control_destroy(struct gb_control *control)
        gb_connection_destroy(control->connection);
        kfree(control);
 }
-
-static int gb_control_connection_init(struct gb_connection *connection)
-{
-       dev_dbg(&connection->intf->dev, "%s\n", __func__);
-
-       return 0;
-}
-
-static void gb_control_connection_exit(struct gb_connection *connection)
-{
-       dev_dbg(&connection->intf->dev, "%s\n", __func__);
-}
-
-static struct gb_protocol control_protocol = {
-       .name                   = "control",
-       .id                     = GREYBUS_PROTOCOL_CONTROL,
-       .major                  = GB_CONTROL_VERSION_MAJOR,
-       .minor                  = GB_CONTROL_VERSION_MINOR,
-       .connection_init        = gb_control_connection_init,
-       .connection_exit        = gb_control_connection_exit,
-};
-gb_builtin_protocol_driver(control_protocol);
index 7cb3dd2290d738d8799bfa0fcc30c2e2db3fbee8..dd0a2d79da20722e37eac74a0521ae5d52128d54 100644 (file)
@@ -12,6 +12,9 @@
 
 struct gb_control {
        struct gb_connection    *connection;
+
+       u8 protocol_major;
+       u8 protocol_minor;
 };
 
 struct gb_control *gb_control_create(struct gb_interface *intf);
@@ -26,6 +29,4 @@ int gb_control_get_manifest_operation(struct gb_interface *intf, void *manifest,
                                      size_t size);
 int gb_control_get_interface_version_operation(struct gb_interface *intf);
 
-int gb_control_protocol_init(void);
-void gb_control_protocol_exit(void);
 #endif /* __CONTROL_H */
index 493f3920aaf0ef53f5ad0041725a140b53bb0745..6674b2728f98bf85e459734219ca7740d143c32e 100644 (file)
@@ -234,12 +234,6 @@ static int __init gb_init(void)
                goto error_operation;
        }
 
-       retval = gb_control_protocol_init();
-       if (retval) {
-               pr_err("gb_control_protocol_init failed\n");
-               goto error_control;
-       }
-
        retval = gb_svc_protocol_init();
        if (retval) {
                pr_err("gb_svc_protocol_init failed\n");
@@ -265,8 +259,6 @@ error_legacy:
 error_firmware:
        gb_svc_protocol_exit();
 error_svc:
-       gb_control_protocol_exit();
-error_control:
        gb_operation_exit();
 error_operation:
        gb_hd_exit();
@@ -284,7 +276,6 @@ static void __exit gb_exit(void)
        gb_legacy_exit();
        gb_firmware_protocol_exit();
        gb_svc_protocol_exit();
-       gb_control_protocol_exit();
        gb_operation_exit();
        gb_hd_exit();
        bus_unregister(&greybus_bus_type);
index c563e7454d9c4bc33187982809b9bdc837b16ae1..abbb214863c9410d97b0f17397feec6dc005e832 100644 (file)
@@ -116,6 +116,7 @@ struct gb_protocol_version_response {
 /* Control Protocol */
 
 /* Greybus control request types */
+#define GB_CONTROL_TYPE_VERSION                        0x01
 #define GB_CONTROL_TYPE_PROBE_AP               0x02
 #define GB_CONTROL_TYPE_GET_MANIFEST_SIZE      0x03
 #define GB_CONTROL_TYPE_GET_MANIFEST           0x04
@@ -123,6 +124,16 @@ struct gb_protocol_version_response {
 #define GB_CONTROL_TYPE_DISCONNECTED           0x06
 #define GB_CONTROL_TYPE_INTERFACE_VERSION      0x0a
 
+struct gb_control_version_request {
+       __u8    major;
+       __u8    minor;
+} __packed;
+
+struct gb_control_version_response {
+       __u8    major;
+       __u8    minor;
+} __packed;
+
 /* Control protocol manifest get size request has no payload*/
 struct gb_control_get_manifest_size_response {
        __le16                  size;