drivers/iio/pressure/ms5611_core.c
Source file repositories/reference/linux-study-clean/drivers/iio/pressure/ms5611_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/pressure/ms5611_core.c- Extension
.c- Size
- 10098 bytes
- Lines
- 455
- 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.
- 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/module.hlinux/iio/iio.hlinux/delay.hlinux/regulator/consumer.hlinux/iio/sysfs.hlinux/iio/buffer.hlinux/iio/triggered_buffer.hlinux/iio/trigger_consumer.hms5611.h
Detected Declarations
function ms5611_prom_is_validfunction ms5611_read_promfunction ms5611_read_temp_and_pressurefunction ms5611_temp_and_pressure_compensatefunction ms5607_temp_and_pressure_compensatefunction ms5611_resetfunction ms5611_trigger_handlerfunction ms5611_read_rawfunction ms5611_write_rawfunction ms5611_initfunction ms5611_probe
Annotated Snippet
if (ret < 0) {
dev_err(&indio_dev->dev,
"failed to read prom at %d\n", i);
return ret;
}
}
if (!ms5611_prom_is_valid(st->prom, MS5611_PROM_WORDS_NB)) {
dev_err(&indio_dev->dev, "PROM integrity check failed\n");
return -ENODEV;
}
return 0;
}
static int ms5611_read_temp_and_pressure(struct iio_dev *indio_dev,
s32 *temp, s32 *pressure)
{
int ret;
struct ms5611_state *st = iio_priv(indio_dev);
ret = st->read_adc_temp_and_pressure(st, temp, pressure);
if (ret < 0) {
dev_err(&indio_dev->dev,
"failed to read temperature and pressure\n");
return ret;
}
return st->compensate_temp_and_pressure(st, temp, pressure);
}
static int ms5611_temp_and_pressure_compensate(struct ms5611_state *st,
s32 *temp, s32 *pressure)
{
s32 t = *temp, p = *pressure;
s64 off, sens, dt;
dt = t - (st->prom[5] << 8);
off = ((s64)st->prom[2] << 16) + ((st->prom[4] * dt) >> 7);
sens = ((s64)st->prom[1] << 15) + ((st->prom[3] * dt) >> 8);
t = 2000 + ((st->prom[6] * dt) >> 23);
if (t < 2000) {
s64 off2, sens2, t2;
t2 = (dt * dt) >> 31;
off2 = (5 * (t - 2000) * (t - 2000)) >> 1;
sens2 = off2 >> 1;
if (t < -1500) {
s64 tmp = (t + 1500) * (t + 1500);
off2 += 7 * tmp;
sens2 += (11 * tmp) >> 1;
}
t -= t2;
off -= off2;
sens -= sens2;
}
*temp = t;
*pressure = (((p * sens) >> 21) - off) >> 15;
return 0;
}
static int ms5607_temp_and_pressure_compensate(struct ms5611_state *st,
s32 *temp, s32 *pressure)
{
s32 t = *temp, p = *pressure;
s64 off, sens, dt;
dt = t - (st->prom[5] << 8);
off = ((s64)st->prom[2] << 17) + ((st->prom[4] * dt) >> 6);
sens = ((s64)st->prom[1] << 16) + ((st->prom[3] * dt) >> 7);
t = 2000 + ((st->prom[6] * dt) >> 23);
if (t < 2000) {
s64 off2, sens2, t2, tmp;
t2 = (dt * dt) >> 31;
tmp = (t - 2000) * (t - 2000);
off2 = (61 * tmp) >> 4;
sens2 = tmp << 1;
if (t < -1500) {
tmp = (t + 1500) * (t + 1500);
off2 += 15 * tmp;
sens2 += 8 * tmp;
Annotation
- Immediate include surface: `linux/module.h`, `linux/iio/iio.h`, `linux/delay.h`, `linux/regulator/consumer.h`, `linux/iio/sysfs.h`, `linux/iio/buffer.h`, `linux/iio/triggered_buffer.h`, `linux/iio/trigger_consumer.h`.
- Detected declarations: `function ms5611_prom_is_valid`, `function ms5611_read_prom`, `function ms5611_read_temp_and_pressure`, `function ms5611_temp_and_pressure_compensate`, `function ms5607_temp_and_pressure_compensate`, `function ms5611_reset`, `function ms5611_trigger_handler`, `function ms5611_read_raw`, `function ms5611_write_raw`, `function ms5611_init`.
- 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.
- 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.