drivers/iio/gyro/mpu3050-core.c
Source file repositories/reference/linux-study-clean/drivers/iio/gyro/mpu3050-core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/gyro/mpu3050-core.c- Extension
.c- Size
- 34045 bytes
- Lines
- 1302
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/bitops.hlinux/delay.hlinux/err.hlinux/iio/buffer.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/trigger.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.hlinux/interrupt.hlinux/module.hlinux/pm_runtime.hlinux/property.hlinux/random.hlinux/slab.hmpu3050.h
Detected Declarations
function mpu3050_get_freqfunction mpu3050_start_samplingfunction mpu3050_set_8khz_sampleratefunction mpu3050_read_rawfunction mpu3050_write_rawfunction mpu3050_trigger_handlerfunction mpu3050_buffer_preenablefunction mpu3050_buffer_postdisablefunction mpu3050_get_mount_matrixfunction mpu3050_read_memfunction mpu3050_hw_initfunction mpu3050_power_upfunction mpu3050_power_downfunction mpu3050_irq_handlerfunction mpu3050_irq_threadfunction mpu3050_drdy_trigger_set_statefunction mpu3050_trigger_probefunction mpu3050_common_probefunction mpu3050_common_removefunction mpu3050_runtime_suspendfunction mpu3050_runtime_resume
Annotated Snippet
switch (chan->type) {
case IIO_TEMP:
/*
* The temperature scaling is (x+23000)/280 Celsius
* for the "best fit straight line" temperature range
* of -30C..85C. The 23000 includes room temperature
* offset of +35C, 280 is the precision scale and x is
* the 16-bit signed integer reported by hardware.
*
* Temperature value itself represents temperature of
* the sensor die.
*/
*val = 23000;
return IIO_VAL_INT;
default:
return -EINVAL;
}
case IIO_CHAN_INFO_CALIBBIAS:
switch (chan->type) {
case IIO_ANGL_VEL:
*val = mpu3050->calibration[chan->scan_index-1];
return IIO_VAL_INT;
default:
return -EINVAL;
}
case IIO_CHAN_INFO_SAMP_FREQ:
*val = mpu3050_get_freq(mpu3050);
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
switch (chan->type) {
case IIO_TEMP:
/* Millidegrees, see about temperature scaling above */
*val = 1000;
*val2 = 280;
return IIO_VAL_FRACTIONAL;
case IIO_ANGL_VEL:
/*
* Convert to the corresponding full scale in
* radians. All 16 bits are used with sign to
* span the available scale: to account for the one
* missing value if we multiply by 1/S16_MAX, instead
* multiply with 2/U16_MAX.
*/
*val = mpu3050_fs_precision[mpu3050->fullscale] * 2;
*val2 = U16_MAX;
return IIO_VAL_FRACTIONAL;
default:
return -EINVAL;
}
case IIO_CHAN_INFO_RAW:
/* Resume device */
ret = pm_runtime_resume_and_get(mpu3050->dev);
if (ret)
return ret;
mutex_lock(&mpu3050->lock);
ret = mpu3050_set_8khz_samplerate(mpu3050);
if (ret)
goto out_read_raw_unlock;
switch (chan->type) {
case IIO_TEMP:
ret = regmap_bulk_read(mpu3050->map, MPU3050_TEMP_H,
&raw_val, sizeof(raw_val));
if (ret) {
dev_err(mpu3050->dev,
"error reading temperature\n");
goto out_read_raw_unlock;
}
*val = (s16)be16_to_cpu(raw_val);
ret = IIO_VAL_INT;
goto out_read_raw_unlock;
case IIO_ANGL_VEL:
ret = regmap_bulk_read(mpu3050->map,
MPU3050_AXIS_REGS(chan->scan_index-1),
&raw_val,
sizeof(raw_val));
if (ret) {
dev_err(mpu3050->dev,
"error reading axis data\n");
goto out_read_raw_unlock;
}
*val = be16_to_cpu(raw_val);
ret = IIO_VAL_INT;
goto out_read_raw_unlock;
default:
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bitops.h`, `linux/delay.h`, `linux/err.h`, `linux/iio/buffer.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/iio/trigger.h`.
- Detected declarations: `function mpu3050_get_freq`, `function mpu3050_start_sampling`, `function mpu3050_set_8khz_samplerate`, `function mpu3050_read_raw`, `function mpu3050_write_raw`, `function mpu3050_trigger_handler`, `function mpu3050_buffer_preenable`, `function mpu3050_buffer_postdisable`, `function mpu3050_get_mount_matrix`, `function mpu3050_read_mem`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.