drivers/misc/apds990x.c
Source file repositories/reference/linux-study-clean/drivers/misc/apds990x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/apds990x.c- Extension
.c- Size
- 34016 bytes
- Lines
- 1285
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/i2c.hlinux/interrupt.hlinux/mutex.hlinux/regulator/consumer.hlinux/pm_runtime.hlinux/delay.hlinux/wait.hlinux/slab.hlinux/platform_data/apds990x.h
Detected Declarations
struct reverse_factorsstruct apds990x_chipfunction apds990x_read_bytefunction apds990x_read_wordfunction apds990x_write_bytefunction apds990x_write_wordfunction apds990x_mode_onfunction apds990x_lux_to_thresholdfunction apds990x_set_atimefunction apds990x_refresh_pthresfunction apds990x_refresh_athresfunction apds990x_force_a_refreshfunction apds990x_force_p_refreshfunction apds990x_calc_againfunction apds990x_get_luxfunction apds990x_ack_intfunction apds990x_irqfunction apds990x_configurefunction apds990x_detectfunction apds990x_chip_onfunction apds990x_chip_offfunction apds990x_lux_showfunction apds990x_lux_range_showfunction apds990x_lux_calib_format_showfunction apds990x_lux_calib_showfunction apds990x_lux_calib_storefunction apds990x_rate_availfunction apds990x_rate_showfunction apds990x_set_aratefunction apds990x_rate_storefunction apds990x_prox_showfunction apds990x_prox_range_showfunction apds990x_prox_enable_showfunction apds990x_prox_enable_storefunction apds990x_prox_reporting_mode_showfunction apds990x_prox_reporting_mode_storefunction apds990x_prox_reporting_avail_showfunction apds990x_lux_thresh_above_showfunction apds990x_lux_thresh_below_showfunction apds990x_set_lux_threshfunction apds990x_lux_thresh_above_storefunction apds990x_lux_thresh_below_storefunction apds990x_prox_threshold_showfunction apds990x_prox_threshold_storefunction apds990x_power_state_showfunction apds990x_power_state_storefunction apds990x_chip_id_showfunction apds990x_probe
Annotated Snippet
struct reverse_factors {
u32 afactor;
int cf1;
int irf1;
int cf2;
int irf2;
};
struct apds990x_chip {
struct apds990x_platform_data *pdata;
struct i2c_client *client;
struct mutex mutex; /* avoid parallel access */
struct regulator_bulk_data regs[2];
wait_queue_head_t wait;
int prox_en;
bool prox_continuous_mode;
bool lux_wait_fresh_res;
/* Chip parameters */
struct apds990x_chip_factors cf;
struct reverse_factors rcf;
u16 atime; /* als integration time */
u16 arate; /* als reporting rate */
u16 a_max_result; /* Max possible ADC value with current atime */
u8 again_meas; /* Gain used in last measurement */
u8 again_next; /* Next calculated gain */
u8 pgain;
u8 pdiode;
u8 pdrive;
u8 lux_persistence;
u8 prox_persistence;
u32 lux_raw;
u32 lux;
u16 lux_clear;
u16 lux_ir;
u16 lux_calib;
u32 lux_thres_hi;
u32 lux_thres_lo;
u32 prox_thres;
u16 prox_data;
u16 prox_calib;
char chipname[10];
u8 revision;
};
#define APDS_CALIB_SCALER 8192
#define APDS_LUX_NEUTRAL_CALIB_VALUE (1 * APDS_CALIB_SCALER)
#define APDS_PROX_NEUTRAL_CALIB_VALUE (1 * APDS_CALIB_SCALER)
#define APDS_PROX_DEF_THRES 600
#define APDS_PROX_HYSTERESIS 50
#define APDS_LUX_DEF_THRES_HI 101
#define APDS_LUX_DEF_THRES_LO 100
#define APDS_DEFAULT_PROX_PERS 1
#define APDS_TIMEOUT 2000
#define APDS_STARTUP_DELAY 25000 /* us */
#define APDS_RANGE 65535
#define APDS_PROX_RANGE 1023
#define APDS_LUX_GAIN_LO_LIMIT 100
#define APDS_LUX_GAIN_LO_LIMIT_STRICT 25
#define TIMESTEP 87 /* 2.7ms is about 87 / 32 */
#define TIME_STEP_SCALER 32
#define APDS_LUX_AVERAGING_TIME 50 /* tolerates 50/60Hz ripple */
#define APDS_LUX_DEFAULT_RATE 200
static const u8 again[] = {1, 8, 16, 120}; /* ALS gain steps */
/* Following two tables must match i.e 10Hz rate means 1 as persistence value */
static const u16 arates_hz[] = {10, 5, 2, 1};
static const u8 apersis[] = {1, 2, 4, 5};
/* Regulators */
static const char reg_vcc[] = "Vdd";
static const char reg_vled[] = "Vled";
static int apds990x_read_byte(struct apds990x_chip *chip, u8 reg, u8 *data)
{
struct i2c_client *client = chip->client;
s32 ret;
reg &= ~APDS990x_CMD_TYPE_MASK;
reg |= APDS990x_CMD | APDS990x_CMD_TYPE_RB;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/mutex.h`, `linux/regulator/consumer.h`, `linux/pm_runtime.h`, `linux/delay.h`.
- Detected declarations: `struct reverse_factors`, `struct apds990x_chip`, `function apds990x_read_byte`, `function apds990x_read_word`, `function apds990x_write_byte`, `function apds990x_write_word`, `function apds990x_mode_on`, `function apds990x_lux_to_threshold`, `function apds990x_set_atime`, `function apds990x_refresh_pthres`.
- Atlas domain: Driver Families / drivers/misc.
- 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.