Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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