drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
Source file repositories/reference/linux-study-clean/drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/imu/inv_icm42600/inv_icm42600_accel.c- Extension
.c- Size
- 33502 bytes
- Lines
- 1246
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/device.hlinux/mutex.hlinux/pm_runtime.hlinux/regmap.hlinux/delay.hlinux/math64.hlinux/minmax.hlinux/units.hlinux/iio/buffer.hlinux/iio/common/inv_sensors_timestamp.hlinux/iio/events.hlinux/iio/iio.hlinux/iio/kfifo_buf.hinv_icm42600.hinv_icm42600_temp.hinv_icm42600_buffer.h
Detected Declarations
struct inv_icm42600_accel_bufferenum inv_icm42600_accel_scanfunction inv_icm42600_accel_power_mode_setfunction inv_icm42600_accel_power_mode_getfunction inv_icm42600_accel_update_scan_modefunction inv_icm42600_accel_read_sensorfunction inv_icm42600_accel_convert_roc_to_womfunction inv_icm42600_accel_convert_wom_to_rocfunction inv_icm42600_accel_set_wom_thresholdfunction _inv_icm42600_accel_enable_womfunction scoped_guardfunction scoped_guardfunction inv_icm42600_accel_enable_womfunction _inv_icm42600_accel_disable_womfunction scoped_guardfunction inv_icm42600_accel_disable_womfunction inv_icm42600_accel_handle_eventsfunction inv_icm42600_accel_read_scalefunction inv_icm42600_accel_write_scalefunction inv_icm42600_accel_read_odrfunction inv_icm42600_accel_write_odrfunction inv_icm42600_accel_read_offsetfunction inv_icm42600_accel_write_offsetfunction inv_icm42600_accel_read_rawfunction inv_icm42600_accel_read_availfunction inv_icm42600_accel_write_rawfunction inv_icm42600_accel_write_raw_get_fmtfunction inv_icm42600_accel_hwfifo_set_watermarkfunction inv_icm42600_accel_hwfifo_flushfunction inv_icm42600_accel_read_event_configfunction inv_icm42600_accel_write_event_configfunction scoped_guardfunction inv_icm42600_accel_read_event_valuefunction _inv_icm42600_accel_wom_valuefunction inv_icm42600_accel_write_event_valuefunction inv_icm42600_accel_parse_fifo
Annotated Snippet
struct inv_icm42600_accel_buffer {
struct inv_icm42600_fifo_sensor_data accel;
s16 temp;
aligned_s64 timestamp;
};
#define INV_ICM42600_SCAN_MASK_ACCEL_3AXIS \
(BIT(INV_ICM42600_ACCEL_SCAN_X) | \
BIT(INV_ICM42600_ACCEL_SCAN_Y) | \
BIT(INV_ICM42600_ACCEL_SCAN_Z))
#define INV_ICM42600_SCAN_MASK_TEMP BIT(INV_ICM42600_ACCEL_SCAN_TEMP)
static const unsigned long inv_icm42600_accel_scan_masks[] = {
/* 3-axis accel + temperature */
INV_ICM42600_SCAN_MASK_ACCEL_3AXIS | INV_ICM42600_SCAN_MASK_TEMP,
0,
};
/* enable accelerometer sensor and FIFO write */
static int inv_icm42600_accel_update_scan_mode(struct iio_dev *indio_dev,
const unsigned long *scan_mask)
{
struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
struct inv_icm42600_sensor_state *accel_st = iio_priv(indio_dev);
struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
unsigned int fifo_en = 0;
unsigned int sleep_temp = 0;
unsigned int sleep_accel = 0;
unsigned int sleep;
int ret;
mutex_lock(&st->lock);
if (*scan_mask & INV_ICM42600_SCAN_MASK_TEMP) {
/* enable temp sensor */
ret = inv_icm42600_set_temp_conf(st, true, &sleep_temp);
if (ret)
goto out_unlock;
fifo_en |= INV_ICM42600_SENSOR_TEMP;
}
if (*scan_mask & INV_ICM42600_SCAN_MASK_ACCEL_3AXIS) {
/* enable accel sensor */
conf.mode = accel_st->power_mode;
conf.filter = accel_st->filter;
ret = inv_icm42600_set_accel_conf(st, &conf, &sleep_accel);
if (ret)
goto out_unlock;
fifo_en |= INV_ICM42600_SENSOR_ACCEL;
}
/* update data FIFO write */
ret = inv_icm42600_buffer_set_fifo_en(st, fifo_en | st->fifo.en);
out_unlock:
mutex_unlock(&st->lock);
/* sleep maximum required time */
sleep = max(sleep_accel, sleep_temp);
if (sleep)
msleep(sleep);
return ret;
}
static int inv_icm42600_accel_read_sensor(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
s16 *val)
{
struct inv_icm42600_state *st = iio_device_get_drvdata(indio_dev);
struct inv_icm42600_sensor_state *accel_st = iio_priv(indio_dev);
struct device *dev = regmap_get_device(st->map);
struct inv_icm42600_sensor_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
unsigned int reg;
__be16 *data;
int ret;
if (chan->type != IIO_ACCEL)
return -EINVAL;
switch (chan->channel2) {
case IIO_MOD_X:
reg = INV_ICM42600_REG_ACCEL_DATA_X;
break;
case IIO_MOD_Y:
reg = INV_ICM42600_REG_ACCEL_DATA_Y;
break;
case IIO_MOD_Z:
reg = INV_ICM42600_REG_ACCEL_DATA_Z;
break;
default:
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/device.h`, `linux/mutex.h`, `linux/pm_runtime.h`, `linux/regmap.h`, `linux/delay.h`, `linux/math64.h`, `linux/minmax.h`.
- Detected declarations: `struct inv_icm42600_accel_buffer`, `enum inv_icm42600_accel_scan`, `function inv_icm42600_accel_power_mode_set`, `function inv_icm42600_accel_power_mode_get`, `function inv_icm42600_accel_update_scan_mode`, `function inv_icm42600_accel_read_sensor`, `function inv_icm42600_accel_convert_roc_to_wom`, `function inv_icm42600_accel_convert_wom_to_roc`, `function inv_icm42600_accel_set_wom_threshold`, `function _inv_icm42600_accel_enable_wom`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source 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.