diff options
author | Viresh Kumar <viresh.kumar@linaro.org> | 2015-01-21 18:12:36 +0530 |
---|---|---|
committer | Greg Kroah-Hartman <greg@kroah.com> | 2015-01-22 11:29:39 +0800 |
commit | 36e79dec96f652110ae2b06bfcf9e67e1b770787 (patch) | |
tree | 333e41723bf440abb77c0dc1ea89cbacf198a480 /drivers/staging/greybus/protocol.h | |
parent | 530430b717f02843fe1f2e77e6f52a41e05d6c3a (diff) |
greybus: create get_version() routines with the help of a macro
This gets rid of lots of duplication of code.
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Alex Elder <elder@linaro.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Diffstat (limited to 'drivers/staging/greybus/protocol.h')
-rw-r--r-- | drivers/staging/greybus/protocol.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/drivers/staging/greybus/protocol.h b/drivers/staging/greybus/protocol.h index 8bda524a4d6d..e65cc18f4dfa 100644 --- a/drivers/staging/greybus/protocol.h +++ b/drivers/staging/greybus/protocol.h @@ -14,6 +14,12 @@ struct gb_operation; +/* version request has no payload */ +struct gb_protocol_version_response { + __u8 major; + __u8 minor; +}; + typedef int (*gb_connection_init_t)(struct gb_connection *); typedef void (*gb_connection_exit_t)(struct gb_connection *); typedef void (*gb_request_recv_t)(u8, struct gb_operation *); @@ -45,6 +51,11 @@ int gb_protocol_deregister(struct gb_protocol *protocol); __gb_protocol_register(protocol, THIS_MODULE) struct gb_protocol *gb_protocol_get(u8 id, u8 major, u8 minor); +int gb_protocol_get_version(struct gb_connection *connection, int type, + void *request, int request_size, + struct gb_protocol_version_response *response, + __u8 major); + void gb_protocol_put(struct gb_protocol *protocol); /* @@ -82,4 +93,27 @@ static void __exit protocol_exit(void) \ } \ module_exit(protocol_exit); +/* + * Macro to create get_version() routine for protocols + * @__device: name of the device struct + * @__protocol: name of protocol in CAPITALS + */ +#define define_get_version(__device, __protocol) \ +static int get_version(struct __device *dev) \ +{ \ + struct gb_protocol_version_response response; \ + int retval; \ + \ + retval = gb_protocol_get_version(dev->connection, \ + GB_##__protocol##_TYPE_PROTOCOL_VERSION,\ + NULL, 0, &response, \ + GB_##__protocol##_VERSION_MAJOR); \ + if (retval) \ + return retval; \ + \ + dev->version_major = response.major; \ + dev->version_minor = response.minor; \ + return 0; \ +} + #endif /* __PROTOCOL_H */ |