Jonathan Cameron | af5046a | 2011-10-26 17:41:32 +0100 | [diff] [blame] | 1 | /* The industrial I/O - event passing to userspace |
| 2 | * |
| 3 | * Copyright (c) 2008-2011 Jonathan Cameron |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | */ |
| 9 | #ifndef _IIO_EVENTS_H_ |
| 10 | #define _IIO_EVENTS_H_ |
| 11 | |
| 12 | #include <linux/ioctl.h> |
Lars-Peter Clausen | 65d5ff8 | 2011-10-26 17:41:33 +0100 | [diff] [blame] | 13 | #include <linux/types.h> |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 14 | #include <linux/iio/types.h> |
Jonathan Cameron | af5046a | 2011-10-26 17:41:32 +0100 | [diff] [blame] | 15 | |
| 16 | /** |
| 17 | * struct iio_event_data - The actual event being pushed to userspace |
| 18 | * @id: event identifier |
| 19 | * @timestamp: best estimate of time of event occurrence (often from |
| 20 | * the interrupt handler) |
| 21 | */ |
| 22 | struct iio_event_data { |
Lars-Peter Clausen | 65d5ff8 | 2011-10-26 17:41:33 +0100 | [diff] [blame] | 23 | __u64 id; |
| 24 | __s64 timestamp; |
Jonathan Cameron | af5046a | 2011-10-26 17:41:32 +0100 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | #define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int) |
| 28 | |
Lars-Peter Clausen | 3014cd9 | 2011-10-26 17:41:34 +0100 | [diff] [blame] | 29 | /** |
| 30 | * IIO_EVENT_CODE() - create event identifier |
| 31 | * @chan_type: Type of the channel. Should be one of enum iio_chan_type. |
| 32 | * @diff: Whether the event is for an differential channel or not. |
| 33 | * @modifier: Modifier for the channel. Should be one of enum iio_modifier. |
| 34 | * @direction: Direction of the event. One of enum iio_event_direction. |
Peter Meerwald | fb1c4bc | 2012-06-15 19:25:28 +0200 | [diff] [blame] | 35 | * @type: Type of the event. Should be one of enum iio_event_type. |
Lars-Peter Clausen | 3014cd9 | 2011-10-26 17:41:34 +0100 | [diff] [blame] | 36 | * @chan: Channel number for non-differential channels. |
| 37 | * @chan1: First channel number for differential channels. |
| 38 | * @chan2: Second channel number for differential channels. |
| 39 | */ |
| 40 | |
Jonathan Cameron | af5046a | 2011-10-26 17:41:32 +0100 | [diff] [blame] | 41 | #define IIO_EVENT_CODE(chan_type, diff, modifier, direction, \ |
| 42 | type, chan, chan1, chan2) \ |
| 43 | (((u64)type << 56) | ((u64)diff << 55) | \ |
| 44 | ((u64)direction << 48) | ((u64)modifier << 40) | \ |
Lars-Peter Clausen | 19c2aed | 2011-11-02 09:40:01 +0100 | [diff] [blame] | 45 | ((u64)chan_type << 32) | (((u16)chan2) << 16) | ((u16)chan1) | \ |
| 46 | ((u16)chan)) |
Jonathan Cameron | af5046a | 2011-10-26 17:41:32 +0100 | [diff] [blame] | 47 | |
| 48 | |
Lars-Peter Clausen | 3014cd9 | 2011-10-26 17:41:34 +0100 | [diff] [blame] | 49 | /** |
| 50 | * IIO_MOD_EVENT_CODE() - create event identifier for modified channels |
| 51 | * @chan_type: Type of the channel. Should be one of enum iio_chan_type. |
| 52 | * @number: Channel number. |
| 53 | * @modifier: Modifier for the channel. Should be one of enum iio_modifier. |
Peter Meerwald | fb1c4bc | 2012-06-15 19:25:28 +0200 | [diff] [blame] | 54 | * @type: Type of the event. Should be one of enum iio_event_type. |
Lars-Peter Clausen | 3014cd9 | 2011-10-26 17:41:34 +0100 | [diff] [blame] | 55 | * @direction: Direction of the event. One of enum iio_event_direction. |
| 56 | */ |
Jonathan Cameron | af5046a | 2011-10-26 17:41:32 +0100 | [diff] [blame] | 57 | |
Lars-Peter Clausen | 3014cd9 | 2011-10-26 17:41:34 +0100 | [diff] [blame] | 58 | #define IIO_MOD_EVENT_CODE(chan_type, number, modifier, \ |
| 59 | type, direction) \ |
| 60 | IIO_EVENT_CODE(chan_type, 0, modifier, direction, type, number, 0, 0) |
| 61 | |
| 62 | /** |
| 63 | * IIO_UNMOD_EVENT_CODE() - create event identifier for unmodified channels |
| 64 | * @chan_type: Type of the channel. Should be one of enum iio_chan_type. |
| 65 | * @number: Channel number. |
Peter Meerwald | fb1c4bc | 2012-06-15 19:25:28 +0200 | [diff] [blame] | 66 | * @type: Type of the event. Should be one of enum iio_event_type. |
Lars-Peter Clausen | 3014cd9 | 2011-10-26 17:41:34 +0100 | [diff] [blame] | 67 | * @direction: Direction of the event. One of enum iio_event_direction. |
| 68 | */ |
| 69 | |
| 70 | #define IIO_UNMOD_EVENT_CODE(chan_type, number, type, direction) \ |
| 71 | IIO_EVENT_CODE(chan_type, 0, 0, direction, type, number, 0, 0) |
Jonathan Cameron | af5046a | 2011-10-26 17:41:32 +0100 | [diff] [blame] | 72 | |
| 73 | #define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF) |
| 74 | |
| 75 | #define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xCF) |
| 76 | |
| 77 | #define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF) |
| 78 | |
| 79 | /* Event code number extraction depends on which type of event we have. |
| 80 | * Perhaps review this function in the future*/ |
Lars-Peter Clausen | da36716 | 2012-02-13 10:25:32 +0100 | [diff] [blame] | 81 | #define IIO_EVENT_CODE_EXTRACT_CHAN(mask) ((__s16)(mask & 0xFFFF)) |
Lars-Peter Clausen | f30f929 | 2012-02-13 10:25:33 +0100 | [diff] [blame] | 82 | #define IIO_EVENT_CODE_EXTRACT_CHAN2(mask) ((__s16)(((mask) >> 16) & 0xFFFF)) |
Jonathan Cameron | af5046a | 2011-10-26 17:41:32 +0100 | [diff] [blame] | 83 | |
| 84 | #define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF) |
Lars-Peter Clausen | f30f929 | 2012-02-13 10:25:33 +0100 | [diff] [blame] | 85 | #define IIO_EVENT_CODE_EXTRACT_DIFF(mask) (((mask) >> 55) & 0x1) |
Jonathan Cameron | af5046a | 2011-10-26 17:41:32 +0100 | [diff] [blame] | 86 | |
| 87 | #endif |