drivers/iio/light/tsl2591.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/tsl2591.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/tsl2591.c- Extension
.c- Size
- 32890 bytes
- Lines
- 1222
- 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/bitfield.hlinux/debugfs.hlinux/delay.hlinux/i2c.hlinux/interrupt.hlinux/iopoll.hlinux/kernel.hlinux/module.hlinux/mutex.hlinux/pm_runtime.hlinux/sysfs.hlinux/unaligned.hlinux/iio/events.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct tsl2591_als_settingsstruct tsl2591_chipfunction tsl2591_gain_to_multiplierfunction tsl2591_multiplier_to_gainfunction tsl2591_persist_cycle_to_litfunction tsl2591_persist_lit_to_cyclefunction tsl2591_compatible_int_timefunction tsl2591_als_time_to_fvalfunction tsl2591_compatible_gainfunction tsl2591_compatible_als_persist_cyclefunction tsl2591_check_als_validfunction tsl2591_wait_adc_completefunction Luxfunction tsl2591_set_als_gain_int_timefunction tsl2591_set_als_lower_thresholdfunction tsl2591_set_als_upper_thresholdfunction tsl2591_set_als_persist_cyclefunction tsl2591_set_power_statefunction tsl2591_in_illuminance_period_available_showfunction tsl2591_read_rawfunction tsl2591_write_rawfunction tsl2591_read_availablefunction tsl2591_read_event_valuefunction tsl2591_write_event_valuefunction tsl2591_read_event_configfunction tsl2591_write_event_configfunction tsl2591_suspendfunction tsl2591_resumefunction tsl2591_event_handlerfunction tsl2591_load_defaultsfunction tsl2591_chip_offfunction tsl2591_probe
Annotated Snippet
struct tsl2591_als_settings {
u16 als_lower_thresh;
u16 als_upper_thresh;
u8 als_int_time;
u8 als_persist;
u8 als_gain;
};
struct tsl2591_chip {
struct tsl2591_als_settings als_settings;
struct i2c_client *client;
/*
* Keep als_settings in sync with hardware state
* and ensure multiple readers are serialized.
*/
struct mutex als_mutex;
bool events_enabled;
};
/*
* Period table is ALS persist cycle x integration time setting
* Integration times: 100ms, 200ms, 300ms, 400ms, 500ms, 600ms
* ALS cycles: 1, 2, 3, 5, 10, 20, 25, 30, 35, 40, 45, 50, 55, 60
*/
static const char * const tsl2591_als_period_list[] = {
"0.1 0.2 0.3 0.5 1.0 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0",
"0.2 0.4 0.6 1.0 2.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0",
"0.3 0.6 0.9 1.5 3.0 6.0 7.5 9.0 10.5 12.0 13.5 15.0 16.5 18.0",
"0.4 0.8 1.2 2.0 4.0 8.0 10.0 12.0 14.0 16.0 18.0 20.0 22.0 24.0",
"0.5 1.0 1.5 2.5 5.0 10.0 12.5 15.0 17.5 20.0 22.5 25.0 27.5 30.0",
"0.6 1.2 1.8 3.0 6.0 12.0 15.0 18.0 21.0 24.0 27.0 30.0 33.0 36.0",
};
static const int tsl2591_int_time_available[] = {
1, 2, 3, 4, 5, 6,
};
static const int tsl2591_calibscale_available[] = {
1, 25, 428, 9876,
};
static int tsl2591_set_als_lower_threshold(struct tsl2591_chip *chip,
u16 als_lower_threshold);
static int tsl2591_set_als_upper_threshold(struct tsl2591_chip *chip,
u16 als_upper_threshold);
static int tsl2591_gain_to_multiplier(const u8 als_gain)
{
switch (als_gain) {
case TSL2591_CTRL_ALS_LOW_GAIN:
return TSL2591_CTRL_ALS_LOW_GAIN_MULTIPLIER;
case TSL2591_CTRL_ALS_MED_GAIN:
return TSL2591_CTRL_ALS_MED_GAIN_MULTIPLIER;
case TSL2591_CTRL_ALS_HIGH_GAIN:
return TSL2591_CTRL_ALS_HIGH_GAIN_MULTIPLIER;
case TSL2591_CTRL_ALS_MAX_GAIN:
return TSL2591_CTRL_ALS_MAX_GAIN_MULTIPLIER;
default:
return -EINVAL;
}
}
static int tsl2591_multiplier_to_gain(const u32 multiplier)
{
switch (multiplier) {
case TSL2591_CTRL_ALS_LOW_GAIN_MULTIPLIER:
return TSL2591_CTRL_ALS_LOW_GAIN;
case TSL2591_CTRL_ALS_MED_GAIN_MULTIPLIER:
return TSL2591_CTRL_ALS_MED_GAIN;
case TSL2591_CTRL_ALS_HIGH_GAIN_MULTIPLIER:
return TSL2591_CTRL_ALS_HIGH_GAIN;
case TSL2591_CTRL_ALS_MAX_GAIN_MULTIPLIER:
return TSL2591_CTRL_ALS_MAX_GAIN;
default:
return -EINVAL;
}
}
static int tsl2591_persist_cycle_to_lit(const u8 als_persist)
{
switch (als_persist) {
case TSL2591_PRST_ALS_INT_CYCLE_ANY:
return 1;
case TSL2591_PRST_ALS_INT_CYCLE_2:
return 2;
case TSL2591_PRST_ALS_INT_CYCLE_3:
return 3;
case TSL2591_PRST_ALS_INT_CYCLE_5:
return 5;
case TSL2591_PRST_ALS_INT_CYCLE_10:
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/debugfs.h`, `linux/delay.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/iopoll.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `struct tsl2591_als_settings`, `struct tsl2591_chip`, `function tsl2591_gain_to_multiplier`, `function tsl2591_multiplier_to_gain`, `function tsl2591_persist_cycle_to_lit`, `function tsl2591_persist_lit_to_cycle`, `function tsl2591_compatible_int_time`, `function tsl2591_als_time_to_fval`, `function tsl2591_compatible_gain`, `function tsl2591_compatible_als_persist_cycle`.
- 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.