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