drivers/iio/humidity/htu21.c
Source file repositories/reference/linux-study-clean/drivers/iio/humidity/htu21.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/humidity/htu21.c- Extension
.c- Size
- 6726 bytes
- Lines
- 262
- 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/init.hlinux/device.hlinux/kernel.hlinux/stat.hlinux/module.hlinux/mod_devicetable.hlinux/iio/iio.hlinux/iio/sysfs.h../common/ms_sensors/ms_sensors_i2c.h
Detected Declarations
function htu21_read_rawfunction htu21_write_rawfunction htu21_show_battery_lowfunction htu21_show_heaterfunction htu21_write_heaterfunction htu21_probe
Annotated Snippet
switch (channel->type) {
case IIO_TEMP: /* in milli °C */
ret = ms_sensors_ht_read_temperature(dev_data,
&temperature);
if (ret)
return ret;
*val = temperature;
return IIO_VAL_INT;
case IIO_HUMIDITYRELATIVE: /* in milli %RH */
ret = ms_sensors_ht_read_humidity(dev_data,
&humidity);
if (ret)
return ret;
*val = humidity;
return IIO_VAL_INT;
default:
return -EINVAL;
}
case IIO_CHAN_INFO_SAMP_FREQ:
*val = htu21_samp_freq[dev_data->res_index];
return IIO_VAL_INT;
default:
return -EINVAL;
}
}
static int htu21_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val, int val2, long mask)
{
struct ms_ht_dev *dev_data = iio_priv(indio_dev);
int i, ret;
switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ:
i = ARRAY_SIZE(htu21_samp_freq);
while (i-- > 0)
if (val == htu21_samp_freq[i])
break;
if (i < 0)
return -EINVAL;
mutex_lock(&dev_data->lock);
dev_data->res_index = i;
ret = ms_sensors_write_resolution(dev_data, i);
mutex_unlock(&dev_data->lock);
return ret;
default:
return -EINVAL;
}
}
static const struct iio_chan_spec htu21_channels[] = {
{
.type = IIO_TEMP,
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED),
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
},
{
.type = IIO_HUMIDITYRELATIVE,
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED),
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
}
};
/*
* Meas Spec recommendation is to not read temperature
* on this driver part for MS8607
*/
static const struct iio_chan_spec ms8607_channels[] = {
{
.type = IIO_HUMIDITYRELATIVE,
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED),
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
}
};
static ssize_t htu21_show_battery_low(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
struct ms_ht_dev *dev_data = iio_priv(indio_dev);
return ms_sensors_show_battery_low(dev_data, buf);
}
static ssize_t htu21_show_heater(struct device *dev,
Annotation
- Immediate include surface: `linux/init.h`, `linux/device.h`, `linux/kernel.h`, `linux/stat.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `function htu21_read_raw`, `function htu21_write_raw`, `function htu21_show_battery_low`, `function htu21_show_heater`, `function htu21_write_heater`, `function htu21_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.