Commit a7e36d0e authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman

greybus: bundle: separate bundle creation and registration

Separate bundle creation and registration.

Note that the bundle connections still needs to be initialised post
registration as protocol drivers create child devices to the bundle.

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: default avatarJohan Hovold <johan@hovoldconsulting.com>
Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent bdc37354
...@@ -107,7 +107,6 @@ struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id, ...@@ -107,7 +107,6 @@ struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id,
u8 class) u8 class)
{ {
struct gb_bundle *bundle; struct gb_bundle *bundle;
int retval;
/* /*
* Reject any attempt to reuse a bundle id. We initialize * Reject any attempt to reuse a bundle id. We initialize
...@@ -128,8 +127,6 @@ struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id, ...@@ -128,8 +127,6 @@ struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id,
bundle->class = class; bundle->class = class;
INIT_LIST_HEAD(&bundle->connections); INIT_LIST_HEAD(&bundle->connections);
/* Build up the bundle device structures and register it with the
* driver core */
bundle->dev.parent = &intf->dev; bundle->dev.parent = &intf->dev;
bundle->dev.bus = &greybus_bus_type; bundle->dev.bus = &greybus_bus_type;
bundle->dev.type = &greybus_bundle_type; bundle->dev.type = &greybus_bundle_type;
...@@ -137,18 +134,24 @@ struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id, ...@@ -137,18 +134,24 @@ struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id,
device_initialize(&bundle->dev); device_initialize(&bundle->dev);
dev_set_name(&bundle->dev, "%s.%d", dev_name(&intf->dev), bundle_id); dev_set_name(&bundle->dev, "%s.%d", dev_name(&intf->dev), bundle_id);
retval = device_add(&bundle->dev);
if (retval) {
pr_err("failed to add bundle device for id %u\n", bundle_id);
put_device(&bundle->dev);
return NULL;
}
list_add(&bundle->links, &intf->bundles); list_add(&bundle->links, &intf->bundles);
return bundle; return bundle;
} }
int gb_bundle_add(struct gb_bundle *bundle)
{
int ret;
ret = device_add(&bundle->dev);
if (ret) {
dev_err(&bundle->dev, "failed to register bundle: %d\n", ret);
return ret;
}
return 0;
}
static void gb_bundle_connections_exit(struct gb_bundle *bundle) static void gb_bundle_connections_exit(struct gb_bundle *bundle)
{ {
struct gb_connection *connection; struct gb_connection *connection;
...@@ -162,10 +165,12 @@ static void gb_bundle_connections_exit(struct gb_bundle *bundle) ...@@ -162,10 +165,12 @@ static void gb_bundle_connections_exit(struct gb_bundle *bundle)
*/ */
void gb_bundle_destroy(struct gb_bundle *bundle) void gb_bundle_destroy(struct gb_bundle *bundle)
{ {
list_del(&bundle->links);
gb_bundle_connections_exit(bundle); gb_bundle_connections_exit(bundle);
device_unregister(&bundle->dev);
}
if (device_is_registered(&bundle->dev))
device_del(&bundle->dev);
list_del(&bundle->links);
put_device(&bundle->dev);
}
...@@ -31,6 +31,7 @@ struct gb_bundle { ...@@ -31,6 +31,7 @@ struct gb_bundle {
/* Greybus "private" definitions" */ /* Greybus "private" definitions" */
struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id, struct gb_bundle *gb_bundle_create(struct gb_interface *intf, u8 bundle_id,
u8 class); u8 class);
int gb_bundle_add(struct gb_bundle *bundle);
void gb_bundle_destroy(struct gb_bundle *bundle); void gb_bundle_destroy(struct gb_bundle *bundle);
#endif /* __BUNDLE_H */ #endif /* __BUNDLE_H */
...@@ -236,7 +236,6 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle) ...@@ -236,7 +236,6 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
u8 protocol_id; u8 protocol_id;
u16 cport_id; u16 cport_id;
u32 count = 0; u32 count = 0;
int ret;
/* Set up all cport descriptors associated with this bundle */ /* Set up all cport descriptors associated with this bundle */
list_for_each_entry_safe(desc, next, &intf->manifest_descs, links) { list_for_each_entry_safe(desc, next, &intf->manifest_descs, links) {
...@@ -262,12 +261,6 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle) ...@@ -262,12 +261,6 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
if (!connection) if (!connection)
goto exit; goto exit;
ret = gb_connection_init(connection);
if (ret) {
gb_connection_destroy(connection);
goto exit;
}
count++; count++;
/* Release the cport descriptor */ /* Release the cport descriptor */
...@@ -293,12 +286,14 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle) ...@@ -293,12 +286,14 @@ static u32 gb_manifest_parse_cports(struct gb_bundle *bundle)
*/ */
static u32 gb_manifest_parse_bundles(struct gb_interface *intf) static u32 gb_manifest_parse_bundles(struct gb_interface *intf)
{ {
struct gb_connection *connection;
struct manifest_desc *desc; struct manifest_desc *desc;
struct gb_bundle *bundle; struct gb_bundle *bundle;
struct gb_bundle *bundle_next; struct gb_bundle *bundle_next;
u32 count = 0; u32 count = 0;
u8 bundle_id; u8 bundle_id;
u8 class; u8 class;
int ret;
while ((desc = get_next_bundle_desc(intf))) { while ((desc = get_next_bundle_desc(intf))) {
struct greybus_descriptor_bundle *desc_bundle; struct greybus_descriptor_bundle *desc_bundle;
...@@ -354,6 +349,23 @@ static u32 gb_manifest_parse_bundles(struct gb_interface *intf) ...@@ -354,6 +349,23 @@ static u32 gb_manifest_parse_bundles(struct gb_interface *intf)
continue; continue;
} }
ret = gb_bundle_add(bundle);
if (ret) {
gb_bundle_destroy(bundle);
continue;
}
list_for_each_entry(connection, &bundle->connections,
bundle_links) {
ret = gb_connection_init(connection);
if (ret)
break;
}
if (ret) {
gb_bundle_destroy(bundle);
continue;
}
count++; count++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment