drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
Source file repositories/reference/linux-study-clean/drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/imu/inv_icm42600/inv_icm42600_gyro.c- Extension
.c- Size
- 22409 bytes
- Lines
- 827
- 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/iio/buffer.hlinux/iio/common/inv_sensors_timestamp.hlinux/iio/iio.hlinux/iio/kfifo_buf.hinv_icm42600.hinv_icm42600_temp.hinv_icm42600_buffer.h
Detected Declarations
struct inv_icm42600_gyro_bufferenum inv_icm42600_gyro_scanfunction inv_icm42600_gyro_update_scan_modefunction inv_icm42600_gyro_read_sensorfunction inv_icm42600_gyro_read_scalefunction inv_icm42600_gyro_write_scalefunction inv_icm42600_gyro_read_odrfunction inv_icm42600_gyro_write_odrfunction inv_icm42600_gyro_read_offsetfunction inv_icm42600_gyro_write_offsetfunction inv_icm42600_gyro_read_rawfunction inv_icm42600_gyro_read_availfunction inv_icm42600_gyro_write_rawfunction inv_icm42600_gyro_write_raw_get_fmtfunction inv_icm42600_gyro_hwfifo_set_watermarkfunction inv_icm42600_gyro_hwfifo_flushfunction inv_icm42600_gyro_parse_fifo
Annotated Snippet
struct inv_icm42600_gyro_buffer {
struct inv_icm42600_fifo_sensor_data gyro;
s16 temp;
aligned_s64 timestamp;
};
#define INV_ICM42600_SCAN_MASK_GYRO_3AXIS \
(BIT(INV_ICM42600_GYRO_SCAN_X) | \
BIT(INV_ICM42600_GYRO_SCAN_Y) | \
BIT(INV_ICM42600_GYRO_SCAN_Z))
#define INV_ICM42600_SCAN_MASK_TEMP BIT(INV_ICM42600_GYRO_SCAN_TEMP)
static const unsigned long inv_icm42600_gyro_scan_masks[] = {
/* 3-axis gyro + temperature */
INV_ICM42600_SCAN_MASK_GYRO_3AXIS | INV_ICM42600_SCAN_MASK_TEMP,
0,
};
/* enable gyroscope sensor and FIFO write */
static int inv_icm42600_gyro_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_conf conf = INV_ICM42600_SENSOR_CONF_INIT;
unsigned int fifo_en = 0;
unsigned int sleep_gyro = 0;
unsigned int sleep_temp = 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_GYRO_3AXIS) {
/* enable gyro sensor */
conf.mode = INV_ICM42600_SENSOR_MODE_LOW_NOISE;
ret = inv_icm42600_set_gyro_conf(st, &conf, &sleep_gyro);
if (ret)
goto out_unlock;
fifo_en |= INV_ICM42600_SENSOR_GYRO;
}
/* 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_gyro, sleep_temp);
if (sleep)
msleep(sleep);
return ret;
}
static int inv_icm42600_gyro_read_sensor(struct inv_icm42600_state *st,
struct iio_chan_spec const *chan,
s16 *val)
{
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_ANGL_VEL)
return -EINVAL;
switch (chan->channel2) {
case IIO_MOD_X:
reg = INV_ICM42600_REG_GYRO_DATA_X;
break;
case IIO_MOD_Y:
reg = INV_ICM42600_REG_GYRO_DATA_Y;
break;
case IIO_MOD_Z:
reg = INV_ICM42600_REG_GYRO_DATA_Z;
break;
default:
return -EINVAL;
}
pm_runtime_get_sync(dev);
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/iio/buffer.h`.
- Detected declarations: `struct inv_icm42600_gyro_buffer`, `enum inv_icm42600_gyro_scan`, `function inv_icm42600_gyro_update_scan_mode`, `function inv_icm42600_gyro_read_sensor`, `function inv_icm42600_gyro_read_scale`, `function inv_icm42600_gyro_write_scale`, `function inv_icm42600_gyro_read_odr`, `function inv_icm42600_gyro_write_odr`, `function inv_icm42600_gyro_read_offset`, `function inv_icm42600_gyro_write_offset`.
- 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.