drivers/iio/pressure/dps310.c
Source file repositories/reference/linux-study-clean/drivers/iio/pressure/dps310.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/pressure/dps310.c- Extension
.c- Size
- 19793 bytes
- Lines
- 914
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/i2c.hlinux/limits.hlinux/math64.hlinux/module.hlinux/regmap.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct dps310_datafunction dps310_get_coefsfunction dps310_temp_workaroundfunction dps310_startupfunction dps310_get_pres_precisionfunction dps310_get_temp_precisionfunction dps310_set_pres_precisionfunction dps310_set_temp_precisionfunction dps310_set_pres_samp_freqfunction dps310_set_temp_samp_freqfunction dps310_get_pres_samp_freqfunction dps310_get_temp_samp_freqfunction dps310_get_pres_kfunction dps310_get_temp_kfunction dps310_reset_waitfunction dps310_reset_reinitfunction dps310_ready_statusfunction dps310_readyfunction dps310_read_pres_rawfunction dps310_read_temp_readyfunction dps310_read_temp_rawfunction dps310_is_writeable_regfunction dps310_is_volatile_regfunction dps310_write_rawfunction dps310_calculate_pressurefunction dps310_read_pressurefunction dps310_calculate_tempfunction dps310_read_tempfunction dps310_read_rawfunction dps310_resetfunction dps310_probe
Annotated Snippet
struct dps310_data {
struct i2c_client *client;
struct regmap *regmap;
struct mutex lock; /* Lock for sequential HW access functions */
s32 c0, c1;
s32 c00, c10, c20, c30, c01, c11, c21;
s32 pressure_raw;
s32 temp_raw;
bool timeout_recovery_failed;
};
static const struct iio_chan_spec dps310_channels[] = {
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) |
BIT(IIO_CHAN_INFO_PROCESSED),
},
{
.type = IIO_PRESSURE,
.info_mask_separate = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO) |
BIT(IIO_CHAN_INFO_SAMP_FREQ) |
BIT(IIO_CHAN_INFO_PROCESSED),
},
};
/* To be called after checking the COEF_RDY bit in MEAS_CFG */
static int dps310_get_coefs(struct dps310_data *data)
{
int rc;
u8 coef[18];
u32 c0, c1;
u32 c00, c10, c20, c30, c01, c11, c21;
/* Read all sensor calibration coefficients from the COEF registers. */
rc = regmap_bulk_read(data->regmap, DPS310_COEF_BASE, coef,
sizeof(coef));
if (rc < 0)
return rc;
/*
* Calculate temperature calibration coefficients c0 and c1. The
* numbers are 12-bit 2's complement numbers.
*/
c0 = (coef[0] << 4) | (coef[1] >> 4);
data->c0 = sign_extend32(c0, 11);
c1 = ((coef[1] & GENMASK(3, 0)) << 8) | coef[2];
data->c1 = sign_extend32(c1, 11);
/*
* Calculate pressure calibration coefficients. c00 and c10 are 20 bit
* 2's complement numbers, while the rest are 16 bit 2's complement
* numbers.
*/
c00 = (coef[3] << 12) | (coef[4] << 4) | (coef[5] >> 4);
data->c00 = sign_extend32(c00, 19);
c10 = ((coef[5] & GENMASK(3, 0)) << 16) | (coef[6] << 8) | coef[7];
data->c10 = sign_extend32(c10, 19);
c01 = (coef[8] << 8) | coef[9];
data->c01 = sign_extend32(c01, 15);
c11 = (coef[10] << 8) | coef[11];
data->c11 = sign_extend32(c11, 15);
c20 = (coef[12] << 8) | coef[13];
data->c20 = sign_extend32(c20, 15);
c21 = (coef[14] << 8) | coef[15];
data->c21 = sign_extend32(c21, 15);
c30 = (coef[16] << 8) | coef[17];
data->c30 = sign_extend32(c30, 15);
return 0;
}
/*
* Some versions of the chip will read temperatures in the ~60C range when
* it's actually ~20C. This is the manufacturer recommended workaround
* to correct the issue. The registers used below are undocumented.
*/
static int dps310_temp_workaround(struct dps310_data *data)
{
int rc;
int reg;
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/limits.h`, `linux/math64.h`, `linux/module.h`, `linux/regmap.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct dps310_data`, `function dps310_get_coefs`, `function dps310_temp_workaround`, `function dps310_startup`, `function dps310_get_pres_precision`, `function dps310_get_temp_precision`, `function dps310_set_pres_precision`, `function dps310_set_temp_precision`, `function dps310_set_pres_samp_freq`, `function dps310_set_temp_samp_freq`.
- 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.
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.