112e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris/* The industrial I/O - event passing to userspace
212e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris *
312e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris * Copyright (c) 2008-2011 Jonathan Cameron
412e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris *
512e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris * This program is free software; you can redistribute it and/or modify it
612e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris * under the terms of the GNU General Public License version 2 as published by
712e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris * the Free Software Foundation.
812e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris */
912e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#ifndef _UAPI_IIO_EVENTS_H_
1012e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#define _UAPI_IIO_EVENTS_H_
1112e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris
1212e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#include <linux/ioctl.h>
1312e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#include <linux/types.h>
1412e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris
1512e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris/**
1612e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris * struct iio_event_data - The actual event being pushed to userspace
1712e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris * @id:		event identifier
1812e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris * @timestamp:	best estimate of time of event occurrence (often from
1912e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris *		the interrupt handler)
2012e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris */
2112e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferrisstruct iio_event_data {
2212e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris	__u64	id;
2312e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris	__s64	timestamp;
2412e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris};
2512e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris
2612e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int)
2712e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris
2812e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
2912e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris
3012e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0x7F)
3112e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris
3212e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
3312e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris
3412e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris/* Event code number extraction depends on which type of event we have.
3512e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris * Perhaps review this function in the future*/
3612e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#define IIO_EVENT_CODE_EXTRACT_CHAN(mask) ((__s16)(mask & 0xFFFF))
3712e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#define IIO_EVENT_CODE_EXTRACT_CHAN2(mask) ((__s16)(((mask) >> 16) & 0xFFFF))
3812e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris
3912e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF)
4012e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#define IIO_EVENT_CODE_EXTRACT_DIFF(mask) (((mask) >> 55) & 0x1)
4112e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris
4212e1f28cce28271eb109a5bae818a804f0c3bb27Christopher Ferris#endif /* _UAPI_IIO_EVENTS_H_ */
43