drivers/iio/proximity/vcnl3020.c
Source file repositories/reference/linux-study-clean/drivers/iio/proximity/vcnl3020.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/proximity/vcnl3020.c- Extension
.c- Size
- 15809 bytes
- Lines
- 672
- 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/i2c.hlinux/err.hlinux/delay.hlinux/regmap.hlinux/interrupt.hlinux/iio/iio.hlinux/iio/events.h
Detected Declarations
struct vcnl3020_datastruct vcnl3020_propertyfunction microamp_to_regfunction vcnl3020_get_and_apply_propertyfunction vcnl3020_initfunction vcnl3020_is_in_periodic_modefunction vcnl3020_measure_proximityfunction vcnl3020_read_proxy_samp_freqfunction vcnl3020_write_proxy_samp_freqfunction vcnl3020_is_thr_enabledfunction vcnl3020_read_eventfunction vcnl3020_write_eventfunction vcnl3020_enable_periodicfunction vcnl3020_disable_periodicfunction vcnl3020_config_thresholdfunction vcnl3020_write_event_configfunction vcnl3020_read_event_configfunction vcnl3020_read_rawfunction vcnl3020_write_rawfunction vcnl3020_read_availfunction vcnl3020_handle_irq_threadfunction vcnl3020_probe
Annotated Snippet
struct vcnl3020_data {
struct regmap *regmap;
struct device *dev;
u8 rev;
struct mutex lock;
__be16 buf;
};
/**
* struct vcnl3020_property - vcnl3020 property.
* @name: property name.
* @reg: i2c register offset.
* @conversion_func: conversion function.
*/
struct vcnl3020_property {
const char *name;
u32 reg;
u32 (*conversion_func)(u32 *val);
};
static u32 microamp_to_reg(u32 *val)
{
/*
* An example of conversion from uA to reg val:
* 200000 uA == 200 mA == 20
*/
return *val /= 10000;
};
static const struct vcnl3020_property vcnl3020_led_current_property = {
.name = "vishay,led-current-microamp",
.reg = VCNL_LED_CURRENT,
.conversion_func = microamp_to_reg,
};
static int vcnl3020_get_and_apply_property(struct vcnl3020_data *data,
const struct vcnl3020_property *prop)
{
int rc;
u32 val;
rc = device_property_read_u32(data->dev, prop->name, &val);
if (rc)
return 0;
if (prop->conversion_func)
prop->conversion_func(&val);
rc = regmap_write(data->regmap, prop->reg, val);
if (rc) {
dev_err(data->dev, "Error (%d) setting property (%s)\n",
rc, prop->name);
}
return rc;
}
static int vcnl3020_init(struct vcnl3020_data *data)
{
int rc;
unsigned int reg;
rc = regmap_read(data->regmap, VCNL_PROD_REV, ®);
if (rc) {
dev_err(data->dev,
"Error (%d) reading product revision\n", rc);
return rc;
}
if (reg != VCNL3020_PROD_ID) {
dev_err(data->dev,
"Product id (%x) did not match vcnl3020 (%x)\n", reg,
VCNL3020_PROD_ID);
return -ENODEV;
}
data->rev = reg;
mutex_init(&data->lock);
return vcnl3020_get_and_apply_property(data,
&vcnl3020_led_current_property);
};
static bool vcnl3020_is_in_periodic_mode(struct vcnl3020_data *data)
{
int rc;
unsigned int cmd;
rc = regmap_read(data->regmap, VCNL_COMMAND, &cmd);
if (rc) {
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/err.h`, `linux/delay.h`, `linux/regmap.h`, `linux/interrupt.h`, `linux/iio/iio.h`, `linux/iio/events.h`.
- Detected declarations: `struct vcnl3020_data`, `struct vcnl3020_property`, `function microamp_to_reg`, `function vcnl3020_get_and_apply_property`, `function vcnl3020_init`, `function vcnl3020_is_in_periodic_mode`, `function vcnl3020_measure_proximity`, `function vcnl3020_read_proxy_samp_freq`, `function vcnl3020_write_proxy_samp_freq`, `function vcnl3020_is_thr_enabled`.
- 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.