drivers/iio/light/opt4001.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/opt4001.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/opt4001.c- Extension
.c- Size
- 12305 bytes
- Lines
- 467
- 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/iio/iio.hlinux/math64.hlinux/module.hlinux/property.hlinux/regmap.hlinux/regulator/consumer.h
Detected Declarations
struct opt4001_chip_infostruct opt4001_chipfunction opt4001_als_time_to_indexfunction opt4001_calculate_crcfunction opt4001_read_lux_valuefunction opt4001_set_conffunction opt4001_power_downfunction opt4001_chip_off_actionfunction opt4001_read_rawfunction opt4001_write_rawfunction opt4001_read_availablefunction opt4001_load_defaultsfunction opt4001_readable_regfunction opt4001_writable_regfunction opt4001_volatile_regfunction opt4001_probe
Annotated Snippet
struct opt4001_chip_info {
int mul;
int div;
const char *name;
};
struct opt4001_chip {
struct regmap *regmap;
struct i2c_client *client;
u8 int_time;
const struct opt4001_chip_info *chip_info;
};
static const struct opt4001_chip_info opt4001_sot_5x3_info = {
.mul = 4375,
.div = 10000000,
.name = "opt4001-sot-5x3"
};
static const struct opt4001_chip_info opt4001_picostar_info = {
.mul = 3125,
.div = 10000000,
.name = "opt4001-picostar"
};
static const int opt4001_int_time_available[][2] = {
{ 0, 600 },
{ 0, 1000 },
{ 0, 1800 },
{ 0, 3400 },
{ 0, 6500 },
{ 0, 12700 },
{ 0, 25000 },
{ 0, 50000 },
{ 0, 100000 },
{ 0, 200000 },
{ 0, 400000 },
{ 0, 800000 },
};
/*
* Conversion time is integration time + time to set register
* this is used as integration time.
*/
static const int opt4001_int_time_reg[][2] = {
{ 600, OPT4001_CTRL_CONVERSION_0_6MS },
{ 1000, OPT4001_CTRL_CONVERSION_1MS },
{ 1800, OPT4001_CTRL_CONVERSION_1_8MS },
{ 3400, OPT4001_CTRL_CONVERSION_3_4MS },
{ 6500, OPT4001_CTRL_CONVERSION_6_5MS },
{ 12700, OPT4001_CTRL_CONVERSION_12_7MS },
{ 25000, OPT4001_CTRL_CONVERSION_25MS },
{ 50000, OPT4001_CTRL_CONVERSION_50MS },
{ 100000, OPT4001_CTRL_CONVERSION_100MS },
{ 200000, OPT4001_CTRL_CONVERSION_200MS },
{ 400000, OPT4001_CTRL_CONVERSION_400MS },
{ 800000, OPT4001_CTRL_CONVERSION_800MS },
};
static int opt4001_als_time_to_index(const u32 als_integration_time)
{
int i;
for (i = 0; i < ARRAY_SIZE(opt4001_int_time_available); i++) {
if (als_integration_time == opt4001_int_time_available[i][1])
return i;
}
return -EINVAL;
}
static u8 opt4001_calculate_crc(u8 exp, u32 mantissa, u8 count)
{
u8 crc;
crc = (hweight32(mantissa) + hweight32(exp) + hweight32(count)) % 2;
crc |= ((hweight32(mantissa & 0xAAAAA) + hweight32(exp & 0xA)
+ hweight32(count & 0xA)) % 2) << 1;
crc |= ((hweight32(mantissa & 0x88888) + hweight32(exp & 0x8)
+ hweight32(count & 0x8)) % 2) << 2;
crc |= (hweight32(mantissa & 0x80808) % 2) << 3;
return crc;
}
static int opt4001_read_lux_value(struct iio_dev *indio_dev,
int *val, int *val2)
{
struct opt4001_chip *chip = iio_priv(indio_dev);
struct device *dev = &chip->client->dev;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/i2c.h`, `linux/iio/iio.h`, `linux/math64.h`, `linux/module.h`, `linux/property.h`, `linux/regmap.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct opt4001_chip_info`, `struct opt4001_chip`, `function opt4001_als_time_to_index`, `function opt4001_calculate_crc`, `function opt4001_read_lux_value`, `function opt4001_set_conf`, `function opt4001_power_down`, `function opt4001_chip_off_action`, `function opt4001_read_raw`, `function opt4001_write_raw`.
- 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.