drivers/iio/pressure/mpl3115.c
Source file repositories/reference/linux-study-clean/drivers/iio/pressure/mpl3115.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/pressure/mpl3115.c- Extension
.c- Size
- 19839 bytes
- Lines
- 812
- 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/cleanup.hlinux/delay.hlinux/i2c.hlinux/limits.hlinux/module.hlinux/property.hlinux/unaligned.hlinux/iio/buffer.hlinux/iio/events.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/triggered_buffer.hlinux/iio/trigger_consumer.hlinux/iio/trigger.h
Detected Declarations
struct mpl3115_dataenum mpl3115_irq_pinfunction mpl3115_requestfunction mpl3115_read_info_rawfunction mpl3115_read_rawfunction mpl3115_read_availfunction mpl3115_write_rawfunction mpl3115_fill_trig_bufferfunction mpl3115_trigger_handlerfunction mpl3115_interrupt_handlerfunction mpl3115_config_interruptfunction mpl3115_set_trigger_statefunction mpl3115_read_event_configfunction mpl3115_write_event_configfunction mpl3115_read_threshfunction mpl3115_write_threshfunction mpl3115_trigger_probefunction mpl3115_probefunction mpl3115_standbyfunction mpl3115_removefunction mpl3115_suspendfunction mpl3115_resume
Annotated Snippet
struct mpl3115_data {
struct i2c_client *client;
struct iio_trigger *drdy_trig;
struct mutex lock;
u8 ctrl_reg1;
u8 ctrl_reg4;
};
enum mpl3115_irq_pin {
MPL3115_IRQ_INT1,
MPL3115_IRQ_INT2,
};
static int mpl3115_request(struct mpl3115_data *data)
{
int ret, tries = 15;
/* trigger measurement */
ret = i2c_smbus_write_byte_data(data->client, MPL3115_CTRL_REG1,
data->ctrl_reg1 | MPL3115_CTRL1_OST);
if (ret < 0)
return ret;
while (tries-- > 0) {
ret = i2c_smbus_read_byte_data(data->client, MPL3115_CTRL_REG1);
if (ret < 0)
return ret;
/* wait for data ready, i.e. OST cleared */
if (!(ret & MPL3115_CTRL1_OST))
break;
msleep(20);
}
if (tries < 0) {
dev_err(&data->client->dev, "data not ready\n");
return -EIO;
}
return 0;
}
static int mpl3115_read_info_raw(struct mpl3115_data *data,
struct iio_chan_spec const *chan, int *val)
{
int ret;
switch (chan->type) {
case IIO_PRESSURE: { /* in 0.25 pascal / LSB */
u8 press_be24[3];
guard(mutex)(&data->lock);
ret = mpl3115_request(data);
if (ret < 0)
return ret;
ret = i2c_smbus_read_i2c_block_data(data->client,
MPL3115_OUT_PRESS,
sizeof(press_be24),
press_be24);
if (ret < 0)
return ret;
/*
* The pressure channel shift is applied in the case where the
* data (24-bit big endian) is read into a 32-bit buffer. Here
* the data is stored in a 24-bit buffer, so the shift is 4.
*/
*val = get_unaligned_be24(press_be24) >> 4;
return IIO_VAL_INT;
}
case IIO_TEMP: { /* in 0.0625 celsius / LSB */
__be16 tmp;
guard(mutex)(&data->lock);
ret = mpl3115_request(data);
if (ret < 0)
return ret;
ret = i2c_smbus_read_i2c_block_data(data->client,
MPL3115_OUT_TEMP,
2, (u8 *) &tmp);
if (ret < 0)
return ret;
*val = sign_extend32(be16_to_cpu(tmp) >> chan->scan_type.shift,
chan->scan_type.realbits - 1);
return IIO_VAL_INT;
}
default:
return -EINVAL;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/cleanup.h`, `linux/delay.h`, `linux/i2c.h`, `linux/limits.h`, `linux/module.h`, `linux/property.h`, `linux/unaligned.h`.
- Detected declarations: `struct mpl3115_data`, `enum mpl3115_irq_pin`, `function mpl3115_request`, `function mpl3115_read_info_raw`, `function mpl3115_read_raw`, `function mpl3115_read_avail`, `function mpl3115_write_raw`, `function mpl3115_fill_trig_buffer`, `function mpl3115_trigger_handler`, `function mpl3115_interrupt_handler`.
- 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.