Commit 7fba0079 authored by Alex Elder's avatar Alex Elder Committed by Greg Kroah-Hartman

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: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent b2969960
...@@ -111,18 +111,18 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, ...@@ -111,18 +111,18 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
} }
static DEVICE_ATTR_RO(state); static DEVICE_ATTR_RO(state);
static ssize_t protocol_show(struct device *dev, struct device_attribute *attr, static ssize_t
char *buf) protocol_id_show(struct device *dev, struct device_attribute *attr, char *buf)
{ {
struct gb_connection *connection = to_gb_connection(dev); 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[] = { static struct attribute *connection_attrs[] = {
&dev_attr_state.attr, &dev_attr_state.attr,
&dev_attr_protocol.attr, &dev_attr_protocol_id.attr,
NULL, NULL,
}; };
...@@ -152,7 +152,7 @@ static struct device_type greybus_connection_type = { ...@@ -152,7 +152,7 @@ static struct device_type greybus_connection_type = {
* pointer otherwise. * pointer otherwise.
*/ */
struct gb_connection *gb_connection_create(struct gb_interface *interface, 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 gb_connection *connection;
struct greybus_host_device *hd; struct greybus_host_device *hd;
...@@ -172,7 +172,7 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface, ...@@ -172,7 +172,7 @@ struct gb_connection *gb_connection_create(struct gb_interface *interface,
connection->interface = interface; connection->interface = interface;
connection->interface_cport_id = cport_id; connection->interface_cport_id = cport_id;
connection->protocol = protocol; connection->protocol_id = protocol_id;
connection->state = GB_CONNECTION_STATE_DISABLED; connection->state = GB_CONNECTION_STATE_DISABLED;
connection->dev.parent = &interface->dev; connection->dev.parent = &interface->dev;
...@@ -267,7 +267,7 @@ int gb_connection_init(struct gb_connection *connection) ...@@ -267,7 +267,7 @@ int gb_connection_init(struct gb_connection *connection)
/* Need to enable the connection to initialize it */ /* Need to enable the connection to initialize it */
connection->state = GB_CONNECTION_STATE_ENABLED; connection->state = GB_CONNECTION_STATE_ENABLED;
switch (connection->protocol) { switch (connection->protocol_id) {
case GREYBUS_PROTOCOL_I2C: case GREYBUS_PROTOCOL_I2C:
connection->handler = &gb_i2c_connection_handler; connection->handler = &gb_i2c_connection_handler;
break; break;
...@@ -286,8 +286,8 @@ int gb_connection_init(struct gb_connection *connection) ...@@ -286,8 +286,8 @@ int gb_connection_init(struct gb_connection *connection)
case GREYBUS_PROTOCOL_LED: case GREYBUS_PROTOCOL_LED:
case GREYBUS_PROTOCOL_VENDOR: case GREYBUS_PROTOCOL_VENDOR:
default: default:
gb_connection_err(connection, "unimplemented protocol %u", gb_connection_err(connection, "unimplemented protocol %hhu",
(u32)connection->protocol); connection->protocol_id);
ret = -ENXIO; ret = -ENXIO;
break; break;
} }
......
...@@ -39,7 +39,8 @@ struct gb_connection { ...@@ -39,7 +39,8 @@ struct gb_connection {
struct rb_node hd_node; struct rb_node hd_node;
struct list_head interface_links; struct list_head interface_links;
enum greybus_protocol protocol; u8 protocol_id;
enum gb_connection_state state; enum gb_connection_state state;
struct list_head operations; struct list_head operations;
...@@ -53,7 +54,7 @@ struct gb_connection { ...@@ -53,7 +54,7 @@ struct gb_connection {
#define to_gb_connection(d) container_of(d, struct gb_connection, dev) #define to_gb_connection(d) container_of(d, struct gb_connection, dev)
struct gb_connection *gb_connection_create(struct gb_interface *interface, 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); void gb_connection_destroy(struct gb_connection *connection);
int gb_connection_init(struct gb_connection *connection); int gb_connection_init(struct gb_connection *connection);
......
...@@ -98,13 +98,13 @@ struct greybus_descriptor_interface { ...@@ -98,13 +98,13 @@ struct greybus_descriptor_interface {
/* /*
* A CPort descriptor indicates the id of the interface within the * A CPort descriptor indicates the id of the interface within the
* module it's associated with, along with the CPort id used to * 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. * exchanged using the CPort.
*/ */
struct greybus_descriptor_cport { struct greybus_descriptor_cport {
__u8 interface; __u8 interface;
__le16 id; __le16 id;
__u8 protocol; /* enum greybus_protocol */ __u8 protocol_id; /* enum greybus_protocol */
}; };
/* /*
......
...@@ -181,7 +181,7 @@ static u32 gb_manifest_parse_cports(struct gb_interface *interface) ...@@ -181,7 +181,7 @@ static u32 gb_manifest_parse_cports(struct gb_interface *interface)
while (true) { while (true) {
struct manifest_desc *descriptor; struct manifest_desc *descriptor;
struct greybus_descriptor_cport *desc_cport; struct greybus_descriptor_cport *desc_cport;
enum greybus_protocol protocol; u8 protocol_id;
u16 cport_id; u16 cport_id;
bool found; bool found;
...@@ -200,9 +200,9 @@ static u32 gb_manifest_parse_cports(struct gb_interface *interface) ...@@ -200,9 +200,9 @@ static u32 gb_manifest_parse_cports(struct gb_interface *interface)
break; break;
/* Found one. Set up its function structure */ /* 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); 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 */ return 0; /* Error */
count++; count++;
......
...@@ -200,21 +200,21 @@ static gb_operation_recv_handler gb_operation_recv_handlers[] = { ...@@ -200,21 +200,21 @@ static gb_operation_recv_handler gb_operation_recv_handlers[] = {
static void gb_operation_request_handle(struct gb_operation *operation) 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 */ /* 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; gb_operation_recv_handler handler;
handler = gb_operation_recv_handlers[protocol]; handler = gb_operation_recv_handlers[protocol_id];
if (handler) { if (handler) {
handler(operation); /* Handle the request */ handler(operation); /* Handle the request */
return; return;
} }
} }
gb_connection_err(operation->connection, "unrecognized protocol %u\n", gb_connection_err(operation->connection,
(unsigned int)protocol); "unrecognized protocol id %hhu\n", protocol_id);
operation->result = GB_OP_PROTOCOL_BAD; operation->result = GB_OP_PROTOCOL_BAD;
gb_operation_complete(operation); gb_operation_complete(operation);
} }
......
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