greybus: connection: separate connection creation and enabling

Separate connection creation from enabling.

This will ultimately allow connection structures to be created while
parsing manifests, but the connections to not be enabled until a driver
is bound.

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>
This commit is contained in:
Johan Hovold 2015-12-07 15:05:34 +01:00 committed by Greg Kroah-Hartman
parent 3617311235
commit 0bf1f24419
5 changed files with 28 additions and 13 deletions

View File

@ -14,7 +14,6 @@
static int gb_connection_bind_protocol(struct gb_connection *connection);
static void gb_connection_unbind_protocol(struct gb_connection *connection);
static int gb_connection_init(struct gb_connection *connection);
static DEFINE_SPINLOCK(gb_connections_lock);
@ -125,7 +124,6 @@ gb_connection_create(struct gb_host_device *hd, int hd_cport_id,
struct gb_connection *connection;
struct ida *id_map = &hd->cport_id_map;
int ida_start, ida_end;
int retval;
u8 major = 0;
u8 minor = 1;
@ -194,14 +192,6 @@ gb_connection_create(struct gb_host_device *hd, int hd_cport_id,
spin_unlock_irq(&gb_connections_lock);
retval = gb_connection_init(connection);
if (retval) {
dev_err(&hd->dev, "%s: failed to initialize connection: %d\n",
connection->name, retval);
gb_connection_destroy(connection);
return NULL;
}
return connection;
err_free_connection:
@ -396,7 +386,7 @@ static int gb_connection_protocol_get_version(struct gb_connection *connection)
return 0;
}
static int gb_connection_init(struct gb_connection *connection)
int gb_connection_init(struct gb_connection *connection)
{
int ret;

View File

@ -63,6 +63,8 @@ static inline bool gb_connection_is_static(struct gb_connection *connection)
return !connection->intf;
}
int gb_connection_init(struct gb_connection *connection);
void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
u8 *data, size_t length);

View File

@ -124,6 +124,13 @@ int gb_hd_add(struct gb_host_device *hd)
return ret;
}
ret = gb_connection_init(hd->svc_connection);
if (ret) {
gb_connection_destroy(hd->svc_connection);
device_del(&hd->dev);
return ret;
}
return 0;
}
EXPORT_SYMBOL_GPL(gb_hd_add);

View File

@ -180,6 +180,12 @@ int gb_interface_init(struct gb_interface *intf, u8 device_id)
return -ENOMEM;
}
ret = gb_connection_init(connection);
if (ret) {
gb_connection_destroy(connection);
return ret;
}
/* Get manifest size using control protocol on CPort */
size = gb_control_get_manifest_size_operation(intf);
if (size <= 0) {

View File

@ -228,6 +228,7 @@ static char *gb_string_get(struct gb_interface *intf, u8 string_id)
*/
static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
{
struct gb_connection *connection;
struct gb_interface *intf = bundle->intf;
struct manifest_desc *desc;
struct manifest_desc *next;
@ -235,6 +236,7 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
u8 protocol_id;
u16 cport_id;
u32 count = 0;
int ret;
/* Set up all cport descriptors associated with this bundle */
list_for_each_entry_safe(desc, next, &intf->manifest_descs, links) {
@ -254,10 +256,18 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
/* Found one. Set up its function structure */
protocol_id = desc_cport->protocol_id;
if (!gb_connection_create_dynamic(intf, bundle, cport_id,
protocol_id))
connection = gb_connection_create_dynamic(intf, bundle,
cport_id,
protocol_id);
if (!connection)
goto exit;
ret = gb_connection_init(connection);
if (ret) {
gb_connection_destroy(connection);
goto exit;
}
count++;
/* Release the cport descriptor */