drivers/iio/pressure/hp206c.c
Source file repositories/reference/linux-study-clean/drivers/iio/pressure/hp206c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/pressure/hp206c.c- Extension
.c- Size
- 10155 bytes
- Lines
- 423
- 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/module.hlinux/mod_devicetable.hlinux/i2c.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/delay.hlinux/util_macros.hlinux/unaligned.h
Detected Declarations
struct hp206c_datastruct hp206c_osr_settingfunction hp206c_read_regfunction hp206c_write_regfunction hp206c_read_20bitfunction hp206c_wait_dev_rdyfunction hp206c_set_compensationfunction hp206c_soft_resetfunction hp206c_conv_and_readfunction hp206c_read_rawfunction hp206c_write_rawfunction hp206c_probe
Annotated Snippet
struct hp206c_data {
struct mutex mutex;
struct i2c_client *client;
int temp_osr_index;
int pres_osr_index;
};
struct hp206c_osr_setting {
u8 osr_mask;
unsigned int temp_conv_time_us;
unsigned int pres_conv_time_us;
};
/* Data from Table 5 in datasheet. */
static const struct hp206c_osr_setting hp206c_osr_settings[] = {
{ HP206C_CMD_ADC_CVT_OSR_4096, 65600, 131100 },
{ HP206C_CMD_ADC_CVT_OSR_2048, 32800, 65600 },
{ HP206C_CMD_ADC_CVT_OSR_1024, 16400, 32800 },
{ HP206C_CMD_ADC_CVT_OSR_512, 8200, 16400 },
{ HP206C_CMD_ADC_CVT_OSR_256, 4100, 8200 },
{ HP206C_CMD_ADC_CVT_OSR_128, 2100, 4100 },
};
static const int hp206c_osr_rates[] = { 4096, 2048, 1024, 512, 256, 128 };
static const char hp206c_osr_rates_str[] = "4096 2048 1024 512 256 128";
static inline int hp206c_read_reg(struct i2c_client *client, u8 reg)
{
return i2c_smbus_read_byte_data(client, HP206C_CMD_READ_REG | reg);
}
static inline int hp206c_write_reg(struct i2c_client *client, u8 reg, u8 val)
{
return i2c_smbus_write_byte_data(client,
HP206C_CMD_WRITE_REG | reg, val);
}
static int hp206c_read_20bit(struct i2c_client *client, u8 cmd)
{
int ret;
u8 values[3];
ret = i2c_smbus_read_i2c_block_data(client, cmd, sizeof(values), values);
if (ret < 0)
return ret;
if (ret != sizeof(values))
return -EIO;
return get_unaligned_be24(&values[0]) & GENMASK(19, 0);
}
/* Spin for max 160ms until DEV_RDY is 1, or return error. */
static int hp206c_wait_dev_rdy(struct iio_dev *indio_dev)
{
int ret;
int count = 0;
struct hp206c_data *data = iio_priv(indio_dev);
struct i2c_client *client = data->client;
while (++count <= HP206C_MAX_DEV_RDY_WAIT_COUNT) {
ret = hp206c_read_reg(client, HP206C_REG_INT_SRC);
if (ret < 0) {
dev_err(&indio_dev->dev, "Failed READ_REG INT_SRC: %d\n", ret);
return ret;
}
if (ret & HP206C_FLAG_DEV_RDY)
return 0;
usleep_range(HP206C_DEV_RDY_WAIT_US, HP206C_DEV_RDY_WAIT_US * 3 / 2);
}
return -ETIMEDOUT;
}
static int hp206c_set_compensation(struct i2c_client *client, bool enabled)
{
int val;
val = hp206c_read_reg(client, HP206C_REG_PARA);
if (val < 0)
return val;
if (enabled)
val |= HP206C_FLAG_CMPS_EN;
else
val &= ~HP206C_FLAG_CMPS_EN;
return hp206c_write_reg(client, HP206C_REG_PARA, val);
}
/* Do a soft reset */
static int hp206c_soft_reset(struct iio_dev *indio_dev)
{
int ret;
struct hp206c_data *data = iio_priv(indio_dev);
Annotation
- Immediate include surface: `linux/module.h`, `linux/mod_devicetable.h`, `linux/i2c.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/delay.h`, `linux/util_macros.h`, `linux/unaligned.h`.
- Detected declarations: `struct hp206c_data`, `struct hp206c_osr_setting`, `function hp206c_read_reg`, `function hp206c_write_reg`, `function hp206c_read_20bit`, `function hp206c_wait_dev_rdy`, `function hp206c_set_compensation`, `function hp206c_soft_reset`, `function hp206c_conv_and_read`, `function hp206c_read_raw`.
- 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.