trigger.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* The industrial I/O core, trigger handling functions
  2. *
  3. * Copyright (c) 2008 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. #include <linux/irq.h>
  10. #include <linux/module.h>
  11. #ifndef _IIO_TRIGGER_H_
  12. #define _IIO_TRIGGER_H_
  13. #ifdef CONFIG_IIO_TRIGGER
  14. struct iio_subirq {
  15. bool enabled;
  16. };
  17. /**
  18. * struct iio_trigger_ops - operations structure for an iio_trigger.
  19. * @owner: used to monitor usage count of the trigger.
  20. * @set_trigger_state: switch on/off the trigger on demand
  21. * @try_reenable: function to reenable the trigger when the
  22. * use count is zero (may be NULL)
  23. * @validate_device: function to validate the device when the
  24. * current trigger gets changed.
  25. *
  26. * This is typically static const within a driver and shared by
  27. * instances of a given device.
  28. **/
  29. struct iio_trigger_ops {
  30. struct module *owner;
  31. int (*set_trigger_state)(struct iio_trigger *trig, bool state);
  32. int (*try_reenable)(struct iio_trigger *trig);
  33. int (*validate_device)(struct iio_trigger *trig,
  34. struct iio_dev *indio_dev);
  35. };
  36. /**
  37. * struct iio_trigger - industrial I/O trigger device
  38. * @ops: [DRIVER] operations structure
  39. * @id: [INTERN] unique id number
  40. * @name: [DRIVER] unique name
  41. * @dev: [DRIVER] associated device (if relevant)
  42. * @private_data: [DRIVER] device specific data
  43. * @list: [INTERN] used in maintenance of global trigger list
  44. * @alloc_list: [DRIVER] used for driver specific trigger list
  45. * @use_count: use count for the trigger
  46. * @subirq_chip: [INTERN] associate 'virtual' irq chip.
  47. * @subirq_base: [INTERN] base number for irqs provided by trigger.
  48. * @subirqs: [INTERN] information about the 'child' irqs.
  49. * @pool: [INTERN] bitmap of irqs currently in use.
  50. * @pool_lock: [INTERN] protection of the irq pool.
  51. **/
  52. struct iio_trigger {
  53. const struct iio_trigger_ops *ops;
  54. int id;
  55. const char *name;
  56. struct device dev;
  57. void *private_data;
  58. struct list_head list;
  59. struct list_head alloc_list;
  60. int use_count;
  61. struct irq_chip subirq_chip;
  62. int subirq_base;
  63. struct iio_subirq subirqs[CONFIG_IIO_CONSUMERS_PER_TRIGGER];
  64. unsigned long pool[BITS_TO_LONGS(CONFIG_IIO_CONSUMERS_PER_TRIGGER)];
  65. struct mutex pool_lock;
  66. };
  67. static inline struct iio_trigger *to_iio_trigger(struct device *d)
  68. {
  69. return container_of(d, struct iio_trigger, dev);
  70. }
  71. static inline void iio_trigger_put(struct iio_trigger *trig)
  72. {
  73. module_put(trig->ops->owner);
  74. put_device(&trig->dev);
  75. }
  76. static inline void iio_trigger_get(struct iio_trigger *trig)
  77. {
  78. get_device(&trig->dev);
  79. __module_get(trig->ops->owner);
  80. }
  81. /**
  82. * iio_device_set_drvdata() - Set trigger driver data
  83. * @trig: IIO trigger structure
  84. * @data: Driver specific data
  85. *
  86. * Allows to attach an arbitrary pointer to an IIO trigger, which can later be
  87. * retrieved by iio_trigger_get_drvdata().
  88. */
  89. static inline void iio_trigger_set_drvdata(struct iio_trigger *trig, void *data)
  90. {
  91. trig->private_data = data;
  92. }
  93. /**
  94. * iio_trigger_get_drvdata() - Get trigger driver data
  95. * @trig: IIO trigger structure
  96. *
  97. * Returns the data previously set with iio_trigger_set_drvdata()
  98. */
  99. static inline void *iio_trigger_get_drvdata(struct iio_trigger *trig)
  100. {
  101. return trig->private_data;
  102. }
  103. /**
  104. * iio_trigger_register() - register a trigger with the IIO core
  105. * @trig_info: trigger to be registered
  106. **/
  107. int iio_trigger_register(struct iio_trigger *trig_info);
  108. /**
  109. * iio_trigger_unregister() - unregister a trigger from the core
  110. * @trig_info: trigger to be unregistered
  111. **/
  112. void iio_trigger_unregister(struct iio_trigger *trig_info);
  113. /**
  114. * iio_trigger_poll() - called on a trigger occurring
  115. * @trig: trigger which occurred
  116. * @time: timestamp when trigger occurred
  117. *
  118. * Typically called in relevant hardware interrupt handler.
  119. **/
  120. void iio_trigger_poll(struct iio_trigger *trig, s64 time);
  121. void iio_trigger_poll_chained(struct iio_trigger *trig, s64 time);
  122. irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private);
  123. __printf(1, 2) struct iio_trigger *iio_trigger_alloc(const char *fmt, ...);
  124. void iio_trigger_free(struct iio_trigger *trig);
  125. #else
  126. struct iio_trigger;
  127. struct iio_trigger_ops;
  128. #endif
  129. #endif /* _IIO_TRIGGER_H_ */