summaryrefslogtreecommitdiff
path: root/drivers/staging/greybus/control.c
diff options
context:
space:
mode:
authorJohan Hovold <johan@hovoldconsulting.com>2015-12-15 15:28:56 +0100
committerGreg Kroah-Hartman <gregkh@google.com>2015-12-15 14:23:37 -0800
commitc634650ecc5b3db9ac4f1258387b87ff66386906 (patch)
tree5fdc77e3622fa0891b31ffbeaa9a8e70b2b16230 /drivers/staging/greybus/control.c
parented972e3a36c3402479f46f6d0218e7ef586d0d3e (diff)
greybus: interface: clean up control-connection handling
Clean up control-connection handling by managing it through the control structure and a higher-level control interface. Also make both the control structure and connection lifetimes coincide with that of the interface. The control connection is now only enabled and disabled when the interface is initialised and removed. Signed-off-by: Johan Hovold <johan@hovoldconsulting.com> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Diffstat (limited to 'drivers/staging/greybus/control.c')
-rw-r--r--drivers/staging/greybus/control.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/drivers/staging/greybus/control.c b/drivers/staging/greybus/control.c
index 2cc1917adda0..9c282e40142b 100644
--- a/drivers/staging/greybus/control.c
+++ b/drivers/staging/greybus/control.c
@@ -59,31 +59,70 @@ int gb_control_disconnected_operation(struct gb_control *control, u16 cport_id)
sizeof(request), NULL, 0);
}
-static int gb_control_connection_init(struct gb_connection *connection)
+struct gb_control *gb_control_create(struct gb_interface *intf)
{
struct gb_control *control;
control = kzalloc(sizeof(*control), GFP_KERNEL);
if (!control)
- return -ENOMEM;
+ return NULL;
+
+ control->connection = gb_connection_create_dynamic(intf, NULL,
+ GB_CONTROL_CPORT_ID,
+ GREYBUS_PROTOCOL_CONTROL);
+ if (!control->connection) {
+ dev_err(&intf->dev, "failed to create control connection\n");
+ kfree(control);
+ return NULL;
+ }
- control->connection = connection;
- connection->private = control;
+ control->connection->private = control;
+
+ return control;
+}
+
+int gb_control_enable(struct gb_control *control)
+{
+ int ret;
- /* Set interface's control connection */
- connection->intf->control = control;
+ dev_dbg(&control->connection->intf->dev, "%s\n", __func__);
+
+ ret = gb_connection_init(control->connection);
+ if (ret) {
+ dev_err(&control->connection->intf->dev,
+ "failed to enable control connection: %d\n",
+ ret);
+ return ret;
+ }
return 0;
}
-static void gb_control_connection_exit(struct gb_connection *connection)
+void gb_control_disable(struct gb_control *control)
{
- struct gb_control *control = connection->private;
+ dev_dbg(&control->connection->intf->dev, "%s\n", __func__);
- connection->intf->control = NULL;
+ gb_connection_exit(control->connection);
+}
+
+void gb_control_destroy(struct gb_control *control)
+{
+ gb_connection_destroy(control->connection);
kfree(control);
}
+static int gb_control_connection_init(struct gb_connection *connection)
+{
+ dev_dbg(&connection->intf->dev, "%s\n", __func__);
+
+ return 0;
+}
+
+static void gb_control_connection_exit(struct gb_connection *connection)
+{
+ dev_dbg(&connection->intf->dev, "%s\n", __func__);
+}
+
static struct gb_protocol control_protocol = {
.name = "control",
.id = GREYBUS_PROTOCOL_CONTROL,