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