drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
Source file repositories/reference/linux-study-clean/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c- Extension
.c- Size
- 64105 bytes
- Lines
- 2271
- 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/module.hlinux/slab.hlinux/i2c.hlinux/err.hlinux/delay.hlinux/sysfs.hlinux/jiffies.hlinux/irq.hlinux/interrupt.hlinux/acpi.hlinux/platform_device.hlinux/regulator/consumer.hlinux/math64.hlinux/minmax.hlinux/pm.hlinux/pm_runtime.hlinux/property.hlinux/iio/common/inv_sensors_timestamp.hlinux/iio/iio.hinv_mpu_iio.hinv_mpu_magn.h
Detected Declarations
function inv_mpu6050_pwr_mgmt_1_writefunction inv_mpu6050_clock_switchfunction inv_mpu6050_switch_enginefunction inv_mpu6050_set_power_itgfunction inv_mpu6050_set_gyro_fsrfunction inv_mpu6050_set_accel_lpf_regsfunction inv_mpu6050_set_lpf_regsfunction inv_mpu6050_init_configfunction inv_mpu6050_sensor_setfunction inv_mpu6050_sensor_showfunction inv_mpu6050_read_channel_datafunction inv_mpu6050_read_rawfunction inv_mpu6050_write_gyro_scalefunction inv_write_raw_get_fmtfunction inv_mpu6050_write_accel_scalefunction inv_mpu6050_write_rawfunction inv_mpu6050_convert_wom_to_rocfunction inv_mpu6050_convert_roc_to_womfunction inv_mpu6050_set_wom_intfunction inv_mpu6050_set_wom_thresholdfunction inv_mpu6050_set_lp_odrfunction inv_mpu6050_set_wom_lpfunction inv_mpu6050_enable_womfunction inv_mpu6050_read_event_configfunction inv_mpu6050_write_event_configfunction inv_mpu6050_read_event_valuefunction inv_mpu6050_write_event_valuefunction inv_mpu6050_set_lpffunction inv_mpu6050_fifo_rate_storefunction inv_fifo_rate_showfunction inv_attr_showfunction inv_mpu6050_validate_triggerfunction inv_get_mount_matrixfunction inv_mpu6050_reg_accessfunction inv_check_and_setup_chipfunction inv_mpu_core_enable_regulator_vddiofunction inv_mpu_core_disable_regulator_vddiofunction inv_mpu_core_disable_regulator_actionfunction inv_mpu_pm_disablefunction inv_mpu_core_probefunction inv_mpu_resumefunction inv_mpu_suspendfunction inv_mpu_runtime_suspendfunction inv_mpu_runtime_resume
Annotated Snippet
if (mask & INV_MPU6050_SENSOR_ACCL) {
if (en)
pwr_mgmt2 &= ~INV_MPU6050_BIT_PWR_ACCL_STBY;
else
pwr_mgmt2 |= INV_MPU6050_BIT_PWR_ACCL_STBY;
}
if (mask & INV_MPU6050_SENSOR_GYRO) {
if (en)
pwr_mgmt2 &= ~INV_MPU6050_BIT_PWR_GYRO_STBY;
else
pwr_mgmt2 |= INV_MPU6050_BIT_PWR_GYRO_STBY;
}
/* switch clock to internal when turning gyro off */
if (mask & INV_MPU6050_SENSOR_GYRO && !en) {
ret = inv_mpu6050_clock_switch(st, INV_CLK_INTERNAL);
if (ret)
return ret;
}
/* update sensors engine */
dev_dbg(regmap_get_device(st->map), "pwr_mgmt_2: 0x%x\n",
pwr_mgmt2);
ret = regmap_write(st->map, st->reg->pwr_mgmt_2, pwr_mgmt2);
if (ret)
return ret;
if (mask & INV_MPU6050_SENSOR_ACCL)
st->chip_config.accl_en = en;
if (mask & INV_MPU6050_SENSOR_GYRO)
st->chip_config.gyro_en = en;
/* compute required time to have sensors stabilized */
sleep = 0;
if (en) {
if (mask & INV_MPU6050_SENSOR_ACCL) {
if (sleep < st->hw->startup_time.accel)
sleep = st->hw->startup_time.accel;
}
if (mask & INV_MPU6050_SENSOR_GYRO) {
if (sleep < st->hw->startup_time.gyro)
sleep = st->hw->startup_time.gyro;
}
} else {
if (mask & INV_MPU6050_SENSOR_GYRO) {
if (sleep < INV_MPU6050_GYRO_DOWN_TIME)
sleep = INV_MPU6050_GYRO_DOWN_TIME;
}
}
if (sleep)
msleep(sleep);
/* switch clock to PLL when turning gyro on */
if (mask & INV_MPU6050_SENSOR_GYRO && en) {
ret = inv_mpu6050_clock_switch(st, INV_CLK_PLL);
if (ret)
return ret;
}
}
/* enable/disable accel intelligence control */
if (mask & INV_MPU6050_SENSOR_WOM) {
val = en ? INV_MPU6500_BIT_ACCEL_INTEL_EN |
INV_MPU6500_BIT_ACCEL_INTEL_MODE : 0;
ret = regmap_write(st->map, INV_MPU6500_REG_ACCEL_INTEL_CTRL, val);
if (ret)
return ret;
st->chip_config.wom_en = en;
}
return 0;
}
static int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st,
bool power_on)
{
int result;
result = inv_mpu6050_pwr_mgmt_1_write(st, !power_on, false, -1, -1);
if (result)
return result;
if (power_on)
usleep_range(INV_MPU6050_REG_UP_TIME_MIN,
INV_MPU6050_REG_UP_TIME_MAX);
return 0;
}
static int inv_mpu6050_set_gyro_fsr(struct inv_mpu6050_state *st,
enum inv_mpu6050_fsr_e val)
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/i2c.h`, `linux/err.h`, `linux/delay.h`, `linux/sysfs.h`, `linux/jiffies.h`, `linux/irq.h`.
- Detected declarations: `function inv_mpu6050_pwr_mgmt_1_write`, `function inv_mpu6050_clock_switch`, `function inv_mpu6050_switch_engine`, `function inv_mpu6050_set_power_itg`, `function inv_mpu6050_set_gyro_fsr`, `function inv_mpu6050_set_accel_lpf_regs`, `function inv_mpu6050_set_lpf_regs`, `function inv_mpu6050_init_config`, `function inv_mpu6050_sensor_set`, `function inv_mpu6050_sensor_show`.
- 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.