drivers/iio/light/apds9306.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/apds9306.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/apds9306.c- Extension
.c- Size
- 36575 bytes
- Lines
- 1358
- 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.
- 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/bits.hlinux/cleanup.hlinux/delay.hlinux/err.hlinux/i2c.hlinux/interrupt.hlinux/minmax.hlinux/module.hlinux/mutex.hlinux/pm.hlinux/pm_runtime.hlinux/regmap.hlinux/regulator/consumer.hlinux/types.hlinux/units.hlinux/iio/iio.hlinux/iio/iio-gts-helper.hlinux/iio/events.hlinux/iio/sysfs.hlinux/unaligned.h
Detected Declarations
struct part_id_gts_multiplierstruct apds9306_regfieldsstruct apds9306_datafunction apds9306_regfield_initfunction apds9306_power_statefunction apds9306_read_datafunction apds9306_intg_time_getfunction apds9306_intg_time_setfunction apds9306_sampling_freq_getfunction apds9306_sampling_freq_setfunction apds9306_scale_getfunction apds9306_scale_setfunction apds9306_event_period_getfunction apds9306_event_period_setfunction apds9306_get_thresh_regfunction apds9306_event_thresh_getfunction apds9306_event_thresh_setfunction apds9306_event_thresh_adaptive_getfunction apds9306_event_thresh_adaptive_setfunction apds9306_read_rawfunction apds9306_read_availfunction apds9306_write_raw_get_fmtfunction apds9306_write_rawfunction apds9306_irq_handlerfunction apds9306_read_eventfunction apds9306_write_eventfunction apds9306_read_event_configfunction apds9306_write_event_configfunction apds9306_init_iio_gtsfunction apds9306_powerdownfunction apds9306_device_initfunction apds9306_pm_initfunction apds9306_probefunction apds9306_runtime_suspendfunction apds9306_runtime_resume
Annotated Snippet
struct part_id_gts_multiplier {
int part_id;
int max_scale_int;
int max_scale_nano;
};
/*
* As per the datasheet, at HW Gain = 3x, Integration time 100mS (32x),
* typical 2000 ADC counts are observed for 49.8 uW per sq cm (340.134 lux)
* for apds9306 and 43 uW per sq cm (293.69 lux) for apds9306-065.
* Assuming lux per count is linear across all integration time ranges.
*
* Lux = (raw + offset) * scale; offset can be any value by userspace.
* HG = Hardware Gain; ITG = Gain by changing integration time.
* Scale table by IIO GTS Helpers = (1 / HG) * (1 / ITG) * Multiplier.
*
* The Lux values provided in the datasheet are at ITG=32x and HG=3x,
* at typical 2000 count for both variants of the device.
*
* Lux per ADC count at 3x and 32x for apds9306 = 340.134 / 2000
* Lux per ADC count at 3x and 32x for apds9306-065 = 293.69 / 2000
*
* The Multiplier for the scale table provided to userspace:
* IIO GTS scale Multiplier for apds9306 = (340.134 / 2000) * 32 * 3 = 16.326432
* and for apds9306-065 = (293.69 / 2000) * 32 * 3 = 14.09712
*/
static const struct part_id_gts_multiplier apds9306_gts_mul[] = {
{
.part_id = 0xB1,
.max_scale_int = 16,
.max_scale_nano = 326432000,
}, {
.part_id = 0xB3,
.max_scale_int = 14,
.max_scale_nano = 97120000,
},
};
static const int apds9306_repeat_rate_freq[APDS9306_NUM_REPEAT_RATES][2] = {
{ 40, 0 },
{ 20, 0 },
{ 10, 0 },
{ 5, 0 },
{ 2, 0 },
{ 1, 0 },
{ 0, 500000 },
};
static const int apds9306_repeat_rate_period[APDS9306_NUM_REPEAT_RATES] = {
25000, 50000, 100000, 200000, 500000, 1000000, 2000000,
};
/**
* struct apds9306_regfields - apds9306 regmap fields definitions
*
* @sw_reset: Software reset regfield
* @en: Enable regfield
* @intg_time: Resolution regfield
* @repeat_rate: Measurement Rate regfield
* @gain: Hardware gain regfield
* @int_src: Interrupt channel regfield
* @int_thresh_var_en: Interrupt variance threshold regfield
* @int_en: Interrupt enable regfield
* @int_persist_val: Interrupt persistence regfield
* @int_thresh_var_val: Interrupt threshold variance value regfield
*/
struct apds9306_regfields {
struct regmap_field *sw_reset;
struct regmap_field *en;
struct regmap_field *intg_time;
struct regmap_field *repeat_rate;
struct regmap_field *gain;
struct regmap_field *int_src;
struct regmap_field *int_thresh_var_en;
struct regmap_field *int_en;
struct regmap_field *int_persist_val;
struct regmap_field *int_thresh_var_val;
};
/**
* struct apds9306_data - apds9306 private data and registers definitions
*
* @dev: Pointer to the device structure
* @gts: IIO Gain Time Scale structure
* @mutex: Lock for protecting adc reads, device settings changes where
* some calculations are required before or after setting or
* getting the raw settings values from regmap writes or reads
* respectively.
* @regmap: Regmap structure pointer
* @rf: Regmap register fields structure
Annotation
- Immediate include surface: `linux/bits.h`, `linux/cleanup.h`, `linux/delay.h`, `linux/err.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/minmax.h`, `linux/module.h`.
- Detected declarations: `struct part_id_gts_multiplier`, `struct apds9306_regfields`, `struct apds9306_data`, `function apds9306_regfield_init`, `function apds9306_power_state`, `function apds9306_read_data`, `function apds9306_intg_time_get`, `function apds9306_intg_time_set`, `function apds9306_sampling_freq_get`, `function apds9306_sampling_freq_set`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- 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.