drivers/iio/light/isl76682.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/isl76682.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/isl76682.c- Extension
.c- Size
- 8384 bytes
- Lines
- 346
- 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/array_size.hlinux/bits.hlinux/cleanup.hlinux/delay.hlinux/err.hlinux/i2c.hlinux/module.hlinux/mutex.hlinux/regmap.hlinux/types.hlinux/iio/iio.h
Detected Declarations
struct isl76682_chipstruct isl76682_rangefunction isl76682_getfunction isl76682_write_rawfunction isl76682_read_rawfunction isl76682_read_availfunction isl76682_clear_configure_regfunction isl76682_reset_actionfunction isl76682_is_volatile_regfunction isl76682_probe
Annotated Snippet
struct isl76682_chip {
/*
* Lock to synchronize access to device command register
* and the content of range variable below.
*/
struct mutex lock;
struct regmap *regmap;
u8 range;
u8 command;
};
struct isl76682_range {
u8 range;
u32 als;
u32 ir;
};
static const struct isl76682_range isl76682_range_table[] = {
{ ISL76682_COMMAND_RANGE_LUX_1K, 15000, 10500 },
{ ISL76682_COMMAND_RANGE_LUX_4K, 60000, 42000 },
{ ISL76682_COMMAND_RANGE_LUX_16K, 240000, 168000 },
{ ISL76682_COMMAND_RANGE_LUX_64K, 960000, 673000 }
};
static int isl76682_get(struct isl76682_chip *chip, bool mode_ir, int *data)
{
u8 command;
int ret;
command = ISL76682_COMMAND_EN | ISL76682_COMMAND_MODE_CONTINUOUS |
chip->range;
if (mode_ir)
command |= ISL76682_COMMAND_LIGHT_IR;
if (command != chip->command) {
ret = regmap_write(chip->regmap, ISL76682_REG_COMMAND, command);
if (ret)
return ret;
/* Need to wait for conversion time if ALS/IR mode enabled */
msleep(ISL76682_CONV_TIME_MS);
chip->command = command;
}
ret = regmap_bulk_read(chip->regmap, ISL76682_REG_ALSIR_L, data, 2);
*data &= ISL76682_ADC_MAX;
return ret;
}
static int isl76682_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val, int val2, long mask)
{
struct isl76682_chip *chip = iio_priv(indio_dev);
int i;
if (mask != IIO_CHAN_INFO_SCALE)
return -EINVAL;
if (val != 0)
return -EINVAL;
for (i = 0; i < ARRAY_SIZE(isl76682_range_table); i++) {
if (chan->type == IIO_LIGHT && val2 != isl76682_range_table[i].als)
continue;
if (chan->type == IIO_INTENSITY && val2 != isl76682_range_table[i].ir)
continue;
scoped_guard(mutex, &chip->lock)
chip->range = isl76682_range_table[i].range;
return 0;
}
return -EINVAL;
}
static int isl76682_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct isl76682_chip *chip = iio_priv(indio_dev);
int ret;
int i;
guard(mutex)(&chip->lock);
switch (mask) {
case IIO_CHAN_INFO_RAW:
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bits.h`, `linux/cleanup.h`, `linux/delay.h`, `linux/err.h`, `linux/i2c.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct isl76682_chip`, `struct isl76682_range`, `function isl76682_get`, `function isl76682_write_raw`, `function isl76682_read_raw`, `function isl76682_read_avail`, `function isl76682_clear_configure_reg`, `function isl76682_reset_action`, `function isl76682_is_volatile_reg`, `function isl76682_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.