triggers.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ========
  2. Triggers
  3. ========
  4. * struct iio_trigger — industrial I/O trigger device
  5. * :c:func:`devm_iio_trigger_alloc` — Resource-managed iio_trigger_alloc
  6. * :c:func:`devm_iio_trigger_register` — Resource-managed iio_trigger_register
  7. iio_trigger_unregister
  8. * :c:func:`iio_trigger_validate_own_device` — Check if a trigger and IIO
  9. device belong to the same device
  10. In many situations it is useful for a driver to be able to capture data based
  11. on some external event (trigger) as opposed to periodically polling for data.
  12. An IIO trigger can be provided by a device driver that also has an IIO device
  13. based on hardware generated events (e.g. data ready or threshold exceeded) or
  14. provided by a separate driver from an independent interrupt source (e.g. GPIO
  15. line connected to some external system, timer interrupt or user space writing
  16. a specific file in sysfs). A trigger may initiate data capture for a number of
  17. sensors and also it may be completely unrelated to the sensor itself.
  18. IIO trigger sysfs interface
  19. ===========================
  20. There are two locations in sysfs related to triggers:
  21. * :file:`/sys/bus/iio/devices/trigger{Y}/*`, this file is created once an
  22. IIO trigger is registered with the IIO core and corresponds to trigger
  23. with index Y.
  24. Because triggers can be very different depending on type there are few
  25. standard attributes that we can describe here:
  26. * :file:`name`, trigger name that can be later used for association with a
  27. device.
  28. * :file:`sampling_frequency`, some timer based triggers use this attribute to
  29. specify the frequency for trigger calls.
  30. * :file:`/sys/bus/iio/devices/iio:device{X}/trigger/*`, this directory is
  31. created once the device supports a triggered buffer. We can associate a
  32. trigger with our device by writing the trigger's name in the
  33. :file:`current_trigger` file.
  34. IIO trigger setup
  35. =================
  36. Let's see a simple example of how to setup a trigger to be used by a driver::
  37. struct iio_trigger_ops trigger_ops = {
  38. .set_trigger_state = sample_trigger_state,
  39. .validate_device = sample_validate_device,
  40. }
  41. struct iio_trigger *trig;
  42. /* first, allocate memory for our trigger */
  43. trig = iio_trigger_alloc(dev, "trig-%s-%d", name, idx);
  44. /* setup trigger operations field */
  45. trig->ops = &trigger_ops;
  46. /* now register the trigger with the IIO core */
  47. iio_trigger_register(trig);
  48. IIO trigger ops
  49. ===============
  50. * struct iio_trigger_ops — operations structure for an iio_trigger.
  51. Notice that a trigger has a set of operations attached:
  52. * :file:`set_trigger_state`, switch the trigger on/off on demand.
  53. * :file:`validate_device`, function to validate the device when the current
  54. trigger gets changed.
  55. More details
  56. ============
  57. .. kernel-doc:: include/linux/iio/trigger.h
  58. .. kernel-doc:: drivers/iio/industrialio-trigger.c
  59. :export: