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 /* 10 * TODO: This header file should be moved to external/kernel-headers/original. 11 */ 12 #ifndef _IIO_EVENTS_H_ 13 #define _IIO_EVENTS_H_ 14 15 #include <linux/ioctl.h> 16 #include <linux/types.h> 17 #include "types.h" 18 19 /** 20 * struct iio_event_data - The actual event being pushed to userspace 21 * @id: event identifier 22 * @timestamp: best estimate of time of event occurrence (often from 23 * the interrupt handler) 24 */ 25 struct iio_event_data { 26 __u64 id; 27 __s64 timestamp; 28 }; 29 30 #define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int) 31 32 enum iio_event_type { 33 IIO_EV_TYPE_THRESH, 34 IIO_EV_TYPE_MAG, 35 IIO_EV_TYPE_ROC, 36 IIO_EV_TYPE_THRESH_ADAPTIVE, 37 IIO_EV_TYPE_MAG_ADAPTIVE, 38 }; 39 40 enum iio_event_direction { 41 IIO_EV_DIR_EITHER, 42 IIO_EV_DIR_RISING, 43 IIO_EV_DIR_FALLING, 44 }; 45 46 /** 47 * IIO_EVENT_CODE() - create event identifier 48 * @chan_type: Type of the channel. Should be one of enum iio_chan_type. 49 * @diff: Whether the event is for an differential channel or not. 50 * @modifier: Modifier for the channel. Should be one of enum iio_modifier. 51 * @direction: Direction of the event. One of enum iio_event_direction. 52 * @type: Type of the event. Should be one enum iio_event_type. 53 * @chan: Channel number for non-differential channels. 54 * @chan1: First channel number for differential channels. 55 * @chan2: Second channel number for differential channels. 56 */ 57 58 #define IIO_EVENT_CODE(chan_type, diff, modifier, direction, \ 59 type, chan, chan1, chan2) \ 60 (((u64)type << 56) | ((u64)diff << 55) | \ 61 ((u64)direction << 48) | ((u64)modifier << 40) | \ 62 ((u64)chan_type << 32) | (((u16)chan2) << 16) | ((u16)chan1) | \ 63 ((u16)chan)) 64 65 66 #define IIO_EV_DIR_MAX 4 67 #define IIO_EV_BIT(type, direction) \ 68 (1 << (type*IIO_EV_DIR_MAX + direction)) 69 70 /** 71 * IIO_MOD_EVENT_CODE() - create event identifier for modified channels 72 * @chan_type: Type of the channel. Should be one of enum iio_chan_type. 73 * @number: Channel number. 74 * @modifier: Modifier for the channel. Should be one of enum iio_modifier. 75 * @type: Type of the event. Should be one enum iio_event_type. 76 * @direction: Direction of the event. One of enum iio_event_direction. 77 */ 78 79 #define IIO_MOD_EVENT_CODE(chan_type, number, modifier, \ 80 type, direction) \ 81 IIO_EVENT_CODE(chan_type, 0, modifier, direction, type, number, 0, 0) 82 83 /** 84 * IIO_UNMOD_EVENT_CODE() - create event identifier for unmodified channels 85 * @chan_type: Type of the channel. Should be one of enum iio_chan_type. 86 * @number: Channel number. 87 * @type: Type of the event. Should be one enum iio_event_type. 88 * @direction: Direction of the event. One of enum iio_event_direction. 89 */ 90 91 #define IIO_UNMOD_EVENT_CODE(chan_type, number, type, direction) \ 92 IIO_EVENT_CODE(chan_type, 0, 0, direction, type, number, 0, 0) 93 94 #define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF) 95 96 #define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xCF) 97 98 #define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF) 99 100 /* Event code number extraction depends on which type of event we have. 101 * Perhaps review this function in the future*/ 102 #define IIO_EVENT_CODE_EXTRACT_CHAN(mask) ((__s16)(mask & 0xFFFF)) 103 #define IIO_EVENT_CODE_EXTRACT_CHAN2(mask) ((__s16)(((mask) >> 16) & 0xFFFF)) 104 105 #define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF) 106 #define IIO_EVENT_CODE_EXTRACT_DIFF(mask) (((mask) >> 55) & 0x1) 107 108 #endif 109