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

greybus: legacy: refactor legacy-connection handling

Add wrapper structure for legacy connections and add helpers to create
and destroy legacy connections.

This is a step in removing legacy connection fields from the core
structures.
Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 24e094d6
...@@ -12,9 +12,13 @@ ...@@ -12,9 +12,13 @@
#include "protocol.h" #include "protocol.h"
struct legacy_connection {
struct gb_connection *connection;
};
struct legacy_data { struct legacy_data {
size_t num_cports; size_t num_cports;
struct gb_connection **connections; struct legacy_connection *connections;
}; };
...@@ -78,12 +82,16 @@ static int legacy_request_handler(struct gb_operation *operation) ...@@ -78,12 +82,16 @@ static int legacy_request_handler(struct gb_operation *operation)
return protocol->request_recv(operation->type, operation); return protocol->request_recv(operation->type, operation);
} }
static int legacy_connection_init(struct gb_connection *connection) static int legacy_connection_init(struct legacy_connection *lc)
{ {
struct gb_connection *connection = lc->connection;
gb_request_handler_t handler; gb_request_handler_t handler;
int ret; int ret;
ret = legacy_connection_bind_protocol(connection); dev_dbg(&connection->bundle->dev, "%s - %s\n", __func__,
connection->name);
ret = legacy_connection_bind_protocol(lc->connection);
if (ret) if (ret)
return ret; return ret;
...@@ -114,8 +122,10 @@ static int legacy_connection_init(struct gb_connection *connection) ...@@ -114,8 +122,10 @@ static int legacy_connection_init(struct gb_connection *connection)
return ret; return ret;
} }
static void legacy_connection_exit(struct gb_connection *connection) static void legacy_connection_exit(struct legacy_connection *lc)
{ {
struct gb_connection *connection = lc->connection;
if (!connection->protocol) if (!connection->protocol)
return; return;
...@@ -126,12 +136,33 @@ static void legacy_connection_exit(struct gb_connection *connection) ...@@ -126,12 +136,33 @@ static void legacy_connection_exit(struct gb_connection *connection)
legacy_connection_unbind_protocol(connection); legacy_connection_unbind_protocol(connection);
} }
static int legacy_connection_create(struct legacy_connection *lc,
struct gb_bundle *bundle,
struct greybus_descriptor_cport *desc)
{
struct gb_connection *connection;
connection = gb_connection_create(bundle, le16_to_cpu(desc->id));
if (IS_ERR(connection))
return PTR_ERR(connection);
lc->connection = connection;
lc->connection->protocol_id = desc->protocol_id;
return 0;
}
static void legacy_connection_destroy(struct legacy_connection *lc)
{
gb_connection_destroy(lc->connection);
}
static int legacy_probe(struct gb_bundle *bundle, static int legacy_probe(struct gb_bundle *bundle,
const struct greybus_bundle_id *id) const struct greybus_bundle_id *id)
{ {
struct greybus_descriptor_cport *cport_desc; struct greybus_descriptor_cport *cport_desc;
struct legacy_data *data; struct legacy_data *data;
struct gb_connection *connection; struct legacy_connection *lc;
int i; int i;
int ret; int ret;
...@@ -154,27 +185,19 @@ static int legacy_probe(struct gb_bundle *bundle, ...@@ -154,27 +185,19 @@ static int legacy_probe(struct gb_bundle *bundle,
for (i = 0; i < data->num_cports; ++i) { for (i = 0; i < data->num_cports; ++i) {
cport_desc = &bundle->cport_desc[i]; cport_desc = &bundle->cport_desc[i];
lc = &data->connections[i];
connection = gb_connection_create(bundle, ret = legacy_connection_create(lc, bundle, cport_desc);
le16_to_cpu(cport_desc->id)); if (ret)
if (IS_ERR(connection)) {
ret = PTR_ERR(connection);
goto err_connections_destroy; goto err_connections_destroy;
} }
connection->protocol_id = cport_desc->protocol_id;
data->connections[i] = connection;
}
greybus_set_drvdata(bundle, data); greybus_set_drvdata(bundle, data);
for (i = 0; i < data->num_cports; ++i) { for (i = 0; i < data->num_cports; ++i) {
connection = data->connections[i]; lc = &data->connections[i];
dev_dbg(&bundle->dev, "enabling connection %s\n",
connection->name);
ret = legacy_connection_init(connection); ret = legacy_connection_init(lc);
if (ret) if (ret)
goto err_connections_disable; goto err_connections_disable;
} }
...@@ -183,10 +206,10 @@ static int legacy_probe(struct gb_bundle *bundle, ...@@ -183,10 +206,10 @@ static int legacy_probe(struct gb_bundle *bundle,
err_connections_disable: err_connections_disable:
for (--i; i >= 0; --i) for (--i; i >= 0; --i)
legacy_connection_exit(data->connections[i]); legacy_connection_exit(&data->connections[i]);
err_connections_destroy: err_connections_destroy:
for (i = 0; i < data->num_cports; ++i) for (i = 0; i < data->num_cports; ++i)
gb_connection_destroy(data->connections[i]); legacy_connection_destroy(&data->connections[i]);
kfree(data->connections); kfree(data->connections);
err_free_data: err_free_data:
kfree(data); kfree(data);
...@@ -203,8 +226,8 @@ static void legacy_disconnect(struct gb_bundle *bundle) ...@@ -203,8 +226,8 @@ static void legacy_disconnect(struct gb_bundle *bundle)
bundle->class); bundle->class);
for (i = 0; i < data->num_cports; ++i) { for (i = 0; i < data->num_cports; ++i) {
legacy_connection_exit(data->connections[i]); legacy_connection_exit(&data->connections[i]);
gb_connection_destroy(data->connections[i]); legacy_connection_destroy(&data->connections[i]);
} }
kfree(data->connections); kfree(data->connections);
......
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