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.

Dependency Surface

Detected Declarations

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

Implementation Notes