drivers/iio/light/veml6040.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/veml6040.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/veml6040.c- Extension
.c- Size
- 7118 bytes
- Lines
- 281
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/err.hlinux/i2c.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/module.hlinux/regmap.h
Detected Declarations
struct veml6040_dataenum veml6040_chanfunction veml6040_read_rawfunction veml6040_write_rawfunction veml6040_read_availfunction veml6040_shutdown_actionfunction veml6040_probe
Annotated Snippet
struct veml6040_data {
struct i2c_client *client;
struct regmap *regmap;
};
static const struct regmap_config veml6040_regmap_config = {
.name = "veml6040_regmap",
.reg_bits = 8,
.val_bits = 16,
.max_register = VEML6040_REG_W,
.val_format_endian = REGMAP_ENDIAN_LITTLE,
};
static int veml6040_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val,
int *val2, long mask)
{
int ret, reg, it_index;
struct veml6040_data *data = iio_priv(indio_dev);
struct regmap *regmap = data->regmap;
struct device *dev = &data->client->dev;
switch (mask) {
case IIO_CHAN_INFO_RAW:
ret = regmap_read(regmap, chan->address, ®);
if (ret) {
dev_err(dev, "Data read failed: %d\n", ret);
return ret;
}
*val = reg;
return IIO_VAL_INT;
case IIO_CHAN_INFO_INT_TIME:
ret = regmap_read(regmap, VEML6040_CONF_REG, ®);
if (ret) {
dev_err(dev, "Data read failed: %d\n", ret);
return ret;
}
it_index = FIELD_GET(VEML6040_CONF_IT_MSK, reg);
if (it_index >= ARRAY_SIZE(veml6040_it_ms)) {
dev_err(dev, "Invalid Integration Time Set");
return -EINVAL;
}
*val = veml6040_it_ms[it_index];
return IIO_VAL_INT;
default:
return -EINVAL;
}
}
static int veml6040_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int val,
int val2, long mask)
{
struct veml6040_data *data = iio_priv(indio_dev);
switch (mask) {
case IIO_CHAN_INFO_INT_TIME:
for (int i = 0; i < ARRAY_SIZE(veml6040_it_ms); i++) {
if (veml6040_it_ms[i] != val)
continue;
return regmap_update_bits(data->regmap,
VEML6040_CONF_REG,
VEML6040_CONF_IT_MSK,
FIELD_PREP(VEML6040_CONF_IT_MSK, i));
}
return -EINVAL;
default:
return -EINVAL;
}
}
static int veml6040_read_avail(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
const int **vals, int *type, int *length,
long mask)
{
switch (mask) {
case IIO_CHAN_INFO_INT_TIME:
*length = ARRAY_SIZE(veml6040_it_ms);
*vals = veml6040_it_ms;
*type = IIO_VAL_INT;
return IIO_AVAIL_LIST;
default:
return -EINVAL;
}
}
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/err.h`, `linux/i2c.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`, `linux/module.h`, `linux/regmap.h`.
- Detected declarations: `struct veml6040_data`, `enum veml6040_chan`, `function veml6040_read_raw`, `function veml6040_write_raw`, `function veml6040_read_avail`, `function veml6040_shutdown_action`, `function veml6040_probe`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
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.