OSDN Git Service

greybus: svc: fully initialize the partially initialized connection
authorViresh Kumar <viresh.kumar@linaro.org>
Fri, 24 Jul 2015 10:02:19 +0000 (15:32 +0530)
committerGreg Kroah-Hartman <gregkh@google.com>
Fri, 24 Jul 2015 23:33:20 +0000 (16:33 -0700)
SVC hello message is received now and we should fully initialize the
partially initialized connection. This can be done by removing and
re-adding the device corresponding to the connection.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Tested-by: Perry Hung <perry@leaflabs.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/connection.c
drivers/staging/greybus/connection.h
drivers/staging/greybus/svc.c

index b88abed..0cd716d 100644 (file)
@@ -111,6 +111,30 @@ struct device_type greybus_connection_type = {
 };
 
 
+int svc_update_connection(struct gb_interface *intf,
+                         struct gb_connection *connection)
+{
+       struct gb_bundle *bundle;
+
+       bundle = gb_bundle_create(intf, GB_SVC_BUNDLE_ID, GREYBUS_CLASS_SVC);
+       if (!bundle)
+               return -EINVAL;
+
+       device_del(&connection->dev);
+       connection->bundle = bundle;
+       connection->dev.parent = &bundle->dev;
+       dev_set_name(&connection->dev, "%s:%d", dev_name(&bundle->dev),
+                    GB_SVC_CPORT_ID);
+
+       WARN_ON(device_add(&connection->dev));
+
+       spin_lock_irq(&gb_connections_lock);
+       list_add(&connection->bundle_links, &bundle->connections);
+       spin_unlock_irq(&gb_connections_lock);
+
+       return 0;
+}
+
 void gb_connection_bind_protocol(struct gb_connection *connection)
 {
        struct gb_protocol *protocol;
index 6b40c4a..f02b9d9 100644 (file)
@@ -47,6 +47,8 @@ struct gb_connection {
 };
 #define to_gb_connection(d) container_of(d, struct gb_connection, dev)
 
+int svc_update_connection(struct gb_interface *intf,
+                         struct gb_connection *connection);
 struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
                                u16 cport_id, u8 protocol_id);
 struct gb_connection *gb_connection_create_range(struct greybus_host_device *hd,
index ebd282d..28a4ca9 100644 (file)
@@ -43,7 +43,6 @@ gb_ap_interface_create(struct greybus_host_device *hd,
 {
        struct gb_interface *intf;
        struct device *dev = &hd->endo->dev;
-       int ret;
 
        intf = gb_interface_create(hd, interface_id);
        if (!intf) {
@@ -53,20 +52,7 @@ gb_ap_interface_create(struct greybus_host_device *hd,
        }
 
        intf->device_id = GB_DEVICE_ID_AP;
-
-       /*
-        * XXX: Disable the initial svc connection here, but don't destroy it
-        * yet. We do need to send a response of 'svc-hello message' on that.
-        */
-
-       /* Establish new control CPort connection */
-       ret = gb_create_bundle_connection(intf, GREYBUS_CLASS_SVC);
-       if (ret) {
-               dev_err(&intf->dev, "%s: Failed to create svc connection (%d %d)\n",
-                       __func__, interface_id, ret);
-               gb_interface_destroy(intf);
-               intf = NULL;
-       }
+       svc_update_connection(intf, connection);
 
        return intf;
 }