drivers/iio/common/st_sensors/st_sensors_core.c
Source file repositories/reference/linux-study-clean/drivers/iio/common/st_sensors/st_sensors_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/common/st_sensors/st_sensors_core.c- Extension
.c- Size
- 17546 bytes
- Lines
- 656
- 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.
- 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/kernel.hlinux/module.hlinux/slab.hlinux/delay.hlinux/iio/iio.hlinux/mutex.hlinux/property.hlinux/regulator/consumer.hlinux/regmap.hlinux/unaligned.hlinux/iio/common/st_sensors.hst_sensors_core.h
Detected Declarations
function st_sensors_write_data_with_maskfunction st_sensors_debugfs_reg_accessfunction st_sensors_match_odrfunction st_sensors_set_odrfunction st_sensors_match_fsfunction st_sensors_set_fullscalefunction st_sensors_set_enablefunction st_sensors_set_axis_enablefunction st_sensors_power_enablefunction st_sensors_set_drdy_int_pinfunction st_sensors_dev_name_probefunction st_sensors_init_sensorfunction st_sensors_set_dataready_irqfunction st_sensors_set_fullscale_by_gainfunction st_sensors_read_axis_datafunction st_sensors_read_info_rawfunction st_sensors_get_settings_indexfunction st_sensors_verify_idfunction st_sensors_sysfs_sampling_frequency_availfunction st_sensors_sysfs_scale_avail
Annotated Snippet
if (sensor_settings->odr.odr_avl[i].hz == odr) {
odr_out->hz = sensor_settings->odr.odr_avl[i].hz;
odr_out->value = sensor_settings->odr.odr_avl[i].value;
ret = 0;
break;
}
}
st_sensors_match_odr_error:
return ret;
}
int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr)
{
int err = 0;
struct st_sensor_odr_avl odr_out = {0, 0};
struct st_sensor_data *sdata = iio_priv(indio_dev);
mutex_lock(&sdata->odr_lock);
if (!sdata->sensor_settings->odr.mask)
goto unlock_mutex;
err = st_sensors_match_odr(sdata->sensor_settings, odr, &odr_out);
if (err < 0)
goto unlock_mutex;
if ((sdata->sensor_settings->odr.addr ==
sdata->sensor_settings->pw.addr) &&
(sdata->sensor_settings->odr.mask ==
sdata->sensor_settings->pw.mask)) {
if (sdata->enabled == true) {
err = st_sensors_write_data_with_mask(indio_dev,
sdata->sensor_settings->odr.addr,
sdata->sensor_settings->odr.mask,
odr_out.value);
} else {
err = 0;
}
} else {
err = st_sensors_write_data_with_mask(indio_dev,
sdata->sensor_settings->odr.addr,
sdata->sensor_settings->odr.mask,
odr_out.value);
}
if (err >= 0)
sdata->odr = odr_out.hz;
unlock_mutex:
mutex_unlock(&sdata->odr_lock);
return err;
}
EXPORT_SYMBOL_NS(st_sensors_set_odr, "IIO_ST_SENSORS");
static int st_sensors_match_fs(struct st_sensor_settings *sensor_settings,
unsigned int fs, int *index_fs_avl)
{
int i, ret = -EINVAL;
for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
if (sensor_settings->fs.fs_avl[i].num == 0)
return ret;
if (sensor_settings->fs.fs_avl[i].num == fs) {
*index_fs_avl = i;
ret = 0;
break;
}
}
return ret;
}
static int st_sensors_set_fullscale(struct iio_dev *indio_dev, unsigned int fs)
{
int err, i = 0;
struct st_sensor_data *sdata = iio_priv(indio_dev);
if (sdata->sensor_settings->fs.addr == 0)
return 0;
err = st_sensors_match_fs(sdata->sensor_settings, fs, &i);
if (err < 0)
goto st_accel_set_fullscale_error;
err = st_sensors_write_data_with_mask(indio_dev,
sdata->sensor_settings->fs.addr,
sdata->sensor_settings->fs.mask,
sdata->sensor_settings->fs.fs_avl[i].value);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/delay.h`, `linux/iio/iio.h`, `linux/mutex.h`, `linux/property.h`, `linux/regulator/consumer.h`.
- Detected declarations: `function st_sensors_write_data_with_mask`, `function st_sensors_debugfs_reg_access`, `function st_sensors_match_odr`, `function st_sensors_set_odr`, `function st_sensors_match_fs`, `function st_sensors_set_fullscale`, `function st_sensors_set_enable`, `function st_sensors_set_axis_enable`, `function st_sensors_power_enable`, `function st_sensors_set_drdy_int_pin`.
- 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.
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.