drivers/iio/chemical/ens160_core.c
Source file repositories/reference/linux-study-clean/drivers/iio/chemical/ens160_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/chemical/ens160_core.c- Extension
.c- Size
- 8907 bytes
- Lines
- 374
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/iio/iio.hlinux/iio/trigger.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.hlinux/module.hlinux/regmap.hens160.h
Detected Declarations
struct ens160_datafunction __ens160_read_rawfunction ens160_read_rawfunction ens160_set_modefunction ens160_set_idlefunction ens160_chip_initfunction ens160_suspendfunction ens160_resumefunction ens160_trigger_handlerfunction ens160_set_trigger_statefunction ens160_setup_triggerfunction devm_ens160_core_probe
Annotated Snippet
struct ens160_data {
struct regmap *regmap;
/* Protect reads from the sensor */
struct mutex mutex;
struct {
__le16 chans[2];
aligned_s64 timestamp;
} scan __aligned(IIO_DMA_MINALIGN);
u8 fw_version[3];
__le16 buf;
};
static const struct iio_chan_spec ens160_channels[] = {
{
.type = IIO_CONCENTRATION,
.channel2 = IIO_MOD_VOC,
.modified = 1,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE),
.address = ENS160_REG_DATA_TVOC,
.scan_index = 0,
.scan_type = {
.sign = 'u',
.realbits = 16,
.storagebits = 16,
.endianness = IIO_LE,
},
},
{
.type = IIO_CONCENTRATION,
.channel2 = IIO_MOD_CO2,
.modified = 1,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE),
.address = ENS160_REG_DATA_ECO2,
.scan_index = 1,
.scan_type = {
.sign = 'u',
.realbits = 16,
.storagebits = 16,
.endianness = IIO_LE,
},
},
IIO_CHAN_SOFT_TIMESTAMP(2),
};
static int __ens160_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val)
{
struct ens160_data *data = iio_priv(indio_dev);
int ret;
guard(mutex)(&data->mutex);
ret = regmap_bulk_read(data->regmap, chan->address,
&data->buf, sizeof(data->buf));
if (ret)
return ret;
*val = le16_to_cpu(data->buf);
return IIO_VAL_INT;
}
static int ens160_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
int ret;
switch (mask) {
case IIO_CHAN_INFO_RAW:
if (!iio_device_claim_direct(indio_dev))
return -EBUSY;
ret = __ens160_read_raw(indio_dev, chan, val);
iio_device_release_direct(indio_dev);
return ret;
case IIO_CHAN_INFO_SCALE:
switch (chan->channel2) {
case IIO_MOD_CO2:
/* The sensor reads CO2 data as ppm */
*val = 0;
*val2 = 100;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_MOD_VOC:
/* The sensor reads VOC data as ppb */
*val = 0;
*val2 = 100;
return IIO_VAL_INT_PLUS_NANO;
default:
return -EINVAL;
}
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/iio/iio.h`, `linux/iio/trigger.h`, `linux/iio/trigger_consumer.h`, `linux/iio/triggered_buffer.h`, `linux/module.h`, `linux/regmap.h`, `ens160.h`.
- Detected declarations: `struct ens160_data`, `function __ens160_read_raw`, `function ens160_read_raw`, `function ens160_set_mode`, `function ens160_set_idle`, `function ens160_chip_init`, `function ens160_suspend`, `function ens160_resume`, `function ens160_trigger_handler`, `function ens160_set_trigger_state`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration 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.