From: Greg Kroah-Hartman Date: Mon, 24 Nov 2014 01:45:24 +0000 (-0800) Subject: greybus: pwm-gb: convert to use gb_operation_sync X-Git-Tag: v4.9-rc1~119^2~378^2~21^2~1821 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=bf2329fd7d2795b9ce7146ca9e7092a7f507ce59;p=karo-tx-linux.git 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: Greg Kroah-Hartman Reviewed-by: Alex Elder --- diff --git a/drivers/staging/greybus/pwm-gb.c b/drivers/staging/greybus/pwm-gb.c index e146b240f89e..bd1379f4400f 100644 --- a/drivers/staging/greybus/pwm-gb.c +++ b/drivers/staging/greybus/pwm-gb.c @@ -85,234 +85,118 @@ struct gb_pwm_disable_request { */ static int gb_pwm_proto_version_operation(struct gb_pwm_chip *pwmc) { - struct gb_connection *connection = pwmc->connection; - struct gb_operation *operation; - struct gb_pwm_proto_version_response *response; + struct gb_pwm_proto_version_response response; int ret; - /* protocol version request has no payload */ - operation = gb_operation_create(connection, - GB_PWM_TYPE_PROTOCOL_VERSION, - 0, sizeof(*response)); - if (!operation) - return -ENOMEM; + ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_PROTOCOL_VERSION, + NULL, 0, &response, sizeof(response)); - /* Synchronous operation--no callback */ - ret = gb_operation_request_send(operation, NULL); - if (ret) { - pr_err("version operation failed (%d)\n", ret); - goto out; - } + if (ret) + return ret; - 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", - response->major, GB_PWM_VERSION_MAJOR); - ret = -ENOTSUPP; - goto out; + response.major, GB_PWM_VERSION_MAJOR); + return -ENOTSUPP; } - pwmc->version_major = response->major; - pwmc->version_minor = response->minor; -out: - gb_operation_destroy(operation); - - return ret; + pwmc->version_major = response.major; + pwmc->version_minor = response.minor; + return 0; } static int gb_pwm_count_operation(struct gb_pwm_chip *pwmc) { - struct gb_connection *connection = pwmc->connection; - struct gb_operation *operation; - struct gb_pwm_count_response *response; + struct gb_pwm_count_response response; int ret; - /* pwm count request has no payload */ - operation = gb_operation_create(connection, GB_PWM_TYPE_PWM_COUNT, - 0, sizeof(*response)); - if (!operation) - return -ENOMEM; - - /* 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; + ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_PWM_COUNT, + NULL, 0, &response, sizeof(response)); + if (ret) + return ret; + pwmc->pwm_max = response.count; + return 0; } static int gb_pwm_activate_operation(struct gb_pwm_chip *pwmc, u8 which) { - struct gb_connection *connection = pwmc->connection; - struct gb_operation *operation; - struct gb_pwm_activate_request *request; - int ret; + struct gb_pwm_activate_request request; if (which > pwmc->pwm_max) return -EINVAL; - /* activate response has no payload */ - operation = gb_operation_create(connection, GB_PWM_TYPE_ACTIVATE, - sizeof(*request), 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; + request.which = which; + return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_ACTIVATE, + &request, sizeof(request), NULL, 0); } static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc, u8 which) { - struct gb_connection *connection = pwmc->connection; - struct gb_operation *operation; - struct gb_pwm_deactivate_request *request; - int ret; + struct gb_pwm_deactivate_request request; if (which > pwmc->pwm_max) return -EINVAL; - /* deactivate response has no payload */ - operation = gb_operation_create(connection, GB_PWM_TYPE_DEACTIVATE, - sizeof(*request), 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; + request.which = which; + return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_DEACTIVATE, + &request, sizeof(request), NULL, 0); } static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc, u8 which, u32 duty, u32 period) { - struct gb_connection *connection = pwmc->connection; - struct gb_operation *operation; - struct gb_pwm_config_request *request; - int ret; + struct gb_pwm_config_request request; if (which > pwmc->pwm_max) return -EINVAL; - operation = gb_operation_create(connection, GB_PWM_TYPE_CONFIG, - sizeof(*request), 0); - if (!operation) - return -ENOMEM; - request = operation->request->payload; - 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; + request.which = which; + request.duty = duty; + request.period = period; + return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_CONFIG, + &request, sizeof(request), NULL, 0); } static int gb_pwm_set_polarity_operation(struct gb_pwm_chip *pwmc, u8 which, u8 polarity) { - struct gb_connection *connection = pwmc->connection; - struct gb_operation *operation; - struct gb_pwm_polarity_request *request; - int ret; + struct gb_pwm_polarity_request request; if (which > pwmc->pwm_max) return -EINVAL; - operation = gb_operation_create(connection, GB_PWM_TYPE_POLARITY, - sizeof(*request), 0); - if (!operation) - return -ENOMEM; - 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; + request.which = which; + request.polarity = polarity; + return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_POLARITY, + &request, sizeof(request), NULL, 0); } static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc, u8 which) { - struct gb_connection *connection = pwmc->connection; - struct gb_operation *operation; - struct gb_pwm_enable_request *request; - int ret; + struct gb_pwm_enable_request request; if (which > pwmc->pwm_max) return -EINVAL; - /* enable response has no payload */ - operation = gb_operation_create(connection, GB_PWM_TYPE_ENABLE, - sizeof(*request), 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; + request.which = which; + return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_ENABLE, + &request, sizeof(request), NULL, 0); } static int gb_pwm_disable_operation(struct gb_pwm_chip *pwmc, u8 which) { - struct gb_connection *connection = pwmc->connection; - struct gb_operation *operation; - struct gb_pwm_disable_request *request; - int ret; + struct gb_pwm_disable_request request; if (which > pwmc->pwm_max) return -EINVAL; - /* disable response has no payload */ - operation = gb_operation_create(connection, GB_PWM_TYPE_DISABLE, - sizeof(*request), 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; + request.which = which; + return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_DISABLE, + &request, sizeof(request), NULL, 0); } static int gb_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)