drivers/iio/humidity/si7005.c
Source file repositories/reference/linux-study-clean/drivers/iio/humidity/si7005.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/humidity/si7005.c- Extension
.c- Size
- 4194 bytes
- Lines
- 191
- 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/err.hlinux/i2c.hlinux/delay.hlinux/module.hlinux/pm.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct si7005_datafunction si7005_read_measurementfunction si7005_read_rawfunction si7005_probe
Annotated Snippet
struct si7005_data {
struct i2c_client *client;
struct mutex lock;
u8 config;
};
static int si7005_read_measurement(struct si7005_data *data, bool temp)
{
int tries = 50;
int ret;
mutex_lock(&data->lock);
ret = i2c_smbus_write_byte_data(data->client, SI7005_CONFIG,
data->config | SI7005_CONFIG_START |
(temp ? SI7005_CONFIG_TEMP : 0));
if (ret < 0)
goto done;
while (tries-- > 0) {
msleep(20);
ret = i2c_smbus_read_byte_data(data->client, SI7005_STATUS);
if (ret < 0)
goto done;
if (!(ret & SI7005_STATUS_NRDY))
break;
}
if (tries < 0) {
ret = -EIO;
goto done;
}
ret = i2c_smbus_read_word_swapped(data->client, SI7005_DATA);
done:
mutex_unlock(&data->lock);
return ret;
}
static int si7005_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val,
int *val2, long mask)
{
struct si7005_data *data = iio_priv(indio_dev);
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = si7005_read_measurement(data, chan->type == IIO_TEMP);
if (ret < 0)
return ret;
*val = ret;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
if (chan->type == IIO_TEMP) {
*val = 7;
*val2 = 812500;
} else {
*val = 3;
*val2 = 906250;
}
return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_OFFSET:
if (chan->type == IIO_TEMP)
*val = -50 * 32 * 4;
else
*val = -24 * 16 * 16;
return IIO_VAL_INT;
default:
break;
}
return -EINVAL;
}
static const struct iio_chan_spec si7005_channels[] = {
{
.type = IIO_HUMIDITYRELATIVE,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET),
},
{
.type = IIO_TEMP,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET),
}
};
static const struct iio_info si7005_info = {
Annotation
- Immediate include surface: `linux/err.h`, `linux/i2c.h`, `linux/delay.h`, `linux/module.h`, `linux/pm.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct si7005_data`, `function si7005_read_measurement`, `function si7005_read_raw`, `function si7005_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.