drivers/iio/light/veml3235.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/veml3235.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/veml3235.c- Extension
.c- Size
- 13745 bytes
- Lines
- 548
- 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/err.hlinux/i2c.hlinux/iio/iio.hlinux/iio/iio-gts-helper.hlinux/module.hlinux/pm_runtime.hlinux/regmap.hlinux/regulator/consumer.h
Detected Declarations
struct veml3235_rfstruct veml3235_dataenum veml3235_chanfunction veml3235_power_onfunction veml3235_shut_downfunction veml3235_shut_down_actionfunction veml3235_get_itfunction veml3235_set_itfunction veml3235_set_scalefunction veml3235_get_scalefunction veml3235_read_rawfunction veml3235_read_availfunction veml3235_write_raw_get_fmtfunction veml3235_write_rawfunction veml3235_read_idfunction veml3235_regfield_initfunction veml3235_hw_initfunction veml3235_probefunction veml3235_runtime_suspendfunction veml3235_runtime_resume
Annotated Snippet
struct veml3235_rf {
struct regmap_field *it;
struct regmap_field *gain;
struct regmap_field *id;
};
struct veml3235_data {
struct i2c_client *client;
struct device *dev;
struct regmap *regmap;
struct veml3235_rf rf;
struct iio_gts gts;
};
static const struct iio_itime_sel_mul veml3235_it_sel[] = {
GAIN_SCALE_ITIME_US(50000, 0, 1),
GAIN_SCALE_ITIME_US(100000, 1, 2),
GAIN_SCALE_ITIME_US(200000, 2, 4),
GAIN_SCALE_ITIME_US(400000, 3, 8),
GAIN_SCALE_ITIME_US(800000, 4, 16),
};
/*
* The MSB (DG) doubles the value of the rest of the field, which leads to
* two possible combinations to obtain gain = 2 and gain = 4. The gain
* handling can be simplified by restricting DG = 1 to the only gain that
* really requires it, gain = 8. Note that "X10" is a reserved value.
*/
#define VEML3235_SEL_GAIN_X1 0
#define VEML3235_SEL_GAIN_X2 1
#define VEML3235_SEL_GAIN_X4 3
#define VEML3235_SEL_GAIN_X8 7
static const struct iio_gain_sel_pair veml3235_gain_sel[] = {
GAIN_SCALE_GAIN(1, VEML3235_SEL_GAIN_X1),
GAIN_SCALE_GAIN(2, VEML3235_SEL_GAIN_X2),
GAIN_SCALE_GAIN(4, VEML3235_SEL_GAIN_X4),
GAIN_SCALE_GAIN(8, VEML3235_SEL_GAIN_X8),
};
static int veml3235_power_on(struct veml3235_data *data)
{
int ret;
ret = regmap_clear_bits(data->regmap, VEML3235_REG_CONF,
VEML3235_CONF_SD | VEML3235_CONF_SD0);
if (ret)
return ret;
/* Wait 4 ms to let processor & oscillator start correctly */
fsleep(4000);
return 0;
}
static int veml3235_shut_down(struct veml3235_data *data)
{
return regmap_set_bits(data->regmap, VEML3235_REG_CONF,
VEML3235_CONF_SD | VEML3235_CONF_SD0);
}
static void veml3235_shut_down_action(void *data)
{
veml3235_shut_down(data);
}
enum veml3235_chan {
CH_ALS,
CH_WHITE,
};
static const struct iio_chan_spec veml3235_channels[] = {
{
.type = IIO_LIGHT,
.channel = CH_ALS,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) |
BIT(IIO_CHAN_INFO_SCALE),
.info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) |
BIT(IIO_CHAN_INFO_SCALE),
},
{
.type = IIO_INTENSITY,
.channel = CH_WHITE,
.modified = 1,
.channel2 = IIO_MOD_LIGHT_BOTH,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_INT_TIME) |
BIT(IIO_CHAN_INFO_SCALE),
.info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_INT_TIME) |
BIT(IIO_CHAN_INFO_SCALE),
Annotation
- Immediate include surface: `linux/err.h`, `linux/i2c.h`, `linux/iio/iio.h`, `linux/iio/iio-gts-helper.h`, `linux/module.h`, `linux/pm_runtime.h`, `linux/regmap.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct veml3235_rf`, `struct veml3235_data`, `enum veml3235_chan`, `function veml3235_power_on`, `function veml3235_shut_down`, `function veml3235_shut_down_action`, `function veml3235_get_it`, `function veml3235_set_it`, `function veml3235_set_scale`, `function veml3235_get_scale`.
- 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.