From 7fba0079ad9a5b1b851947ad3c5b90093b2fc415 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Tue, 28 Oct 2014 19:35:59 -0500 Subject: [PATCH] greybus: use protocol_id for numeric values Switch to using "protocol_id" to refer to a byte-sized numeric protocol number. A "protocol" will represent a protocol structure (created in the next patch). Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- drivers/staging/greybus/connection.c | 20 ++++++++++---------- drivers/staging/greybus/connection.h | 5 +++-- drivers/staging/greybus/greybus_manifest.h | 4 ++-- drivers/staging/greybus/manifest.c | 6 +++--- drivers/staging/greybus/operation.c | 10 +++++----- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index 3fee64773976..6d5085d2b6aa 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -111,18 +111,18 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(state); -static ssize_t protocol_show(struct device *dev, struct device_attribute *attr, - char *buf) +static ssize_t +protocol_id_show(struct device *dev, struct device_attribute *attr, char *buf) { struct gb_connection *connection = to_gb_connection(dev); - return sprintf(buf, "%d", connection->protocol); + return sprintf(buf, "%d", connection->protocol_id); } -static DEVICE_ATTR_RO(protocol); +static DEVICE_ATTR_RO(protocol_id); static struct attribute *connection_attrs[] = { &dev_attr_state.attr, - &dev_attr_protocol.attr, + &dev_attr_protocol_id.attr, NULL, }; @@ -152,7 +152,7 @@ static struct device_type greybus_connection_type = { * pointer otherwise. */ struct gb_connection *gb_connection_create(struct gb_interface *interface, - u16 cport_id, enum greybus_protocol protocol) + u16 cport_id, u8 protocol_id) { struct gb_connection *connection; struct greybus_host_device *hd; @@ -172,7 +172,7 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface, connection->interface = interface; connection->interface_cport_id = cport_id; - connection->protocol = protocol; + connection->protocol_id = protocol_id; connection->state = GB_CONNECTION_STATE_DISABLED; connection->dev.parent = &interface->dev; @@ -267,7 +267,7 @@ int gb_connection_init(struct gb_connection *connection) /* Need to enable the connection to initialize it */ connection->state = GB_CONNECTION_STATE_ENABLED; - switch (connection->protocol) { + switch (connection->protocol_id) { case GREYBUS_PROTOCOL_I2C: connection->handler = &gb_i2c_connection_handler; break; @@ -286,8 +286,8 @@ int gb_connection_init(struct gb_connection *connection) case GREYBUS_PROTOCOL_LED: case GREYBUS_PROTOCOL_VENDOR: default: - gb_connection_err(connection, "unimplemented protocol %u", - (u32)connection->protocol); + gb_connection_err(connection, "unimplemented protocol %hhu", + connection->protocol_id); ret = -ENXIO; break; } diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h index 88a9398c79d6..830abe7060ba 100644 --- a/drivers/staging/greybus/connection.h +++ b/drivers/staging/greybus/connection.h @@ -39,7 +39,8 @@ struct gb_connection { struct rb_node hd_node; struct list_head interface_links; - enum greybus_protocol protocol; + u8 protocol_id; + enum gb_connection_state state; struct list_head operations; @@ -53,7 +54,7 @@ struct gb_connection { #define to_gb_connection(d) container_of(d, struct gb_connection, dev) struct gb_connection *gb_connection_create(struct gb_interface *interface, - u16 cport_id, enum greybus_protocol protocol); + u16 cport_id, u8 protocol_id); void gb_connection_destroy(struct gb_connection *connection); int gb_connection_init(struct gb_connection *connection); diff --git a/drivers/staging/greybus/greybus_manifest.h b/drivers/staging/greybus/greybus_manifest.h index c18ee112f6df..c6988ce2818a 100644 --- a/drivers/staging/greybus/greybus_manifest.h +++ b/drivers/staging/greybus/greybus_manifest.h @@ -98,13 +98,13 @@ struct greybus_descriptor_interface { /* * A CPort descriptor indicates the id of the interface within the * module it's associated with, along with the CPort id used to - * address the CPort. The protocol defines the format of messages + * address the CPort. The protocol id defines the format of messages * exchanged using the CPort. */ struct greybus_descriptor_cport { __u8 interface; __le16 id; - __u8 protocol; /* enum greybus_protocol */ + __u8 protocol_id; /* enum greybus_protocol */ }; /* diff --git a/drivers/staging/greybus/manifest.c b/drivers/staging/greybus/manifest.c index 09fcde9dd7ce..2e22f545e15b 100644 --- a/drivers/staging/greybus/manifest.c +++ b/drivers/staging/greybus/manifest.c @@ -181,7 +181,7 @@ static u32 gb_manifest_parse_cports(struct gb_interface *interface) while (true) { struct manifest_desc *descriptor; struct greybus_descriptor_cport *desc_cport; - enum greybus_protocol protocol; + u8 protocol_id; u16 cport_id; bool found; @@ -200,9 +200,9 @@ static u32 gb_manifest_parse_cports(struct gb_interface *interface) break; /* Found one. Set up its function structure */ - protocol = (enum greybus_protocol)desc_cport->protocol; + protocol_id = desc_cport->protocol_id; cport_id = le16_to_cpu(desc_cport->id); - if (!gb_connection_create(interface, cport_id, protocol)) + if (!gb_connection_create(interface, cport_id, protocol_id)) return 0; /* Error */ count++; diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c index dc354252bef5..0388242d9b79 100644 --- a/drivers/staging/greybus/operation.c +++ b/drivers/staging/greybus/operation.c @@ -200,21 +200,21 @@ static gb_operation_recv_handler gb_operation_recv_handlers[] = { static void gb_operation_request_handle(struct gb_operation *operation) { - u8 protocol = operation->connection->protocol; + u8 protocol_id = operation->connection->protocol_id; /* Subtract one from array size to stay within u8 range */ - if (protocol <= (u8)(ARRAY_SIZE(gb_operation_recv_handlers) - 1)) { + if (protocol_id <= (u8)(ARRAY_SIZE(gb_operation_recv_handlers) - 1)) { gb_operation_recv_handler handler; - handler = gb_operation_recv_handlers[protocol]; + handler = gb_operation_recv_handlers[protocol_id]; if (handler) { handler(operation); /* Handle the request */ return; } } - gb_connection_err(operation->connection, "unrecognized protocol %u\n", - (unsigned int)protocol); + gb_connection_err(operation->connection, + "unrecognized protocol id %hhu\n", protocol_id); operation->result = GB_OP_PROTOCOL_BAD; gb_operation_complete(operation); } -- 2.20.1