drivers/iio/light/ltr501.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/ltr501.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/ltr501.c- Extension
.c- Size
- 41119 bytes
- Lines
- 1638
- 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/module.hlinux/mod_devicetable.hlinux/i2c.hlinux/err.hlinux/delay.hlinux/regmap.hlinux/regulator/consumer.hlinux/iio/iio.hlinux/iio/events.hlinux/iio/sysfs.hlinux/iio/trigger_consumer.hlinux/iio/buffer.hlinux/iio/triggered_buffer.h
Detected Declarations
struct ltr501_samp_tablestruct ltr501_gainstruct ltr501_chip_infostruct ltr501_datafunction ltr501_match_samp_freqfunction ltr501_als_read_samp_freqfunction ltr501_ps_read_samp_freqfunction ltr501_als_write_samp_freqfunction ltr501_ps_write_samp_freqfunction ltr501_als_read_samp_periodfunction ltr501_ps_read_samp_periodfunction ltr501_calculate_luxfunction ltr501_drdyfunction ltr501_set_it_timefunction ltr501_read_it_timefunction ltr501_read_alsfunction ltr501_read_psfunction ltr501_read_intr_prstfunction ltr501_write_intr_prstfunction ltr501_read_near_levelfunction ltr501_read_info_rawfunction ltr501_read_rawfunction ltr501_get_gain_indexfunction __ltr501_write_rawfunction ltr501_write_rawfunction ltr501_read_threshfunction ltr501_write_threshfunction ltr501_read_eventfunction ltr501_write_eventfunction ltr501_read_event_configfunction ltr501_write_event_configfunction ltr501_show_proximity_scale_availfunction ltr501_show_intensity_scale_availfunction ltr501_write_contrfunction ltr501_trigger_handlerfunction ltr501_interrupt_handlerfunction ltr501_initfunction ltr501_is_volatile_regfunction ltr501_powerdownfunction ltr501_probefunction ltr501_removefunction ltr501_suspendfunction ltr501_resume
Annotated Snippet
struct ltr501_samp_table {
int freq_val; /* repetition frequency in micro HZ*/
int time_val; /* repetition rate in micro seconds */
};
#define LTR501_RESERVED_GAIN -1
enum {
ltr501 = 0,
ltr559,
ltr301,
ltr303,
};
struct ltr501_gain {
int scale;
int uscale;
};
static const struct ltr501_gain ltr501_als_gain_tbl[] = {
{1, 0},
{0, 5000},
};
static const struct ltr501_gain ltr559_als_gain_tbl[] = {
{1, 0},
{0, 500000},
{0, 250000},
{0, 125000},
{LTR501_RESERVED_GAIN, LTR501_RESERVED_GAIN},
{LTR501_RESERVED_GAIN, LTR501_RESERVED_GAIN},
{0, 20000},
{0, 10000},
};
static const struct ltr501_gain ltr501_ps_gain_tbl[] = {
{1, 0},
{0, 250000},
{0, 125000},
{0, 62500},
};
static const struct ltr501_gain ltr559_ps_gain_tbl[] = {
{0, 62500}, /* x16 gain */
{0, 31250}, /* x32 gain */
{0, 15625}, /* bits X1 are for x64 gain */
{0, 15624},
};
struct ltr501_chip_info {
u8 partid;
const struct ltr501_gain *als_gain;
int als_gain_tbl_size;
const struct ltr501_gain *ps_gain;
int ps_gain_tbl_size;
u8 als_mode_active;
u8 als_gain_mask;
u8 als_gain_shift;
struct iio_chan_spec const *channels;
const int no_channels;
const struct iio_info *info;
const struct iio_info *info_no_irq;
};
struct ltr501_data {
struct i2c_client *client;
struct mutex lock_als, lock_ps;
const struct ltr501_chip_info *chip_info;
u8 als_contr, ps_contr;
int als_period, ps_period; /* period in micro seconds */
struct regmap *regmap;
struct regmap_field *reg_it;
struct regmap_field *reg_als_intr;
struct regmap_field *reg_ps_intr;
struct regmap_field *reg_als_rate;
struct regmap_field *reg_ps_rate;
struct regmap_field *reg_als_prst;
struct regmap_field *reg_ps_prst;
uint32_t near_level;
};
static const struct ltr501_samp_table ltr501_als_samp_table[] = {
{20000000, 50000}, {10000000, 100000},
{5000000, 200000}, {2000000, 500000},
{1000000, 1000000}, {500000, 2000000},
{500000, 2000000}, {500000, 2000000}
};
static const struct ltr501_samp_table ltr501_ps_samp_table[] = {
{20000000, 50000}, {14285714, 70000},
Annotation
- Immediate include surface: `linux/module.h`, `linux/mod_devicetable.h`, `linux/i2c.h`, `linux/err.h`, `linux/delay.h`, `linux/regmap.h`, `linux/regulator/consumer.h`, `linux/iio/iio.h`.
- Detected declarations: `struct ltr501_samp_table`, `struct ltr501_gain`, `struct ltr501_chip_info`, `struct ltr501_data`, `function ltr501_match_samp_freq`, `function ltr501_als_read_samp_freq`, `function ltr501_ps_read_samp_freq`, `function ltr501_als_write_samp_freq`, `function ltr501_ps_write_samp_freq`, `function ltr501_als_read_samp_period`.
- 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.