drivers/misc/tsl2550.c
Source file repositories/reference/linux-study-clean/drivers/misc/tsl2550.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/tsl2550.c- Extension
.c- Size
- 10134 bytes
- Lines
- 451
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/slab.hlinux/i2c.hlinux/mutex.h
Detected Declarations
struct tsl2550_datafunction tsl2550_set_operating_modefunction tsl2550_set_power_statefunction tsl2550_get_adc_valuefunction tsl2550_calculate_luxfunction tsl2550_show_power_statefunction tsl2550_store_power_statefunction tsl2550_show_operating_modefunction tsl2550_store_operating_modefunction __tsl2550_show_luxfunction tsl2550_show_lux1_inputfunction tsl2550_init_clientfunction tsl2550_probefunction tsl2550_removefunction tsl2550_suspendfunction tsl2550_resume
Annotated Snippet
struct tsl2550_data {
struct i2c_client *client;
struct mutex update_lock;
unsigned int power_state:1;
unsigned int operating_mode:1;
};
/*
* Global data
*/
static const u8 TSL2550_MODE_RANGE[2] = {
TSL2550_STANDARD_RANGE, TSL2550_EXTENDED_RANGE,
};
/*
* Management functions
*/
static int tsl2550_set_operating_mode(struct i2c_client *client, int mode)
{
struct tsl2550_data *data = i2c_get_clientdata(client);
int ret = i2c_smbus_write_byte(client, TSL2550_MODE_RANGE[mode]);
data->operating_mode = mode;
return ret;
}
static int tsl2550_set_power_state(struct i2c_client *client, int state)
{
struct tsl2550_data *data = i2c_get_clientdata(client);
int ret;
if (state == 0)
ret = i2c_smbus_write_byte(client, TSL2550_POWER_DOWN);
else {
ret = i2c_smbus_write_byte(client, TSL2550_POWER_UP);
/* On power up we should reset operating mode also... */
tsl2550_set_operating_mode(client, data->operating_mode);
}
data->power_state = state;
return ret;
}
static int tsl2550_get_adc_value(struct i2c_client *client, u8 cmd)
{
int ret;
ret = i2c_smbus_read_byte_data(client, cmd);
if (ret < 0)
return ret;
if (!(ret & 0x80))
return -EAGAIN;
return ret & 0x7f; /* remove the "valid" bit */
}
/*
* LUX calculation
*/
#define TSL2550_MAX_LUX 1846
static const u8 ratio_lut[] = {
100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 98, 98, 98, 98, 98,
98, 98, 97, 97, 97, 97, 97, 96,
96, 96, 96, 95, 95, 95, 94, 94,
93, 93, 93, 92, 92, 91, 91, 90,
89, 89, 88, 87, 87, 86, 85, 84,
83, 82, 81, 80, 79, 78, 77, 75,
74, 73, 71, 69, 68, 66, 64, 62,
60, 58, 56, 54, 52, 49, 47, 44,
42, 41, 40, 40, 39, 39, 38, 38,
37, 37, 37, 36, 36, 36, 35, 35,
35, 35, 34, 34, 34, 34, 33, 33,
33, 33, 32, 32, 32, 32, 32, 31,
31, 31, 31, 31, 30, 30, 30, 30,
30,
};
static const u16 count_lut[] = {
0, 1, 2, 3, 4, 5, 6, 7,
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/i2c.h`, `linux/mutex.h`.
- Detected declarations: `struct tsl2550_data`, `function tsl2550_set_operating_mode`, `function tsl2550_set_power_state`, `function tsl2550_get_adc_value`, `function tsl2550_calculate_lux`, `function tsl2550_show_power_state`, `function tsl2550_store_power_state`, `function tsl2550_show_operating_mode`, `function tsl2550_store_operating_mode`, `function __tsl2550_show_lux`.
- Atlas domain: Driver Families / drivers/misc.
- 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.