drivers/iio/industrialio-trigger.c
Source file repositories/reference/linux-study-clean/drivers/iio/industrialio-trigger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/industrialio-trigger.c- Extension
.c- Size
- 21197 bytes
- Lines
- 797
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cleanup.hlinux/kernel.hlinux/idr.hlinux/err.hlinux/device.hlinux/interrupt.hlinux/list.hlinux/slab.hlinux/iio/iio.hlinux/iio/iio-opaque.hlinux/iio/trigger.hiio_core.hiio_core_trigger.hlinux/iio/trigger_consumer.h
Detected Declarations
function name_showfunction iio_trigger_registerfunction iio_trigger_unregisterfunction iio_trigger_set_immutablefunction iio_reenable_work_fnfunction Forfunction iio_trigger_pollfunction iio_trigger_generic_data_rdy_pollfunction iio_trigger_poll_nestedfunction iio_trigger_notify_donefunction iio_trigger_get_irqfunction scoped_guardfunction iio_trigger_put_irqfunction iio_trigger_attach_poll_funcfunction iio_trigger_detach_poll_funcfunction iio_pollfunc_store_timefunction irqreturn_tfunction iio_dealloc_pollfuncfunction current_trigger_showfunction current_trigger_storefunction scoped_guardfunction iio_trig_releasefunction iio_trig_subirqmaskfunction iio_trig_subirqunmaskfunction __printffunction iio_trigger_freefunction devm_iio_trigger_releasefunction devm_iio_trigger_unregfunction iio_trigger_registerfunction iio_trigger_using_ownfunction iio_validate_own_triggerfunction iio_trigger_validate_own_devicefunction iio_device_register_trigger_consumerfunction iio_device_unregister_trigger_consumerfunction iio_device_suspend_triggeringfunction iio_device_resume_triggeringexport iio_trigger_registerexport iio_trigger_unregisterexport iio_trigger_set_immutableexport iio_trigger_pollexport iio_trigger_generic_data_rdy_pollexport iio_trigger_poll_nestedexport iio_trigger_notify_doneexport iio_pollfunc_store_timeexport iio_alloc_pollfuncexport iio_dealloc_pollfuncexport __iio_trigger_allocexport iio_trigger_free
Annotated Snippet
ret = device_add(&trig_info->dev);
if (ret)
goto error_unregister_id;
/* Add to list of available triggers held by the IIO core */
scoped_guard(mutex, &iio_trigger_list_lock) {
if (__iio_trigger_find_by_name(trig_info->name)) {
pr_err("Duplicate trigger name '%s'\n", trig_info->name);
ret = -EEXIST;
goto error_device_del;
}
list_add_tail(&trig_info->list, &iio_trigger_list);
}
return 0;
error_device_del:
device_del(&trig_info->dev);
error_unregister_id:
ida_free(&iio_trigger_ida, trig_info->id);
return ret;
}
EXPORT_SYMBOL(iio_trigger_register);
void iio_trigger_unregister(struct iio_trigger *trig_info)
{
scoped_guard(mutex, &iio_trigger_list_lock)
list_del(&trig_info->list);
ida_free(&iio_trigger_ida, trig_info->id);
/* Possible issue in here */
device_del(&trig_info->dev);
}
EXPORT_SYMBOL(iio_trigger_unregister);
int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *trig)
{
struct iio_dev_opaque *iio_dev_opaque;
if (!indio_dev || !trig)
return -EINVAL;
iio_dev_opaque = to_iio_dev_opaque(indio_dev);
guard(mutex)(&iio_dev_opaque->mlock);
WARN_ON(iio_dev_opaque->trig_readonly);
indio_dev->trig = iio_trigger_get(trig);
iio_dev_opaque->trig_readonly = true;
return 0;
}
EXPORT_SYMBOL(iio_trigger_set_immutable);
/* Search for trigger by name, assuming iio_trigger_list_lock held */
static struct iio_trigger *__iio_trigger_find_by_name(const char *name)
{
struct iio_trigger *iter;
list_for_each_entry(iter, &iio_trigger_list, list)
if (!strcmp(iter->name, name))
return iter;
return NULL;
}
static struct iio_trigger *iio_trigger_acquire_by_name(const char *name)
{
struct iio_trigger *iter;
guard(mutex)(&iio_trigger_list_lock);
list_for_each_entry(iter, &iio_trigger_list, list)
if (sysfs_streq(iter->name, name))
return iio_trigger_get(iter);
return NULL;
}
static void iio_reenable_work_fn(struct work_struct *work)
{
struct iio_trigger *trig = container_of(work, struct iio_trigger,
reenable_work);
/*
* This 'might' occur after the trigger state is set to disabled -
* in that case the driver should skip reenabling.
*/
trig->ops->reenable(trig);
}
/*
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/kernel.h`, `linux/idr.h`, `linux/err.h`, `linux/device.h`, `linux/interrupt.h`, `linux/list.h`, `linux/slab.h`.
- Detected declarations: `function name_show`, `function iio_trigger_register`, `function iio_trigger_unregister`, `function iio_trigger_set_immutable`, `function iio_reenable_work_fn`, `function For`, `function iio_trigger_poll`, `function iio_trigger_generic_data_rdy_poll`, `function iio_trigger_poll_nested`, `function iio_trigger_notify_done`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.