drivers/iio/proximity/vl53l1x-i2c.c
Source file repositories/reference/linux-study-clean/drivers/iio/proximity/vl53l1x-i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/proximity/vl53l1x-i2c.c- Extension
.c- Size
- 20288 bytes
- Lines
- 757
- 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/array_size.hlinux/bits.hlinux/bitfield.hlinux/completion.hlinux/delay.hlinux/dev_printk.hlinux/err.hlinux/i2c.hlinux/interrupt.hlinux/math.hlinux/mod_devicetable.hlinux/module.hlinux/regmap.hlinux/regulator/consumer.hlinux/reset.hlinux/time.hlinux/types.hasm/byteorder.hlinux/iio/buffer.hlinux/iio/iio.hlinux/iio/trigger.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.h
Detected Declarations
struct vl53l1x_dataenum vl53l1x_distance_modefunction vl53l1x_read_u16function vl53l1x_write_u16function vl53l1x_write_u32function vl53l1x_clear_irqfunction vl53l1x_start_rangingfunction vl53l1x_stop_rangingfunction vl53l1x_chip_initfunction vl53l1x_set_distance_modefunction vl53l1x_set_timing_budgetfunction vl53l1x_set_inter_measurement_msfunction vl53l1x_read_proximityfunction vl53l1x_read_rawfunction vl53l1x_trigger_handlerfunction vl53l1x_irq_handlerfunction vl53l1x_stop_ranging_actionfunction vl53l1x_configure_irqfunction vl53l1x_probe
Annotated Snippet
struct vl53l1x_data {
struct regmap *regmap;
struct completion completion;
struct reset_control *xshut_reset;
enum vl53l1x_distance_mode distance_mode;
u8 gpio_polarity;
int irq;
};
static const struct regmap_range vl53l1x_volatile_ranges[] = {
regmap_reg_range(VL53L1X_REG_GPIO__TIO_HV_STATUS,
VL53L1X_REG_GPIO__TIO_HV_STATUS),
regmap_reg_range(VL53L1X_REG_RESULT__RANGE_STATUS,
VL53L1X_REG_RESULT__RANGE_STATUS),
regmap_reg_range(VL53L1X_REG_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0,
VL53L1X_REG_RESULT__FINAL_CROSSTALK_CORRECTED_RANGE_MM_SD0 + 1),
regmap_reg_range(VL53L1X_REG_RESULT__OSC_CALIBRATE_VAL,
VL53L1X_REG_RESULT__OSC_CALIBRATE_VAL + 1),
regmap_reg_range(VL53L1X_REG_FIRMWARE__SYSTEM_STATUS,
VL53L1X_REG_FIRMWARE__SYSTEM_STATUS),
};
static const struct regmap_access_table vl53l1x_volatile_table = {
.yes_ranges = vl53l1x_volatile_ranges,
.n_yes_ranges = ARRAY_SIZE(vl53l1x_volatile_ranges),
};
static const struct regmap_range vl53l1x_write_only_ranges[] = {
regmap_reg_range(VL53L1X_REG_SOFT_RESET, VL53L1X_REG_SOFT_RESET),
regmap_reg_range(VL53L1X_REG_SYSTEM__INTERRUPT_CLEAR,
VL53L1X_REG_SYSTEM__MODE_START),
};
static const struct regmap_access_table vl53l1x_readable_table = {
.no_ranges = vl53l1x_write_only_ranges,
.n_no_ranges = ARRAY_SIZE(vl53l1x_write_only_ranges),
};
static const struct regmap_config vl53l1x_regmap_config = {
.reg_bits = 16,
.val_bits = 8,
/* MODEL_ID is 16-bit. +1 covers the second byte at 0x0110 */
.max_register = VL53L1X_REG_IDENTIFICATION__MODEL_ID + 1,
.cache_type = REGCACHE_MAPLE,
.volatile_table = &vl53l1x_volatile_table,
.rd_table = &vl53l1x_readable_table,
};
static int vl53l1x_read_u16(struct vl53l1x_data *data, u16 reg, u16 *val)
{
__be16 buf;
int ret;
ret = regmap_bulk_read(data->regmap, reg, &buf, sizeof(buf));
if (ret)
return ret;
*val = be16_to_cpu(buf);
return 0;
}
static int vl53l1x_write_u16(struct vl53l1x_data *data, u16 reg, u16 val)
{
__be16 buf = cpu_to_be16(val);
return regmap_bulk_write(data->regmap, reg, &buf, sizeof(buf));
}
static int vl53l1x_write_u32(struct vl53l1x_data *data, u16 reg, u32 val)
{
__be32 buf = cpu_to_be32(val);
return regmap_bulk_write(data->regmap, reg, &buf, sizeof(buf));
}
static int vl53l1x_clear_irq(struct vl53l1x_data *data)
{
return regmap_write(data->regmap, VL53L1X_REG_SYSTEM__INTERRUPT_CLEAR, 0x01);
}
static int vl53l1x_start_ranging(struct vl53l1x_data *data)
{
int ret;
ret = vl53l1x_clear_irq(data);
if (ret)
return ret;
return regmap_write(data->regmap, VL53L1X_REG_SYSTEM__MODE_START,
VL53L1X_MODE_START_TIMED);
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bits.h`, `linux/bitfield.h`, `linux/completion.h`, `linux/delay.h`, `linux/dev_printk.h`, `linux/err.h`, `linux/i2c.h`.
- Detected declarations: `struct vl53l1x_data`, `enum vl53l1x_distance_mode`, `function vl53l1x_read_u16`, `function vl53l1x_write_u16`, `function vl53l1x_write_u32`, `function vl53l1x_clear_irq`, `function vl53l1x_start_ranging`, `function vl53l1x_stop_ranging`, `function vl53l1x_chip_init`, `function vl53l1x_set_distance_mode`.
- 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.