diff options
author | Julian Andres Klode <jak@jak-linux.org> | 2011-09-27 19:00:50 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-09-29 17:41:33 -0700 |
commit | 8517e879e0d11a277275616b9e1c749afe2fceff (patch) | |
tree | 4b61aad47d6108541c1e8e2d99fc020299a174ab /drivers/staging/nvec | |
parent | e7c40851fd7989dad297988b6343f4e3cb687292 (diff) |
staging: nvec: Add is_event() and size() functions for nvec_msg
Add functions nvec_msg_is_event() and nvec_msg_size() which
do just what the say: tell whether the message is an event,
and getting the size of the message.
Signed-off-by: Julian Andres Klode <jak@jak-linux.org>
Acked-by: Marc Dietrich <marvin24@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/nvec')
-rw-r--r-- | drivers/staging/nvec/nvec.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c index 17f5abfcb78..8e97e2d7ac3 100644 --- a/drivers/staging/nvec/nvec.c +++ b/drivers/staging/nvec/nvec.c @@ -114,6 +114,37 @@ static void nvec_msg_free(struct nvec_chip *nvec, struct nvec_msg *msg) atomic_set(&msg->used, 0); } +/** + * nvec_msg_is_event - Return %true if @msg is an event + * @msg: A message + */ +static bool nvec_msg_is_event(struct nvec_msg *msg) +{ + return msg->data[0] >> 7; +} + +/** + * nvec_msg_size - Get the size of a message + * @msg: The message to get the size for + * + * This only works for received messages, not for outgoing messages. + */ +static size_t nvec_msg_size(struct nvec_msg *msg) +{ + bool is_event = nvec_msg_is_event(msg); + int event_length = (msg->data[0] & 0x60) >> 5; + + /* for variable size, payload size in byte 1 + count (1) + cmd (1) */ + if (!is_event || event_length == NVEC_VAR_SIZE) + return (msg->pos || msg->size) ? (msg->data[1] + 2) : 0; + else if (event_length == NVEC_2BYTES) + return 2; + else if (event_length == NVEC_3BYTES) + return 3; + else + return 0; +} + static void nvec_gpio_set_value(struct nvec_chip *nvec, int value) { dev_dbg(nvec->dev, "GPIO changed from %u to %u\n", |