drivers/iio/light/vl6180.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/vl6180.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/vl6180.c- Extension
.c- Size
- 18553 bytes
- Lines
- 773
- 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/mutex.hlinux/err.hlinux/delay.hlinux/util_macros.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/buffer.hlinux/iio/trigger.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.h
Detected Declarations
struct vl6180_datastruct vl6180_chan_regsfunction vl6180_readfunction vl6180_read_bytefunction vl6180_read_wordfunction vl6180_write_bytefunction vl6180_write_wordfunction vl6180_measurefunction vl6180_read_rawfunction vl6180_holdfunction vl6180_set_als_gainfunction vl6180_set_itfunction vl6180_meas_reg_val_from_mhzfunction vl6180_write_rawfunction vl6180_threaded_irqfunction vl6180_trigger_handlerfunction iio_for_each_active_channelfunction vl6180_buffer_postenablefunction vl6180_buffer_postdisablefunction vl6180_initfunction vl6180_probe
Annotated Snippet
struct vl6180_data {
struct i2c_client *client;
struct mutex lock;
struct completion completion;
struct iio_trigger *trig;
unsigned int als_gain_milli;
unsigned int als_it_ms;
unsigned int als_meas_rate;
unsigned int range_meas_rate;
};
enum { VL6180_ALS, VL6180_RANGE, VL6180_PROX };
/**
* struct vl6180_chan_regs - Registers for accessing channels
* @drdy_mask: Data ready bit in status register
* @start_reg: Conversion start register
* @value_reg: Result value register
* @word: Register word length
*/
struct vl6180_chan_regs {
u8 drdy_mask;
u16 start_reg, value_reg;
bool word;
};
static const struct vl6180_chan_regs vl6180_chan_regs_table[] = {
[VL6180_ALS] = {
.drdy_mask = VL6180_ALS_READY,
.start_reg = VL6180_ALS_START,
.value_reg = VL6180_ALS_VALUE,
.word = true,
},
[VL6180_RANGE] = {
.drdy_mask = VL6180_RANGE_READY,
.start_reg = VL6180_RANGE_START,
.value_reg = VL6180_RANGE_VALUE,
.word = false,
},
[VL6180_PROX] = {
.drdy_mask = VL6180_RANGE_READY,
.start_reg = VL6180_RANGE_START,
.value_reg = VL6180_RANGE_RATE,
.word = true,
},
};
static int vl6180_read(struct i2c_client *client, u16 cmd, void *databuf,
u8 len)
{
__be16 cmdbuf = cpu_to_be16(cmd);
struct i2c_msg msgs[2] = {
{ .addr = client->addr, .len = sizeof(cmdbuf), .buf = (u8 *) &cmdbuf },
{ .addr = client->addr, .len = len, .buf = databuf,
.flags = I2C_M_RD } };
int ret;
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
if (ret < 0)
dev_err(&client->dev, "failed reading register 0x%04x\n", cmd);
return ret;
}
static int vl6180_read_byte(struct i2c_client *client, u16 cmd)
{
u8 data;
int ret;
ret = vl6180_read(client, cmd, &data, sizeof(data));
if (ret < 0)
return ret;
return data;
}
static int vl6180_read_word(struct i2c_client *client, u16 cmd)
{
__be16 data;
int ret;
ret = vl6180_read(client, cmd, &data, sizeof(data));
if (ret < 0)
return ret;
return be16_to_cpu(data);
}
static int vl6180_write_byte(struct i2c_client *client, u16 cmd, u8 val)
{
Annotation
- Immediate include surface: `linux/module.h`, `linux/mod_devicetable.h`, `linux/i2c.h`, `linux/mutex.h`, `linux/err.h`, `linux/delay.h`, `linux/util_macros.h`, `linux/iio/iio.h`.
- Detected declarations: `struct vl6180_data`, `struct vl6180_chan_regs`, `function vl6180_read`, `function vl6180_read_byte`, `function vl6180_read_word`, `function vl6180_write_byte`, `function vl6180_write_word`, `function vl6180_measure`, `function vl6180_read_raw`, `function vl6180_hold`.
- 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.