Commit bf2329fd authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

greybus: pwm-gb: convert to use gb_operation_sync

This converts the PWM 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 5a8b8314
...@@ -85,234 +85,118 @@ struct gb_pwm_disable_request { ...@@ -85,234 +85,118 @@ struct gb_pwm_disable_request {
*/ */
static int gb_pwm_proto_version_operation(struct gb_pwm_chip *pwmc) static int gb_pwm_proto_version_operation(struct gb_pwm_chip *pwmc)
{ {
struct gb_connection *connection = pwmc->connection; struct gb_pwm_proto_version_response response;
struct gb_operation *operation;
struct gb_pwm_proto_version_response *response;
int ret; int ret;
/* protocol version request has no payload */ ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_PROTOCOL_VERSION,
operation = gb_operation_create(connection, NULL, 0, &response, sizeof(response));
GB_PWM_TYPE_PROTOCOL_VERSION,
0, sizeof(*response));
if (!operation)
return -ENOMEM;
/* Synchronous operation--no callback */ if (ret)
ret = gb_operation_request_send(operation, NULL); return ret;
if (ret) {
pr_err("version operation failed (%d)\n", ret);
goto out;
}
response = operation->response->payload; if (response.major > GB_PWM_VERSION_MAJOR) {
if (response->major > GB_PWM_VERSION_MAJOR) {
pr_err("unsupported major version (%hhu > %hhu)\n", pr_err("unsupported major version (%hhu > %hhu)\n",
response->major, GB_PWM_VERSION_MAJOR); response.major, GB_PWM_VERSION_MAJOR);
ret = -ENOTSUPP; return -ENOTSUPP;
goto out;
} }
pwmc->version_major = response->major; pwmc->version_major = response.major;
pwmc->version_minor = response->minor; pwmc->version_minor = response.minor;
out: return 0;
gb_operation_destroy(operation);
return ret;
} }
static int gb_pwm_count_operation(struct gb_pwm_chip *pwmc) static int gb_pwm_count_operation(struct gb_pwm_chip *pwmc)
{ {
struct gb_connection *connection = pwmc->connection; struct gb_pwm_count_response response;
struct gb_operation *operation;
struct gb_pwm_count_response *response;
int ret; int ret;
/* pwm count request has no payload */ ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_PWM_COUNT,
operation = gb_operation_create(connection, GB_PWM_TYPE_PWM_COUNT, NULL, 0, &response, sizeof(response));
0, sizeof(*response)); if (ret)
if (!operation) return ret;
return -ENOMEM; pwmc->pwm_max = response.count;
return 0;
/* Synchronous operation--no callback */
ret = gb_operation_request_send(operation, NULL);
if (ret) {
pr_err("line count operation failed (%d)\n", ret);
} else {
response = operation->response->payload;
pwmc->pwm_max = response->count;
}
gb_operation_destroy(operation);
return ret;
} }
static int gb_pwm_activate_operation(struct gb_pwm_chip *pwmc, static int gb_pwm_activate_operation(struct gb_pwm_chip *pwmc,
u8 which) u8 which)
{ {
struct gb_connection *connection = pwmc->connection; struct gb_pwm_activate_request request;
struct gb_operation *operation;
struct gb_pwm_activate_request *request;
int ret;
if (which > pwmc->pwm_max) if (which > pwmc->pwm_max)
return -EINVAL; return -EINVAL;
/* activate response has no payload */ request.which = which;
operation = gb_operation_create(connection, GB_PWM_TYPE_ACTIVATE, return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_ACTIVATE,
sizeof(*request), 0); &request, sizeof(request), NULL, 0);
if (!operation)
return -ENOMEM;
request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
ret = gb_operation_request_send(operation, NULL);
if (ret)
pr_err("activate operation failed (%d)\n", ret);
gb_operation_destroy(operation);
return ret;
} }
static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc, static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc,
u8 which) u8 which)
{ {
struct gb_connection *connection = pwmc->connection; struct gb_pwm_deactivate_request request;
struct gb_operation *operation;
struct gb_pwm_deactivate_request *request;
int ret;
if (which > pwmc->pwm_max) if (which > pwmc->pwm_max)
return -EINVAL; return -EINVAL;
/* deactivate response has no payload */ request.which = which;
operation = gb_operation_create(connection, GB_PWM_TYPE_DEACTIVATE, return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_DEACTIVATE,
sizeof(*request), 0); &request, sizeof(request), NULL, 0);
if (!operation)
return -ENOMEM;
request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
ret = gb_operation_request_send(operation, NULL);
if (ret)
pr_err("deactivate operation failed (%d)\n", ret);
gb_operation_destroy(operation);
return ret;
} }
static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc, static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc,
u8 which, u32 duty, u32 period) u8 which, u32 duty, u32 period)
{ {
struct gb_connection *connection = pwmc->connection; struct gb_pwm_config_request request;
struct gb_operation *operation;
struct gb_pwm_config_request *request;
int ret;
if (which > pwmc->pwm_max) if (which > pwmc->pwm_max)
return -EINVAL; return -EINVAL;
operation = gb_operation_create(connection, GB_PWM_TYPE_CONFIG, request.which = which;
sizeof(*request), 0); request.duty = duty;
if (!operation) request.period = period;
return -ENOMEM; return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_CONFIG,
request = operation->request->payload; &request, sizeof(request), NULL, 0);
request->which = which;
request->duty = duty;
request->period = period;
/* Synchronous operation--no callback */
ret = gb_operation_request_send(operation, NULL);
if (ret)
pr_err("config operation failed (%d)\n", ret);
gb_operation_destroy(operation);
return ret;
} }
static int gb_pwm_set_polarity_operation(struct gb_pwm_chip *pwmc, static int gb_pwm_set_polarity_operation(struct gb_pwm_chip *pwmc,
u8 which, u8 polarity) u8 which, u8 polarity)
{ {
struct gb_connection *connection = pwmc->connection; struct gb_pwm_polarity_request request;
struct gb_operation *operation;
struct gb_pwm_polarity_request *request;
int ret;
if (which > pwmc->pwm_max) if (which > pwmc->pwm_max)
return -EINVAL; return -EINVAL;
operation = gb_operation_create(connection, GB_PWM_TYPE_POLARITY, request.which = which;
sizeof(*request), 0); request.polarity = polarity;
if (!operation) return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_POLARITY,
return -ENOMEM; &request, sizeof(request), NULL, 0);
request = operation->request->payload;
request->which = which;
request->polarity = polarity;
/* Synchronous operation--no callback */
ret = gb_operation_request_send(operation, NULL);
if (ret)
pr_err("set polarity operation failed (%d)\n", ret);
gb_operation_destroy(operation);
return ret;
} }
static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc, static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc,
u8 which) u8 which)
{ {
struct gb_connection *connection = pwmc->connection; struct gb_pwm_enable_request request;
struct gb_operation *operation;
struct gb_pwm_enable_request *request;
int ret;
if (which > pwmc->pwm_max) if (which > pwmc->pwm_max)
return -EINVAL; return -EINVAL;
/* enable response has no payload */ request.which = which;
operation = gb_operation_create(connection, GB_PWM_TYPE_ENABLE, return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_ENABLE,
sizeof(*request), 0); &request, sizeof(request), NULL, 0);
if (!operation)
return -ENOMEM;
request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
ret = gb_operation_request_send(operation, NULL);
if (ret)
pr_err("enable operation failed (%d)\n", ret);
gb_operation_destroy(operation);
return ret;
} }
static int gb_pwm_disable_operation(struct gb_pwm_chip *pwmc, static int gb_pwm_disable_operation(struct gb_pwm_chip *pwmc,
u8 which) u8 which)
{ {
struct gb_connection *connection = pwmc->connection; struct gb_pwm_disable_request request;
struct gb_operation *operation;
struct gb_pwm_disable_request *request;
int ret;
if (which > pwmc->pwm_max) if (which > pwmc->pwm_max)
return -EINVAL; return -EINVAL;
/* disable response has no payload */ request.which = which;
operation = gb_operation_create(connection, GB_PWM_TYPE_DISABLE, return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_DISABLE,
sizeof(*request), 0); &request, sizeof(request), NULL, 0);
if (!operation)
return -ENOMEM;
request = operation->request->payload;
request->which = which;
/* Synchronous operation--no callback */
ret = gb_operation_request_send(operation, NULL);
if (ret)
pr_err("disable operation failed (%d)\n", ret);
gb_operation_destroy(operation);
return ret;
} }
static int gb_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) static int gb_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
......
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