greybus: use protocol_id for numeric values
authorAlex Elder <elder@linaro.org>
Wed, 29 Oct 2014 00:35:59 +0000 (19:35 -0500)
committerGreg Kroah-Hartman <greg@kroah.com>
Wed, 29 Oct 2014 00:42:17 +0000 (08:42 +0800)
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 <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/staging/greybus/connection.c
drivers/staging/greybus/connection.h
drivers/staging/greybus/greybus_manifest.h
drivers/staging/greybus/manifest.c
drivers/staging/greybus/operation.c

index 3fee647..6d5085d 100644 (file)
@@ -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;
        }
index 88a9398..830abe7 100644 (file)
@@ -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);
index c18ee11..c6988ce 100644 (file)
@@ -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 */
 };
 
 /*
index 09fcde9..2e22f54 100644 (file)
@@ -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++;
index dc35425..0388242 100644 (file)
@@ -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);
 }