Commit 5a8b8314 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

greybus: i2c-gb: convert to use gb_operation_sync

This converts the I2C protocol driver to use gb_operation_sync, removing
lots of places where the create/send/destroy pattern was being used to
send greybus messages.
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
Reviewed-by: default avatarAlex Elder <elder@linaro.org>
parent 7d5bbb17
...@@ -92,38 +92,23 @@ struct gb_i2c_transfer_response { ...@@ -92,38 +92,23 @@ struct gb_i2c_transfer_response {
*/ */
static int gb_i2c_proto_version_operation(struct gb_i2c_device *gb_i2c_dev) static int gb_i2c_proto_version_operation(struct gb_i2c_device *gb_i2c_dev)
{ {
struct gb_connection *connection = gb_i2c_dev->connection; struct gb_i2c_proto_version_response response;
struct gb_operation *operation;
struct gb_i2c_proto_version_response *response;
int ret; int ret;
/* A protocol version request has no payload */ ret = gb_operation_sync(gb_i2c_dev->connection,
operation = gb_operation_create(connection, GB_I2C_TYPE_PROTOCOL_VERSION,
GB_I2C_TYPE_PROTOCOL_VERSION, NULL, 0, &response, sizeof(response));
0, sizeof(*response)); if (ret)
if (!operation) return ret;
return -ENOMEM;
/* Synchronous operation--no callback */
ret = gb_operation_request_send(operation, NULL);
if (ret) {
pr_err("version operation failed (%d)\n", ret);
goto out;
}
response = operation->response->payload; if (response.major > GB_I2C_VERSION_MAJOR) {
if (response->major > GB_I2C_VERSION_MAJOR) {
pr_err("unsupported major version (%hhu > %hhu)\n", pr_err("unsupported major version (%hhu > %hhu)\n",
response->major, GB_I2C_VERSION_MAJOR); response.major, GB_I2C_VERSION_MAJOR);
ret = -ENOTSUPP; return -ENOTSUPP;
goto out;
} }
gb_i2c_dev->version_major = response->major; gb_i2c_dev->version_major = response.major;
gb_i2c_dev->version_minor = response->minor; gb_i2c_dev->version_minor = response.minor;
out: return 0;
gb_operation_destroy(operation);
return ret;
} }
/* /*
...@@ -136,56 +121,34 @@ static u32 gb_i2c_functionality_map(u32 gb_i2c_functionality) ...@@ -136,56 +121,34 @@ static u32 gb_i2c_functionality_map(u32 gb_i2c_functionality)
static int gb_i2c_functionality_operation(struct gb_i2c_device *gb_i2c_dev) static int gb_i2c_functionality_operation(struct gb_i2c_device *gb_i2c_dev)
{ {
struct gb_connection *connection = gb_i2c_dev->connection; struct gb_i2c_functionality_response response;
struct gb_operation *operation;
struct gb_i2c_functionality_response *response;
u32 functionality; u32 functionality;
int ret; int ret;
/* A functionality request has no payload */ ret = gb_operation_sync(gb_i2c_dev->connection,
operation = gb_operation_create(connection, GB_I2C_TYPE_FUNCTIONALITY,
GB_I2C_TYPE_FUNCTIONALITY, NULL, 0, &response, sizeof(response));
0, sizeof(*response)); if (ret)
if (!operation) return ret;
return -ENOMEM;
/* Synchronous operation--no callback */
ret = gb_operation_request_send(operation, NULL);
if (ret) {
pr_err("functionality operation failed (%d)\n", ret);
goto out;
}
response = operation->response->payload; functionality = le32_to_cpu(response.functionality);
functionality = le32_to_cpu(response->functionality);
gb_i2c_dev->functionality = gb_i2c_functionality_map(functionality); gb_i2c_dev->functionality = gb_i2c_functionality_map(functionality);
out:
gb_operation_destroy(operation);
return ret; return 0;
} }
static int gb_i2c_timeout_operation(struct gb_i2c_device *gb_i2c_dev, u16 msec) static int gb_i2c_timeout_operation(struct gb_i2c_device *gb_i2c_dev, u16 msec)
{ {
struct gb_connection *connection = gb_i2c_dev->connection; struct gb_i2c_timeout_request request;
struct gb_operation *operation;
struct gb_i2c_timeout_request *request;
int ret; int ret;
operation = gb_operation_create(connection, GB_I2C_TYPE_TIMEOUT, request.msec = cpu_to_le16(msec);
sizeof(*request), 0); ret = gb_operation_sync(gb_i2c_dev->connection, GB_I2C_TYPE_TIMEOUT,
if (!operation) &request, sizeof(request), NULL, 0);
return -ENOMEM;
request = operation->request->payload;
request->msec = cpu_to_le16(msec);
/* Synchronous operation--no callback */
ret = gb_operation_request_send(operation, NULL);
if (ret) if (ret)
pr_err("timeout operation failed (%d)\n", ret); pr_err("timeout operation failed (%d)\n", ret);
else else
gb_i2c_dev->timeout_msec = msec; gb_i2c_dev->timeout_msec = msec;
gb_operation_destroy(operation);
return ret; return ret;
} }
...@@ -193,25 +156,16 @@ static int gb_i2c_timeout_operation(struct gb_i2c_device *gb_i2c_dev, u16 msec) ...@@ -193,25 +156,16 @@ static int gb_i2c_timeout_operation(struct gb_i2c_device *gb_i2c_dev, u16 msec)
static int gb_i2c_retries_operation(struct gb_i2c_device *gb_i2c_dev, static int gb_i2c_retries_operation(struct gb_i2c_device *gb_i2c_dev,
u8 retries) u8 retries)
{ {
struct gb_connection *connection = gb_i2c_dev->connection; struct gb_i2c_retries_request request;
struct gb_operation *operation;
struct gb_i2c_retries_request *request;
int ret; int ret;
operation = gb_operation_create(connection, GB_I2C_TYPE_RETRIES, request.retries = retries;
sizeof(*request), 0); ret = gb_operation_sync(gb_i2c_dev->connection, GB_I2C_TYPE_RETRIES,
if (!operation) &request, sizeof(request), NULL, 0);
return -ENOMEM;
request = operation->request->payload;
request->retries = retries;
/* Synchronous operation--no callback */
ret = gb_operation_request_send(operation, NULL);
if (ret) if (ret)
pr_err("retries operation failed (%d)\n", ret); pr_err("retries operation failed (%d)\n", ret);
else else
gb_i2c_dev->retries = retries; gb_i2c_dev->retries = retries;
gb_operation_destroy(operation);
return ret; return ret;
} }
......
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