summaryrefslogtreecommitdiffstats
path: root/drivers/staging/greybus/connection.c
diff options
context:
space:
mode:
authorAlex Elder2014-10-22 09:04:30 +0200
committerGreg Kroah-Hartman2014-10-22 11:20:28 +0200
commit36561f23a80b7c44320f34a3b6e6833616e50200 (patch)
tree585aeed63253eabe95ea7c43f2e237cb6a4b0564 /drivers/staging/greybus/connection.c
parentgreybus: define operation_cancel() (diff)
downloadkernel-qcow2-linux-36561f23a80b7c44320f34a3b6e6833616e50200.tar.gz
kernel-qcow2-linux-36561f23a80b7c44320f34a3b6e6833616e50200.tar.xz
kernel-qcow2-linux-36561f23a80b7c44320f34a3b6e6833616e50200.zip
greybus: define connection state
Define the state of a connection. A connection will not be enabled until it has been successfully set up. Once it starts getting torn down its state will move to "being destroyed". Don't send any operation request messages unless the connection is enabled. And drop any incoming messages if if the connection is not enabled. Signed-off-by: Alex Elder <elder@linaro.org> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Diffstat (limited to 'drivers/staging/greybus/connection.c')
-rw-r--r--drivers/staging/greybus/connection.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c
index 9bcda993685a..b1e933fc7044 100644
--- a/drivers/staging/greybus/connection.c
+++ b/drivers/staging/greybus/connection.c
@@ -143,6 +143,7 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface,
connection->interface = interface; /* XXX refcount? */
connection->interface_cport_id = cport_id;
connection->protocol = protocol;
+ connection->state = GB_CONNECTION_STATE_DISABLED;
spin_lock_irq(&gb_connections_lock);
_gb_hd_connection_insert(hd, connection);
@@ -217,13 +218,20 @@ void gb_connection_err(struct gb_connection *connection, const char *fmt, ...)
*/
int gb_connection_init(struct gb_connection *connection)
{
+ int ret;
+
+ /* Need to enable the connection to initialize it */
+ connection->state = GB_CONNECTION_STATE_ENABLED;
switch (connection->protocol) {
case GREYBUS_PROTOCOL_I2C:
- return gb_i2c_device_init(connection);
+ ret = gb_i2c_device_init(connection);
+ break;
case GREYBUS_PROTOCOL_GPIO:
- return gb_gpio_controller_init(connection);
+ ret = gb_gpio_controller_init(connection);
+ break;
case GREYBUS_PROTOCOL_BATTERY:
- return gb_battery_device_init(connection);
+ ret = gb_battery_device_init(connection);
+ break;
case GREYBUS_PROTOCOL_CONTROL:
case GREYBUS_PROTOCOL_AP:
case GREYBUS_PROTOCOL_UART:
@@ -233,13 +241,20 @@ int gb_connection_init(struct gb_connection *connection)
default:
gb_connection_err(connection, "unimplemented protocol %u",
(u32)connection->protocol);
+ ret = -ENXIO;
break;
}
- return -ENXIO;
+
+ if (ret)
+ connection->state = GB_CONNECTION_STATE_ERROR;
+
+ return ret;
}
void gb_connection_exit(struct gb_connection *connection)
{
+ connection->state = GB_CONNECTION_STATE_DESTROYING;
+
switch (connection->protocol) {
case GREYBUS_PROTOCOL_I2C:
gb_i2c_device_exit(connection);