drivers/iio/light/apds9960.c
Source file repositories/reference/linux-study-clean/drivers/iio/light/apds9960.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/light/apds9960.c- Extension
.c- Size
- 29449 bytes
- Lines
- 1190
- 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/acpi.hlinux/module.hlinux/init.hlinux/interrupt.hlinux/delay.hlinux/mutex.hlinux/err.hlinux/irq.hlinux/i2c.hlinux/pm_runtime.hlinux/regmap.hlinux/iio/iio.hlinux/iio/buffer.hlinux/iio/events.hlinux/iio/kfifo_buf.hlinux/iio/sysfs.h
Detected Declarations
struct apds9960_dataenum apds9960_als_channel_idxenum apds9960_gesture_channel_idxfunction apds9960_set_calibbiasfunction apds9960_set_it_timefunction apds9960_set_pxs_gainfunction apds9960_set_als_gainfunction apds9960_set_power_statefunction apds9960_set_power_statefunction apds9960_read_rawfunction apds9960_write_rawfunction apds9960_get_thres_regfunction apds9960_read_eventfunction apds9960_write_eventfunction apds9960_read_event_configfunction apds9960_write_event_configfunction apds9660_fifo_is_emptyfunction apds9960_read_gesture_fifofunction apds9960_interrupt_handlerfunction apds9960_set_powermodefunction apds9960_buffer_postenablefunction apds9960_buffer_predisablefunction apds9960_regfield_initfunction apds9960_chip_initfunction apds9960_probefunction apds9960_removefunction apds9960_runtime_suspendfunction apds9960_runtime_resume
Annotated Snippet
struct apds9960_data {
struct i2c_client *client;
struct iio_dev *indio_dev;
struct mutex lock;
/* regmap fields */
struct regmap *regmap;
struct regmap_field *reg_int_als;
struct regmap_field *reg_int_ges;
struct regmap_field *reg_int_pxs;
struct regmap_field *reg_enable_als;
struct regmap_field *reg_enable_ges;
struct regmap_field *reg_enable_pxs;
/* state */
bool als_int;
bool pxs_int;
int gesture_mode_running;
/* gain values */
int als_gain;
int pxs_gain;
/* integration time value in us */
int als_adc_int_us;
/* gesture buffer */
u8 buffer[4]; /* 4 8-bit channels */
/* calibration value buffer */
int calibbias[5];
};
enum {
APDS9960_CHAN_PROXIMITY,
APDS9960_CHAN_GESTURE_UP,
APDS9960_CHAN_GESTURE_DOWN,
APDS9960_CHAN_GESTURE_LEFT,
APDS9960_CHAN_GESTURE_RIGHT,
};
static const unsigned int apds9960_offset_regs[][2] = {
[APDS9960_CHAN_PROXIMITY] = {APDS9960_REG_POFFSET_UR, APDS9960_REG_POFFSET_DL},
[APDS9960_CHAN_GESTURE_UP] = {APDS9960_REG_GOFFSET_U, 0},
[APDS9960_CHAN_GESTURE_DOWN] = {APDS9960_REG_GOFFSET_D, 0},
[APDS9960_CHAN_GESTURE_LEFT] = {APDS9960_REG_GOFFSET_L, 0},
[APDS9960_CHAN_GESTURE_RIGHT] = {APDS9960_REG_GOFFSET_R, 0},
};
static const struct reg_default apds9960_reg_defaults[] = {
/* Default ALS integration time = 2.48ms */
{ APDS9960_REG_ATIME, 0xff },
};
static const struct regmap_range apds9960_volatile_ranges[] = {
regmap_reg_range(APDS9960_REG_STATUS,
APDS9960_REG_PDATA),
regmap_reg_range(APDS9960_REG_GFLVL,
APDS9960_REG_GSTATUS),
regmap_reg_range(APDS9960_REG_GFIFO_DIR(UP),
APDS9960_REG_GFIFO_DIR(RIGHT)),
regmap_reg_range(APDS9960_REG_IFORCE,
APDS9960_REG_AICLEAR),
};
static const struct regmap_access_table apds9960_volatile_table = {
.yes_ranges = apds9960_volatile_ranges,
.n_yes_ranges = ARRAY_SIZE(apds9960_volatile_ranges),
};
static const struct regmap_range apds9960_precious_ranges[] = {
regmap_reg_range(APDS9960_REG_RAM_START, APDS9960_REG_RAM_END),
};
static const struct regmap_access_table apds9960_precious_table = {
.yes_ranges = apds9960_precious_ranges,
.n_yes_ranges = ARRAY_SIZE(apds9960_precious_ranges),
};
static const struct regmap_range apds9960_readable_ranges[] = {
regmap_reg_range(APDS9960_REG_ENABLE,
APDS9960_REG_GSTATUS),
regmap_reg_range(APDS9960_REG_GFIFO_DIR(UP),
APDS9960_REG_GFIFO_DIR(RIGHT)),
};
static const struct regmap_access_table apds9960_readable_table = {
.yes_ranges = apds9960_readable_ranges,
.n_yes_ranges = ARRAY_SIZE(apds9960_readable_ranges),
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/module.h`, `linux/init.h`, `linux/interrupt.h`, `linux/delay.h`, `linux/mutex.h`, `linux/err.h`, `linux/irq.h`.
- Detected declarations: `struct apds9960_data`, `enum apds9960_als_channel_idx`, `enum apds9960_gesture_channel_idx`, `function apds9960_set_calibbias`, `function apds9960_set_it_time`, `function apds9960_set_pxs_gain`, `function apds9960_set_als_gain`, `function apds9960_set_power_state`, `function apds9960_set_power_state`, `function apds9960_read_raw`.
- 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.