triggers.rst 3.0 KB

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