drivers/iio/pressure/hp03.c
Source file repositories/reference/linux-study-clean/drivers/iio/pressure/hp03.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/pressure/hp03.c- Extension
.c- Size
- 7068 bytes
- Lines
- 293
- 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/delay.hlinux/gpio/consumer.hlinux/i2c.hlinux/regmap.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct hp03_privfunction hp03_is_writeable_regfunction hp03_is_volatile_regfunction hp03_get_temp_pressurefunction hp03_update_temp_pressurefunction hp03_read_rawfunction hp03_probe
Annotated Snippet
struct hp03_priv {
struct i2c_client *client;
struct mutex lock;
struct gpio_desc *xclr_gpio;
struct i2c_client *eeprom_client;
struct regmap *eeprom_regmap;
s32 pressure; /* kPa */
s32 temp; /* Deg. C */
};
static const struct iio_chan_spec hp03_channels[] = {
{
.type = IIO_PRESSURE,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
},
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
},
};
static bool hp03_is_writeable_reg(struct device *dev, unsigned int reg)
{
return false;
}
static bool hp03_is_volatile_reg(struct device *dev, unsigned int reg)
{
return false;
}
static const struct regmap_config hp03_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = HP03_EEPROM_CD_OFFSET + 1,
.cache_type = REGCACHE_RBTREE,
.writeable_reg = hp03_is_writeable_reg,
.volatile_reg = hp03_is_volatile_reg,
};
static int hp03_get_temp_pressure(struct hp03_priv *priv, const u8 reg)
{
int ret;
ret = i2c_smbus_write_byte_data(priv->client, HP03_ADC_WRITE_REG, reg);
if (ret < 0)
return ret;
msleep(50); /* Wait for conversion to finish */
return i2c_smbus_read_word_data(priv->client, HP03_ADC_READ_REG);
}
static int hp03_update_temp_pressure(struct hp03_priv *priv)
{
struct device *dev = &priv->client->dev;
u8 coefs[18];
u16 cx_val[7];
int ab_val, d1_val, d2_val, diff_val, dut, off, sens, x;
int i, ret;
/* Sample coefficients from EEPROM */
ret = regmap_bulk_read(priv->eeprom_regmap, HP03_EEPROM_CX_OFFSET,
coefs, sizeof(coefs));
if (ret < 0) {
dev_err(dev, "Failed to read EEPROM (reg=%02x)\n",
HP03_EEPROM_CX_OFFSET);
return ret;
}
/* Sample Temperature and Pressure */
gpiod_set_value_cansleep(priv->xclr_gpio, 1);
ret = hp03_get_temp_pressure(priv, HP03_ADC_READ_PRESSURE);
if (ret < 0) {
dev_err(dev, "Failed to read pressure\n");
goto err_adc;
}
d1_val = ret;
ret = hp03_get_temp_pressure(priv, HP03_ADC_READ_TEMP);
if (ret < 0) {
dev_err(dev, "Failed to read temperature\n");
goto err_adc;
Annotation
- Immediate include surface: `linux/module.h`, `linux/delay.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/regmap.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct hp03_priv`, `function hp03_is_writeable_reg`, `function hp03_is_volatile_reg`, `function hp03_get_temp_pressure`, `function hp03_update_temp_pressure`, `function hp03_read_raw`, `function hp03_probe`.
- 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.