drivers/iio/light/ltr390.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/ltr390.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/ltr390.c- Extension
.c- Size
- 23411 bytes
- Lines
- 917
- 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.
- 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/device.hlinux/i2c.hlinux/irq.hlinux/interrupt.hlinux/math.hlinux/module.hlinux/mutex.hlinux/pm_runtime.hlinux/regmap.hlinux/iio/iio.hlinux/iio/events.hlinux/unaligned.h
Detected Declarations
struct ltr390_dataenum ltr390_modeenum ltr390_meas_ratefunction ltr390_register_readfunction ltr390_set_modefunction ltr390_counts_per_uvifunction ltr390_get_samp_freq_or_periodfunction ltr390_do_read_rawfunction ltr390_read_rawfunction ltr390_set_gainfunction ltr390_set_int_timefunction ltr390_set_samp_freqfunction ltr390_read_availfunction ltr390_write_rawfunction ltr390_read_intr_prstfunction ltr390_write_intr_prstfunction ltr390_read_thresholdfunction ltr390_write_thresholdfunction ltr390_read_event_valuefunction ltr390_write_event_valuefunction ltr390_read_event_configfunction ltr390_do_event_configfunction ltr390_write_event_configfunction ltr390_debugfs_reg_accessfunction ltr390_interrupt_handlerfunction ltr390_powerdownfunction ltr390_pm_initfunction ltr390_probefunction ltr390_suspendfunction ltr390_resumefunction ltr390_runtime_suspendfunction ltr390_runtime_resume
Annotated Snippet
struct ltr390_data {
struct regmap *regmap;
struct i2c_client *client;
/* Protects device from simultaneous reads */
struct mutex lock;
enum ltr390_mode mode;
int gain;
int int_time_us;
bool irq_enabled;
};
static const struct regmap_range ltr390_readable_reg_ranges[] = {
regmap_reg_range(LTR390_MAIN_CTRL, LTR390_MAIN_CTRL),
regmap_reg_range(LTR390_ALS_UVS_MEAS_RATE, LTR390_MAIN_STATUS),
regmap_reg_range(LTR390_ALS_DATA_BYTE(0), LTR390_UVS_DATA_BYTE(2)),
regmap_reg_range(LTR390_INT_CFG, LTR390_INT_PST),
regmap_reg_range(LTR390_THRESH_UP_BYTE(0), LTR390_THRESH_LOW_BYTE(2)),
};
static const struct regmap_access_table ltr390_readable_reg_table = {
.yes_ranges = ltr390_readable_reg_ranges,
.n_yes_ranges = ARRAY_SIZE(ltr390_readable_reg_ranges),
};
static const struct regmap_range ltr390_writeable_reg_ranges[] = {
regmap_reg_range(LTR390_MAIN_CTRL, LTR390_MAIN_CTRL),
regmap_reg_range(LTR390_ALS_UVS_MEAS_RATE, LTR390_ALS_UVS_GAIN),
regmap_reg_range(LTR390_INT_CFG, LTR390_INT_PST),
regmap_reg_range(LTR390_THRESH_UP_BYTE(0), LTR390_THRESH_LOW_BYTE(2)),
};
static const struct regmap_access_table ltr390_writeable_reg_table = {
.yes_ranges = ltr390_writeable_reg_ranges,
.n_yes_ranges = ARRAY_SIZE(ltr390_writeable_reg_ranges),
};
static const struct regmap_config ltr390_regmap_config = {
.name = "ltr390",
.reg_bits = 8,
.reg_stride = 1,
.val_bits = 8,
.max_register = LTR390_THRESH_LOW_BYTE(2),
.rd_table = <r390_readable_reg_table,
.wr_table = <r390_writeable_reg_table,
};
/* Sampling frequency is in mili Hz and mili Seconds */
static const int ltr390_samp_freq_table[][2] = {
[0] = { 40000, 25 },
[1] = { 20000, 50 },
[2] = { 10000, 100 },
[3] = { 5000, 200 },
[4] = { 2000, 500 },
[5] = { 1000, 1000 },
[6] = { 500, 2000 },
[7] = { 500, 2000 },
};
static int ltr390_register_read(struct ltr390_data *data, u8 register_address)
{
struct device *dev = &data->client->dev;
int ret;
u8 receive_buffer[3];
ret = regmap_bulk_read(data->regmap, register_address, receive_buffer,
sizeof(receive_buffer));
if (ret) {
dev_err(dev, "failed to read measurement data");
return ret;
}
return get_unaligned_le24(receive_buffer);
}
static int ltr390_set_mode(struct ltr390_data *data, enum ltr390_mode mode)
{
int ret;
if (data->mode == mode)
return 0;
switch (mode) {
case LTR390_SET_ALS_MODE:
ret = regmap_clear_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_UVS_MODE);
break;
case LTR390_SET_UVS_MODE:
ret = regmap_set_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_UVS_MODE);
break;
}
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/device.h`, `linux/i2c.h`, `linux/irq.h`, `linux/interrupt.h`, `linux/math.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct ltr390_data`, `enum ltr390_mode`, `enum ltr390_meas_rate`, `function ltr390_register_read`, `function ltr390_set_mode`, `function ltr390_counts_per_uvi`, `function ltr390_get_samp_freq_or_period`, `function ltr390_do_read_raw`, `function ltr390_read_raw`, `function ltr390_set_gain`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: source implementation candidate.
- 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.