drivers/iio/light/opt3001.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/opt3001.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/opt3001.c- Extension
.c- Size
- 22289 bytes
- Lines
- 980
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/delay.hlinux/device.hlinux/i2c.hlinux/interrupt.hlinux/irq.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/mutex.hlinux/slab.hlinux/types.hlinux/iio/events.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct opt3001_scalestruct opt3001_chip_infostruct opt3001function opt3001_find_scalefunction opt3001_to_iio_retfunction opt3001_set_modefunction opt3001_get_processedfunction opt3001_get_int_timefunction opt3001_set_int_timefunction opt3001_read_rawfunction opt3001_write_rawfunction opt3001_read_event_valuefunction opt3001_write_event_valuefunction opt3001_read_event_configfunction opt3001_write_event_configfunction opt3001_read_idfunction opt3001_configurefunction opt3001_irqfunction opt3001_probefunction opt3001_remove
Annotated Snippet
struct opt3001_scale {
int val;
int val2;
};
struct opt3001_chip_info {
const struct iio_chan_spec (*channels)[2];
enum iio_chan_type chan_type;
int num_channels;
const struct opt3001_scale (*scales)[12];
/*
* Factor as specified by conversion equation in datasheet.
* eg. 0.01 (scaled to integer 10) for opt3001.
*/
int factor_whole;
/*
* Factor to compensate for potentially scaled factor_whole.
*/
int factor_integer;
/*
* Factor used to align decimal part of processed value to six decimal
* places.
*/
int factor_decimal;
bool has_id;
};
struct opt3001 {
struct i2c_client *client;
struct device *dev;
struct mutex lock;
bool ok_to_ignore_lock;
bool result_ready;
wait_queue_head_t result_ready_queue;
u16 result;
const struct opt3001_chip_info *chip_info;
u32 int_time;
u32 mode;
u16 high_thresh_mantissa;
u16 low_thresh_mantissa;
u8 high_thresh_exp;
u8 low_thresh_exp;
bool use_irq;
};
static const struct opt3001_scale opt3001_scales[] = {
{
.val = 40,
.val2 = 950000,
},
{
.val = 81,
.val2 = 900000,
},
{
.val = 163,
.val2 = 800000,
},
{
.val = 327,
.val2 = 600000,
},
{
.val = 655,
.val2 = 200000,
},
{
.val = 1310,
.val2 = 400000,
},
{
.val = 2620,
.val2 = 800000,
},
{
.val = 5241,
.val2 = 600000,
},
{
.val = 10483,
.val2 = 200000,
},
{
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/delay.h`, `linux/device.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `struct opt3001_scale`, `struct opt3001_chip_info`, `struct opt3001`, `function opt3001_find_scale`, `function opt3001_to_iio_ret`, `function opt3001_set_mode`, `function opt3001_get_processed`, `function opt3001_get_int_time`, `function opt3001_set_int_time`, `function opt3001_read_raw`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.