drivers/iio/light/tsl2583.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/tsl2583.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/tsl2583.c- Extension
.c- Size
- 24017 bytes
- Lines
- 948
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/i2c.hlinux/errno.hlinux/delay.hlinux/string.hlinux/mutex.hlinux/unistd.hlinux/slab.hlinux/module.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/pm_runtime.h
Detected Declarations
struct tsl2583_als_infostruct tsl2583_luxstruct tsl2583_settingsstruct tsl2583_chipstruct gainadjfunction tsl2583_defaultsfunction tsl2583_get_luxfunction als_gain_trimfunction tsl2583_set_als_timefunction tsl2583_set_als_gainfunction tsl2583_set_power_statefunction tsl2583_chip_init_and_power_onfunction in_illuminance_input_target_showfunction in_illuminance_input_target_storefunction in_illuminance_calibrate_storefunction in_illuminance_lux_table_showfunction in_illuminance_lux_table_storefunction tsl2583_set_pm_runtime_busyfunction tsl2583_read_rawfunction tsl2583_write_rawfunction tsl2583_probefunction tsl2583_removefunction tsl2583_suspendfunction tsl2583_resume
Annotated Snippet
struct tsl2583_als_info {
u16 als_ch0;
u16 als_ch1;
u16 lux;
};
struct tsl2583_lux {
unsigned int ratio;
unsigned int ch0;
unsigned int ch1;
};
static const struct tsl2583_lux tsl2583_default_lux[] = {
{ 9830, 8520, 15729 },
{ 12452, 10807, 23344 },
{ 14746, 6383, 11705 },
{ 17695, 4063, 6554 },
{ 0, 0, 0 } /* Termination segment */
};
#define TSL2583_MAX_LUX_TABLE_ENTRIES 11
struct tsl2583_settings {
int als_time;
int als_gain;
int als_gain_trim;
int als_cal_target;
/*
* This structure is intentionally large to accommodate updates via
* sysfs. Sized to 11 = max 10 segments + 1 termination segment.
* Assumption is that one and only one type of glass used.
*/
struct tsl2583_lux als_device_lux[TSL2583_MAX_LUX_TABLE_ENTRIES];
};
struct tsl2583_chip {
struct mutex als_mutex;
struct i2c_client *client;
struct tsl2583_als_info als_cur_info;
struct tsl2583_settings als_settings;
int als_time_scale;
int als_saturation;
};
struct gainadj {
s16 ch0;
s16 ch1;
s16 mean;
};
/* Index = (0 - 3) Used to validate the gain selection index */
static const struct gainadj gainadj[] = {
{ 1, 1, 1 },
{ 8, 8, 8 },
{ 16, 16, 16 },
{ 107, 115, 111 }
};
/*
* Provides initial operational parameter defaults.
* These defaults may be changed through the device's sysfs files.
*/
static void tsl2583_defaults(struct tsl2583_chip *chip)
{
/*
* The integration time must be a multiple of 50ms and within the
* range [50, 600] ms.
*/
chip->als_settings.als_time = 100;
/*
* This is an index into the gainadj table. Assume clear glass as the
* default.
*/
chip->als_settings.als_gain = 0;
/* Default gain trim to account for aperture effects */
chip->als_settings.als_gain_trim = 1000;
/* Known external ALS reading used for calibration */
chip->als_settings.als_cal_target = 130;
/* Default lux table. */
memcpy(chip->als_settings.als_device_lux, tsl2583_default_lux,
sizeof(tsl2583_default_lux));
}
/*
* Reads and calculates current lux value.
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/i2c.h`, `linux/errno.h`, `linux/delay.h`, `linux/string.h`, `linux/mutex.h`, `linux/unistd.h`, `linux/slab.h`.
- Detected declarations: `struct tsl2583_als_info`, `struct tsl2583_lux`, `struct tsl2583_settings`, `struct tsl2583_chip`, `struct gainadj`, `function tsl2583_defaults`, `function tsl2583_get_lux`, `function als_gain_trim`, `function tsl2583_set_als_time`, `function tsl2583_set_als_gain`.
- 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.
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.