greybus: connection: send [dis]connected events over control CPort
authorViresh Kumar <viresh.kumar@linaro.org>
Mon, 22 Jun 2015 11:12:29 +0000 (16:42 +0530)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 24 Jun 2015 06:17:25 +0000 (23:17 -0700)
The AP needs to send connected and disconnection events to all
interfaces, before a CPort (other than control CPort) can be used.

For now do it which we initialize the connection, but it should be moved
to operations code later.

Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/connection.c

index 9467aaba2b329ba23b6b6a4a78c24bdb13968cad..564011ac78948e7ab9b3b45a3ce8aa9f98ac2080 100644 (file)
@@ -248,6 +248,7 @@ void gb_connection_destroy(struct gb_connection *connection)
 
 int gb_connection_init(struct gb_connection *connection)
 {
+       int cport_id = connection->intf_cport_id;
        int ret;
 
        if (!connection->protocol) {
@@ -255,6 +256,22 @@ int gb_connection_init(struct gb_connection *connection)
                return 0;
        }
 
+       /*
+        * Inform Interface about Active CPorts. We don't need to do this
+        * operation for control cport.
+        */
+       if (cport_id != GB_CONTROL_CPORT_ID) {
+               struct gb_control *control = connection->bundle->intf->control;
+
+               ret = gb_control_connected_operation(control, cport_id);
+               if (ret) {
+                       dev_warn(&connection->dev,
+                                "Failed to connect CPort-%d (%d)\n",
+                                cport_id, ret);
+                       return 0;
+               }
+       }
+
        /* Need to enable the connection to initialize it */
        connection->state = GB_CONNECTION_STATE_ENABLED;
        ret = connection->protocol->connection_init(connection);
@@ -266,6 +283,8 @@ int gb_connection_init(struct gb_connection *connection)
 
 void gb_connection_exit(struct gb_connection *connection)
 {
+       int cport_id = connection->intf_cport_id;
+
        if (!connection->protocol) {
                dev_warn(&connection->dev, "exit without protocol.\n");
                return;
@@ -276,4 +295,19 @@ void gb_connection_exit(struct gb_connection *connection)
 
        connection->state = GB_CONNECTION_STATE_DESTROYING;
        connection->protocol->connection_exit(connection);
+
+       /*
+        * Inform Interface about In-active CPorts. We don't need to do this
+        * operation for control cport.
+        */
+       if (cport_id != GB_CONTROL_CPORT_ID) {
+               struct gb_control *control = connection->bundle->intf->control;
+               int ret;
+
+               ret = gb_control_disconnected_operation(control, cport_id);
+               if (ret)
+                       dev_warn(&connection->dev,
+                                "Failed to disconnect CPort-%d (%d)\n",
+                                cport_id, ret);
+       }
 }