events.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include <linux/ioctl.h>
  12. #include <linux/types.h>
  13. #include <linux/iio/types.h>
  14. /**
  15. * struct iio_event_data - The actual event being pushed to userspace
  16. * @id: event identifier
  17. * @timestamp: best estimate of time of event occurrence (often from
  18. * the interrupt handler)
  19. */
  20. struct iio_event_data {
  21. __u64 id;
  22. __s64 timestamp;
  23. };
  24. #define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int)
  25. /**
  26. * IIO_EVENT_CODE() - create event identifier
  27. * @chan_type: Type of the channel. Should be one of enum iio_chan_type.
  28. * @diff: Whether the event is for an differential channel or not.
  29. * @modifier: Modifier for the channel. Should be one of enum iio_modifier.
  30. * @direction: Direction of the event. One of enum iio_event_direction.
  31. * @type: Type of the event. Should be one of enum iio_event_type.
  32. * @chan: Channel number for non-differential channels.
  33. * @chan1: First channel number for differential channels.
  34. * @chan2: Second channel number for differential channels.
  35. */
  36. #define IIO_EVENT_CODE(chan_type, diff, modifier, direction, \
  37. type, chan, chan1, chan2) \
  38. (((u64)type << 56) | ((u64)diff << 55) | \
  39. ((u64)direction << 48) | ((u64)modifier << 40) | \
  40. ((u64)chan_type << 32) | (((u16)chan2) << 16) | ((u16)chan1) | \
  41. ((u16)chan))
  42. /**
  43. * IIO_MOD_EVENT_CODE() - create event identifier for modified channels
  44. * @chan_type: Type of the channel. Should be one of enum iio_chan_type.
  45. * @number: Channel number.
  46. * @modifier: Modifier for the channel. Should be one of enum iio_modifier.
  47. * @type: Type of the event. Should be one of enum iio_event_type.
  48. * @direction: Direction of the event. One of enum iio_event_direction.
  49. */
  50. #define IIO_MOD_EVENT_CODE(chan_type, number, modifier, \
  51. type, direction) \
  52. IIO_EVENT_CODE(chan_type, 0, modifier, direction, type, number, 0, 0)
  53. /**
  54. * IIO_UNMOD_EVENT_CODE() - create event identifier for unmodified channels
  55. * @chan_type: Type of the channel. Should be one of enum iio_chan_type.
  56. * @number: Channel number.
  57. * @type: Type of the event. Should be one of enum iio_event_type.
  58. * @direction: Direction of the event. One of enum iio_event_direction.
  59. */
  60. #define IIO_UNMOD_EVENT_CODE(chan_type, number, type, direction) \
  61. IIO_EVENT_CODE(chan_type, 0, 0, direction, type, number, 0, 0)
  62. #define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
  63. #define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0x7F)
  64. #define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
  65. /* Event code number extraction depends on which type of event we have.
  66. * Perhaps review this function in the future*/
  67. #define IIO_EVENT_CODE_EXTRACT_CHAN(mask) ((__s16)(mask & 0xFFFF))
  68. #define IIO_EVENT_CODE_EXTRACT_CHAN2(mask) ((__s16)(((mask) >> 16) & 0xFFFF))
  69. #define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF)
  70. #define IIO_EVENT_CODE_EXTRACT_DIFF(mask) (((mask) >> 55) & 0x1)
  71. #endif