drivers/iio/imu/inv_icm45600/inv_icm45600_gyro.c
Source file repositories/reference/linux-study-clean/drivers/iio/imu/inv_icm45600/inv_icm45600_gyro.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/imu/inv_icm45600/inv_icm45600_gyro.c- Extension
.c- Size
- 21675 bytes
- Lines
- 792
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/device.hlinux/err.hlinux/math64.hlinux/mutex.hlinux/pm_runtime.hlinux/regmap.hlinux/types.hlinux/iio/buffer.hlinux/iio/common/inv_sensors_timestamp.hlinux/iio/iio.hlinux/iio/kfifo_buf.hinv_icm45600_buffer.hinv_icm45600.h
Detected Declarations
struct inv_icm45600_gyro_bufferenum inv_icm45600_gyro_scanfunction inv_icm45600_gyro_update_scan_modefunction scoped_guardfunction _inv_icm45600_gyro_read_sensorfunction inv_icm45600_gyro_read_sensorfunction inv_icm45600_gyro_read_scalefunction inv_icm45600_gyro_write_scalefunction inv_icm45600_gyro_read_odrfunction _inv_icm45600_gyro_write_odrfunction inv_icm45600_gyro_write_odrfunction inv_icm45600_gyro_read_offsetfunction inv_icm45600_gyro_write_offsetfunction inv_icm45600_gyro_read_rawfunction inv_icm45600_gyro_read_availfunction inv_icm45600_gyro_write_rawfunction inv_icm45600_gyro_write_raw_get_fmtfunction inv_icm45600_gyro_hwfifo_set_watermarkfunction inv_icm45600_gyro_hwfifo_flushfunction inv_icm45600_gyro_parse_fifo
Annotated Snippet
struct inv_icm45600_gyro_buffer {
struct inv_icm45600_fifo_sensor_data gyro;
s16 temp;
aligned_s64 timestamp;
};
static const unsigned long inv_icm45600_gyro_scan_masks[] = {
/* 3-axis gyro + temperature */
BIT(INV_ICM45600_GYRO_SCAN_X) |
BIT(INV_ICM45600_GYRO_SCAN_Y) |
BIT(INV_ICM45600_GYRO_SCAN_Z) |
BIT(INV_ICM45600_GYRO_SCAN_TEMP),
0
};
/* enable gyroscope sensor and FIFO write */
static int inv_icm45600_gyro_update_scan_mode(struct iio_dev *indio_dev,
const unsigned long *scan_mask)
{
struct inv_icm45600_state *st = iio_device_get_drvdata(indio_dev);
struct inv_icm45600_sensor_state *gyro_st = iio_priv(indio_dev);
struct inv_icm45600_sensor_conf conf = INV_ICM45600_SENSOR_CONF_KEEP_VALUES;
unsigned int fifo_en = 0;
unsigned int sleep = 0;
int ret;
scoped_guard(mutex, &st->lock) {
if (*scan_mask & BIT(INV_ICM45600_GYRO_SCAN_TEMP))
fifo_en |= INV_ICM45600_SENSOR_TEMP;
if (*scan_mask & (BIT(INV_ICM45600_GYRO_SCAN_X) |
BIT(INV_ICM45600_GYRO_SCAN_Y) |
BIT(INV_ICM45600_GYRO_SCAN_Z))) {
/* enable gyro sensor */
conf.mode = gyro_st->power_mode;
ret = inv_icm45600_set_gyro_conf(st, &conf, &sleep);
if (ret)
return ret;
fifo_en |= INV_ICM45600_SENSOR_GYRO;
}
ret = inv_icm45600_buffer_set_fifo_en(st, fifo_en | st->fifo.en);
}
if (sleep)
msleep(sleep);
return ret;
}
static int _inv_icm45600_gyro_read_sensor(struct inv_icm45600_state *st,
struct inv_icm45600_sensor_state *gyro_st,
unsigned int reg, int *val)
{
struct inv_icm45600_sensor_conf conf = INV_ICM45600_SENSOR_CONF_KEEP_VALUES;
int ret;
/* enable gyro sensor */
conf.mode = gyro_st->power_mode;
ret = inv_icm45600_set_gyro_conf(st, &conf, NULL);
if (ret)
return ret;
/* read gyro register data */
ret = regmap_bulk_read(st->map, reg, &st->buffer.u16, sizeof(st->buffer.u16));
if (ret)
return ret;
*val = sign_extend32(le16_to_cpup(&st->buffer.u16), 15);
if (*val == INV_ICM45600_DATA_INVALID)
return -ENODATA;
return 0;
}
static int inv_icm45600_gyro_read_sensor(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val)
{
struct inv_icm45600_state *st = iio_device_get_drvdata(indio_dev);
struct inv_icm45600_sensor_state *gyro_st = iio_priv(indio_dev);
struct device *dev = regmap_get_device(st->map);
unsigned int reg;
int ret;
if (chan->type != IIO_ANGL_VEL)
return -EINVAL;
switch (chan->channel2) {
case IIO_MOD_X:
reg = INV_ICM45600_REG_GYRO_DATA_X;
break;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/device.h`, `linux/err.h`, `linux/math64.h`, `linux/mutex.h`, `linux/pm_runtime.h`, `linux/regmap.h`, `linux/types.h`.
- Detected declarations: `struct inv_icm45600_gyro_buffer`, `enum inv_icm45600_gyro_scan`, `function inv_icm45600_gyro_update_scan_mode`, `function scoped_guard`, `function _inv_icm45600_gyro_read_sensor`, `function inv_icm45600_gyro_read_sensor`, `function inv_icm45600_gyro_read_scale`, `function inv_icm45600_gyro_write_scale`, `function inv_icm45600_gyro_read_odr`, `function _inv_icm45600_gyro_write_odr`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
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.