Commit | Line | Data |
---|---|---|
af5046af JC |
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> | |
65d5ff8d | 13 | #include <linux/types.h> |
06458e27 | 14 | #include <linux/iio/types.h> |
af5046af JC |
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 { | |
65d5ff8d LPC |
23 | __u64 id; |
24 | __s64 timestamp; | |
af5046af JC |
25 | }; |
26 | ||
27 | #define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int) | |
28 | ||
29 | enum iio_event_type { | |
30 | IIO_EV_TYPE_THRESH, | |
31 | IIO_EV_TYPE_MAG, | |
32 | IIO_EV_TYPE_ROC, | |
33 | IIO_EV_TYPE_THRESH_ADAPTIVE, | |
34 | IIO_EV_TYPE_MAG_ADAPTIVE, | |
35 | }; | |
36 | ||
37 | enum iio_event_direction { | |
38 | IIO_EV_DIR_EITHER, | |
39 | IIO_EV_DIR_RISING, | |
40 | IIO_EV_DIR_FALLING, | |
41 | }; | |
42 | ||
3014cd97 LPC |
43 | /** |
44 | * IIO_EVENT_CODE() - create event identifier | |
45 | * @chan_type: Type of the channel. Should be one of enum iio_chan_type. | |
46 | * @diff: Whether the event is for an differential channel or not. | |
47 | * @modifier: Modifier for the channel. Should be one of enum iio_modifier. | |
48 | * @direction: Direction of the event. One of enum iio_event_direction. | |
fb1c4bcd | 49 | * @type: Type of the event. Should be one of enum iio_event_type. |
3014cd97 LPC |
50 | * @chan: Channel number for non-differential channels. |
51 | * @chan1: First channel number for differential channels. | |
52 | * @chan2: Second channel number for differential channels. | |
53 | */ | |
54 | ||
af5046af JC |
55 | #define IIO_EVENT_CODE(chan_type, diff, modifier, direction, \ |
56 | type, chan, chan1, chan2) \ | |
57 | (((u64)type << 56) | ((u64)diff << 55) | \ | |
58 | ((u64)direction << 48) | ((u64)modifier << 40) | \ | |
19c2aedc LPC |
59 | ((u64)chan_type << 32) | (((u16)chan2) << 16) | ((u16)chan1) | \ |
60 | ((u16)chan)) | |
af5046af JC |
61 | |
62 | ||
63 | #define IIO_EV_DIR_MAX 4 | |
64 | #define IIO_EV_BIT(type, direction) \ | |
65 | (1 << (type*IIO_EV_DIR_MAX + direction)) | |
66 | ||
3014cd97 LPC |
67 | /** |
68 | * IIO_MOD_EVENT_CODE() - create event identifier for modified channels | |
69 | * @chan_type: Type of the channel. Should be one of enum iio_chan_type. | |
70 | * @number: Channel number. | |
71 | * @modifier: Modifier for the channel. Should be one of enum iio_modifier. | |
fb1c4bcd | 72 | * @type: Type of the event. Should be one of enum iio_event_type. |
3014cd97 LPC |
73 | * @direction: Direction of the event. One of enum iio_event_direction. |
74 | */ | |
75 | ||
76 | #define IIO_MOD_EVENT_CODE(chan_type, number, modifier, \ | |
af5046af | 77 | type, direction) \ |
3014cd97 LPC |
78 | IIO_EVENT_CODE(chan_type, 0, modifier, direction, type, number, 0, 0) |
79 | ||
80 | /** | |
81 | * IIO_UNMOD_EVENT_CODE() - create event identifier for unmodified channels | |
82 | * @chan_type: Type of the channel. Should be one of enum iio_chan_type. | |
83 | * @number: Channel number. | |
fb1c4bcd | 84 | * @type: Type of the event. Should be one of enum iio_event_type. |
3014cd97 LPC |
85 | * @direction: Direction of the event. One of enum iio_event_direction. |
86 | */ | |
af5046af | 87 | |
3014cd97 LPC |
88 | #define IIO_UNMOD_EVENT_CODE(chan_type, number, type, direction) \ |
89 | IIO_EVENT_CODE(chan_type, 0, 0, direction, type, number, 0, 0) | |
af5046af JC |
90 | |
91 | #define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF) | |
92 | ||
8743a139 | 93 | #define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0x7F) |
af5046af JC |
94 | |
95 | #define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF) | |
96 | ||
97 | /* Event code number extraction depends on which type of event we have. | |
98 | * Perhaps review this function in the future*/ | |
da367160 | 99 | #define IIO_EVENT_CODE_EXTRACT_CHAN(mask) ((__s16)(mask & 0xFFFF)) |
f30f929f | 100 | #define IIO_EVENT_CODE_EXTRACT_CHAN2(mask) ((__s16)(((mask) >> 16) & 0xFFFF)) |
af5046af JC |
101 | |
102 | #define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF) | |
f30f929f | 103 | #define IIO_EVENT_CODE_EXTRACT_DIFF(mask) (((mask) >> 55) & 0x1) |
af5046af JC |
104 | |
105 | #endif |