drivers/iio/light/al3320a.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/al3320a.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/al3320a.c- Extension
.c- Size
- 7008 bytes
- Lines
- 282
- 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/i2c.hlinux/module.hlinux/regmap.hlinux/mod_devicetable.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct al3320a_dataenum al3320a_rangefunction al3320a_set_pwr_onfunction al3320a_set_pwr_offfunction al3320a_initfunction al3320a_read_rawfunction al3320a_write_rawfunction al3320a_probefunction al3320a_suspendfunction al3320a_resume
Annotated Snippet
struct al3320a_data {
struct regmap *regmap;
};
static const struct iio_chan_spec al3320a_channels[] = {
{
.type = IIO_LIGHT,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_SCALE),
}
};
static IIO_CONST_ATTR(in_illuminance_scale_available, AL3320A_SCALE_AVAILABLE);
static struct attribute *al3320a_attributes[] = {
&iio_const_attr_in_illuminance_scale_available.dev_attr.attr,
NULL,
};
static const struct attribute_group al3320a_attribute_group = {
.attrs = al3320a_attributes,
};
static int al3320a_set_pwr_on(struct al3320a_data *data)
{
return regmap_write(data->regmap, AL3320A_REG_CONFIG, AL3320A_CONFIG_ENABLE);
}
static void al3320a_set_pwr_off(void *_data)
{
struct al3320a_data *data = _data;
struct device *dev = regmap_get_device(data->regmap);
int ret;
ret = regmap_write(data->regmap, AL3320A_REG_CONFIG, AL3320A_CONFIG_DISABLE);
if (ret)
dev_err(dev, "failed to write system register\n");
}
static int al3320a_init(struct al3320a_data *data)
{
struct device *dev = regmap_get_device(data->regmap);
int ret;
ret = al3320a_set_pwr_on(data);
if (ret)
return ret;
ret = devm_add_action_or_reset(dev, al3320a_set_pwr_off, data);
if (ret)
return ret;
ret = regmap_write(data->regmap, AL3320A_REG_CONFIG_RANGE,
FIELD_PREP(AL3320A_GAIN_MASK, AL3320A_RANGE_3));
if (ret)
return ret;
ret = regmap_write(data->regmap, AL3320A_REG_MEAN_TIME,
AL3320A_DEFAULT_MEAN_TIME);
if (ret)
return ret;
return regmap_write(data->regmap, AL3320A_REG_WAIT,
AL3320A_DEFAULT_WAIT_TIME);
}
static int al3320a_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *val,
int *val2, long mask)
{
struct al3320a_data *data = iio_priv(indio_dev);
int ret, gain, raw;
switch (mask) {
case IIO_CHAN_INFO_RAW:
/*
* ALS ADC value is stored in two adjacent registers:
* - low byte of output is stored at AL3320A_REG_DATA_LOW
* - high byte of output is stored at AL3320A_REG_DATA_LOW + 1
*/
ret = regmap_read(data->regmap, AL3320A_REG_DATA_LOW, &raw);
if (ret)
return ret;
*val = raw;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
ret = regmap_read(data->regmap, AL3320A_REG_CONFIG_RANGE, &gain);
if (ret)
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/i2c.h`, `linux/module.h`, `linux/regmap.h`, `linux/mod_devicetable.h`, `linux/iio/iio.h`, `linux/iio/sysfs.h`.
- Detected declarations: `struct al3320a_data`, `enum al3320a_range`, `function al3320a_set_pwr_on`, `function al3320a_set_pwr_off`, `function al3320a_init`, `function al3320a_read_raw`, `function al3320a_write_raw`, `function al3320a_probe`, `function al3320a_suspend`, `function al3320a_resume`.
- 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.