1 /* The industrial I/O - event passing to userspace
3 * Copyright (c) 2008-2011 Jonathan Cameron
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.
10 #define _IIO_EVENTS_H_
12 #include <linux/ioctl.h>
13 #include <linux/types.h>
14 #include <linux/iio/types.h>
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)
22 struct iio_event_data {
27 #define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int)
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.
35 * @type: Type of the event. Should be one of enum iio_event_type.
36 * @chan: Channel number for non-differential channels.
37 * @chan1: First channel number for differential channels.
38 * @chan2: Second channel number for differential channels.
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) | \
45 ((u64)chan_type << 32) | (((u16)chan2) << 16) | ((u16)chan1) | \
49 #define IIO_EV_DIR_MAX 4
50 #define IIO_EV_BIT(type, direction) \
51 (1 << (type*IIO_EV_DIR_MAX + direction))
54 * IIO_MOD_EVENT_CODE() - create event identifier for modified channels
55 * @chan_type: Type of the channel. Should be one of enum iio_chan_type.
56 * @number: Channel number.
57 * @modifier: Modifier for the channel. Should be one of enum iio_modifier.
58 * @type: Type of the event. Should be one of enum iio_event_type.
59 * @direction: Direction of the event. One of enum iio_event_direction.
62 #define IIO_MOD_EVENT_CODE(chan_type, number, modifier, \
64 IIO_EVENT_CODE(chan_type, 0, modifier, direction, type, number, 0, 0)
67 * IIO_UNMOD_EVENT_CODE() - create event identifier for unmodified channels
68 * @chan_type: Type of the channel. Should be one of enum iio_chan_type.
69 * @number: Channel number.
70 * @type: Type of the event. Should be one of enum iio_event_type.
71 * @direction: Direction of the event. One of enum iio_event_direction.
74 #define IIO_UNMOD_EVENT_CODE(chan_type, number, type, direction) \
75 IIO_EVENT_CODE(chan_type, 0, 0, direction, type, number, 0, 0)
77 #define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
79 #define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xCF)
81 #define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
83 /* Event code number extraction depends on which type of event we have.
84 * Perhaps review this function in the future*/
85 #define IIO_EVENT_CODE_EXTRACT_CHAN(mask) ((__s16)(mask & 0xFFFF))
86 #define IIO_EVENT_CODE_EXTRACT_CHAN2(mask) ((__s16)(((mask) >> 16) & 0xFFFF))
88 #define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF)
89 #define IIO_EVENT_CODE_EXTRACT_DIFF(mask) (((mask) >> 55) & 0x1)