From 67c93ae6f544a0953d1159ffcc0dd14bea77fc53 Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Fri, 24 Jul 2015 15:32:19 +0530 Subject: [PATCH] greybus: svc: fully initialize the partially initialized connection 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 Tested-by: Perry Hung Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/connection.c | 24 ++++++++++++++++++++++++ drivers/staging/greybus/connection.h | 2 ++ drivers/staging/greybus/svc.c | 16 +--------------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index b88abed2e1ad..0cd716d58a3a 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -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; diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h index 6b40c4aeeeac..f02b9d9fb084 100644 --- a/drivers/staging/greybus/connection.h +++ b/drivers/staging/greybus/connection.h @@ -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, diff --git a/drivers/staging/greybus/svc.c b/drivers/staging/greybus/svc.c index ebd282d33e66..28a4ca9f8aca 100644 --- a/drivers/staging/greybus/svc.c +++ b/drivers/staging/greybus/svc.c @@ -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; } -- 2.20.1