events.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. enum iio_event_type {
  26. IIO_EV_TYPE_THRESH,
  27. IIO_EV_TYPE_MAG,
  28. IIO_EV_TYPE_ROC,
  29. IIO_EV_TYPE_THRESH_ADAPTIVE,
  30. IIO_EV_TYPE_MAG_ADAPTIVE,
  31. };
  32. enum iio_event_direction {
  33. IIO_EV_DIR_EITHER,
  34. IIO_EV_DIR_RISING,
  35. IIO_EV_DIR_FALLING,
  36. };
  37. /**
  38. * IIO_EVENT_CODE() - create event identifier
  39. * @chan_type: Type of the channel. Should be one of enum iio_chan_type.
  40. * @diff: Whether the event is for an differential channel or not.
  41. * @modifier: Modifier for the channel. Should be one of enum iio_modifier.
  42. * @direction: Direction of the event. One of enum iio_event_direction.
  43. * @type: Type of the event. Should be one of enum iio_event_type.
  44. * @chan: Channel number for non-differential channels.
  45. * @chan1: First channel number for differential channels.
  46. * @chan2: Second channel number for differential channels.
  47. */
  48. #define IIO_EVENT_CODE(chan_type, diff, modifier, direction, \
  49. type, chan, chan1, chan2) \
  50. (((u64)type << 56) | ((u64)diff << 55) | \
  51. ((u64)direction << 48) | ((u64)modifier << 40) | \
  52. ((u64)chan_type << 32) | (((u16)chan2) << 16) | ((u16)chan1) | \
  53. ((u16)chan))
  54. #define IIO_EV_DIR_MAX 4
  55. #define IIO_EV_BIT(type, direction) \
  56. (1 << (type*IIO_EV_DIR_MAX + direction))
  57. /**
  58. * IIO_MOD_EVENT_CODE() - create event identifier for modified channels
  59. * @chan_type: Type of the channel. Should be one of enum iio_chan_type.
  60. * @number: Channel number.
  61. * @modifier: Modifier for the channel. Should be one of enum iio_modifier.
  62. * @type: Type of the event. Should be one of enum iio_event_type.
  63. * @direction: Direction of the event. One of enum iio_event_direction.
  64. */
  65. #define IIO_MOD_EVENT_CODE(chan_type, number, modifier, \
  66. type, direction) \
  67. IIO_EVENT_CODE(chan_type, 0, modifier, direction, type, number, 0, 0)
  68. /**
  69. * IIO_UNMOD_EVENT_CODE() - create event identifier for unmodified channels
  70. * @chan_type: Type of the channel. Should be one of enum iio_chan_type.
  71. * @number: Channel number.
  72. * @type: Type of the event. Should be one of enum iio_event_type.
  73. * @direction: Direction of the event. One of enum iio_event_direction.
  74. */
  75. #define IIO_UNMOD_EVENT_CODE(chan_type, number, type, direction) \
  76. IIO_EVENT_CODE(chan_type, 0, 0, direction, type, number, 0, 0)
  77. #define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
  78. #define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xCF)
  79. #define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
  80. /* Event code number extraction depends on which type of event we have.
  81. * Perhaps review this function in the future*/
  82. #define IIO_EVENT_CODE_EXTRACT_CHAN(mask) ((__s16)(mask & 0xFFFF))
  83. #define IIO_EVENT_CODE_EXTRACT_CHAN2(mask) ((__s16)(((mask) >> 16) & 0xFFFF))
  84. #define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF)
  85. #define IIO_EVENT_CODE_EXTRACT_DIFF(mask) (((mask) >> 55) & 0x1)
  86. #endif