drivers/iio/humidity/hdc3020.c
Source file repositories/reference/linux-study-clean/drivers/iio/humidity/hdc3020.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/humidity/hdc3020.c- Extension
.c- Size
- 23610 bytes
- Lines
- 906
- 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.
- 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/bitops.hlinux/cleanup.hlinux/crc8.hlinux/delay.hlinux/gpio/consumer.hlinux/i2c.hlinux/init.hlinux/interrupt.hlinux/math64.hlinux/module.hlinux/mutex.hlinux/pm.hlinux/regulator/consumer.hlinux/units.hlinux/unaligned.hlinux/iio/events.hlinux/iio/iio.h
Detected Declarations
struct hdc3020_datafunction hdc3020_write_bytesfunction hdc3020_read_bytesfunction hdc3020_read_be16function hdc3020_exec_cmdfunction hdc3020_read_measurementfunction hdc3020_read_rawfunction hdc3020_read_availablefunction hdc3020_update_heaterfunction hdc3020_write_rawfunction hdc3020_thresh_get_tempfunction hdc3020_thresh_get_humfunction hdc3020_thresh_set_tempfunction hdc3020_thresh_set_humfunction hdc3020_thresh_clrfunction _hdc3020_write_threshfunction hdc3020_write_threshfunction hdc3020_read_threshfunction hdc3020_interrupt_handlerfunction hdc3020_power_offfunction hdc3020_power_onfunction hdc3020_exitfunction hdc3020_probefunction hdc3020_suspendfunction hdc3020_resume
Annotated Snippet
struct hdc3020_data {
struct i2c_client *client;
struct gpio_desc *reset_gpio;
struct regulator *vdd_supply;
/*
* Ensure that the sensor configuration (currently only heater is
* supported) will not be changed during the process of reading
* sensor data (this driver will try HDC3020_READ_RETRY_TIMES times
* if the device does not respond).
*/
struct mutex lock;
};
static const int hdc3020_heater_vals[] = {0, 1, 0x3FFF};
static const struct iio_event_spec hdc3020_t_rh_event[] = {
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_RISING,
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_HYSTERESIS),
},
{
.type = IIO_EV_TYPE_THRESH,
.dir = IIO_EV_DIR_FALLING,
.mask_separate = BIT(IIO_EV_INFO_VALUE) |
BIT(IIO_EV_INFO_HYSTERESIS),
},
};
static const struct iio_chan_spec hdc3020_channels[] = {
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_PEAK) |
BIT(IIO_CHAN_INFO_TROUGH) | BIT(IIO_CHAN_INFO_OFFSET),
.event_spec = hdc3020_t_rh_event,
.num_event_specs = ARRAY_SIZE(hdc3020_t_rh_event),
},
{
.type = IIO_HUMIDITYRELATIVE,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_PEAK) |
BIT(IIO_CHAN_INFO_TROUGH),
.event_spec = hdc3020_t_rh_event,
.num_event_specs = ARRAY_SIZE(hdc3020_t_rh_event),
},
{
/*
* For setting the internal heater, which can be switched on to
* prevent or remove any condensation that may develop when the
* ambient environment approaches its dew point temperature.
*/
.type = IIO_CURRENT,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_separate_available = BIT(IIO_CHAN_INFO_RAW),
.output = 1,
},
};
DECLARE_CRC8_TABLE(hdc3020_crc8_table);
static int hdc3020_write_bytes(struct hdc3020_data *data, u8 *buf, u8 len)
{
struct i2c_client *client = data->client;
struct i2c_msg msg;
int ret, cnt;
msg.addr = client->addr;
msg.flags = 0;
msg.buf = buf;
msg.len = len;
/*
* During the measurement process, HDC3020 will not return data.
* So wait for a while and try again
*/
for (cnt = 0; cnt < HDC3020_READ_RETRY_TIMES; cnt++) {
ret = i2c_transfer(client->adapter, &msg, 1);
if (ret == 1)
return 0;
mdelay(HDC3020_BUSY_DELAY_MS);
}
dev_err(&client->dev, "Could not write sensor command\n");
return -ETIMEDOUT;
}
static
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bitops.h`, `linux/cleanup.h`, `linux/crc8.h`, `linux/delay.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/init.h`.
- Detected declarations: `struct hdc3020_data`, `function hdc3020_write_bytes`, `function hdc3020_read_bytes`, `function hdc3020_read_be16`, `function hdc3020_exec_cmd`, `function hdc3020_read_measurement`, `function hdc3020_read_raw`, `function hdc3020_read_available`, `function hdc3020_update_heater`, `function hdc3020_write_raw`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- 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.