drivers/iio/light/tsl2563.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/tsl2563.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/tsl2563.c- Extension
.c- Size
- 20566 bytes
- Lines
- 874
- 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/bits.hlinux/delay.hlinux/err.hlinux/i2c.hlinux/interrupt.hlinux/irq.hlinux/math.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/pm.hlinux/property.hlinux/sched.hlinux/slab.hlinux/iio/events.hlinux/iio/iio.hlinux/iio/sysfs.h
Detected Declarations
struct tsl2563_gainlevel_coeffstruct tsl2563_chipstruct tsl2563_lux_coefffunction tsl2563_set_powerfunction tsl2563_get_powerfunction tsl2563_configurefunction tsl2563_poweroff_workfunction tsl2563_detectfunction tsl2563_read_idfunction tsl2563_configure_irqfunction tsl2563_adc_shiftbitsfunction tsl2563_normalize_adcfunction tsl2563_wait_adcfunction tsl2563_adjust_gainlevelfunction tsl2563_get_adcfunction tsl2563_calib_to_sysfsfunction tsl2563_calib_from_sysfsfunction tsl2563_adc_to_luxfunction tsl2563_calib_adcfunction tsl2563_write_rawfunction tsl2563_read_rawfunction tsl2563_read_threshfunction tsl2563_write_threshfunction tsl2563_event_handlerfunction tsl2563_write_interrupt_configfunction tsl2563_read_interrupt_configfunction tsl2563_probefunction tsl2563_removefunction tsl2563_suspendfunction tsl2563_resume
Annotated Snippet
struct tsl2563_gainlevel_coeff {
u8 gaintime;
u16 min;
u16 max;
};
static const struct tsl2563_gainlevel_coeff tsl2563_gainlevel_table[] = {
{
.gaintime = TSL2563_TIMING_400MS | TSL2563_TIMING_GAIN16,
.min = 0,
.max = 65534,
}, {
.gaintime = TSL2563_TIMING_400MS | TSL2563_TIMING_GAIN1,
.min = 2048,
.max = 65534,
}, {
.gaintime = TSL2563_TIMING_100MS | TSL2563_TIMING_GAIN1,
.min = 4095,
.max = 37177,
}, {
.gaintime = TSL2563_TIMING_13MS | TSL2563_TIMING_GAIN1,
.min = 3000,
.max = 65535,
},
};
struct tsl2563_chip {
struct mutex lock;
struct i2c_client *client;
struct delayed_work poweroff_work;
/* Remember state for suspend and resume functions */
bool suspended;
struct tsl2563_gainlevel_coeff const *gainlevel;
u16 low_thres;
u16 high_thres;
u8 intr;
bool int_enabled;
/* Calibration coefficients */
u32 calib0;
u32 calib1;
int cover_comp_gain;
/* Cache current values, to be returned while suspended */
u32 data0;
u32 data1;
};
static int tsl2563_set_power(struct tsl2563_chip *chip, int on)
{
struct i2c_client *client = chip->client;
u8 cmd;
cmd = on ? TSL2563_CMD_POWER_ON : TSL2563_CMD_POWER_OFF;
return i2c_smbus_write_byte_data(client,
TSL2563_CMD | TSL2563_REG_CTRL, cmd);
}
/*
* Return value is 0 for off, 1 for on, or a negative error
* code if reading failed.
*/
static int tsl2563_get_power(struct tsl2563_chip *chip)
{
struct i2c_client *client = chip->client;
int ret;
ret = i2c_smbus_read_byte_data(client, TSL2563_CMD | TSL2563_REG_CTRL);
if (ret < 0)
return ret;
return (ret & TSL2563_CTRL_POWER_MASK) == TSL2563_CMD_POWER_ON;
}
static int tsl2563_configure(struct tsl2563_chip *chip)
{
int ret;
ret = i2c_smbus_write_byte_data(chip->client,
TSL2563_CMD | TSL2563_REG_TIMING,
chip->gainlevel->gaintime);
if (ret)
goto error_ret;
ret = i2c_smbus_write_word_data(chip->client,
TSL2563_CMD | TSL2563_REG_HIGH,
chip->high_thres);
if (ret)
Annotation
- Immediate include surface: `linux/bits.h`, `linux/delay.h`, `linux/err.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/math.h`, `linux/mod_devicetable.h`.
- Detected declarations: `struct tsl2563_gainlevel_coeff`, `struct tsl2563_chip`, `struct tsl2563_lux_coeff`, `function tsl2563_set_power`, `function tsl2563_get_power`, `function tsl2563_configure`, `function tsl2563_poweroff_work`, `function tsl2563_detect`, `function tsl2563_read_id`, `function tsl2563_configure_irq`.
- 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.