drivers/iio/light/apds9306.c

Source file repositories/reference/linux-study-clean/drivers/iio/light/apds9306.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/apds9306.c
Extension
.c
Size
36575 bytes
Lines
1358
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct part_id_gts_multiplier {
	int part_id;
	int max_scale_int;
	int max_scale_nano;
};

/*
 * As per the datasheet, at HW Gain = 3x, Integration time 100mS (32x),
 * typical 2000 ADC counts are observed for 49.8 uW per sq cm (340.134 lux)
 * for apds9306 and 43 uW per sq cm (293.69 lux) for apds9306-065.
 * Assuming lux per count is linear across all integration time ranges.
 *
 * Lux = (raw + offset) * scale; offset can be any value by userspace.
 * HG = Hardware Gain; ITG = Gain by changing integration time.
 * Scale table by IIO GTS Helpers = (1 / HG) * (1 / ITG) * Multiplier.
 *
 * The Lux values provided in the datasheet are at ITG=32x and HG=3x,
 * at typical 2000 count for both variants of the device.
 *
 * Lux per ADC count at 3x and 32x for apds9306 = 340.134 / 2000
 * Lux per ADC count at 3x and 32x for apds9306-065 = 293.69 / 2000
 *
 * The Multiplier for the scale table provided to userspace:
 * IIO GTS scale Multiplier for apds9306 = (340.134 / 2000) * 32 * 3 = 16.326432
 * and for apds9306-065 = (293.69 / 2000) * 32 * 3 = 14.09712
 */
static const struct part_id_gts_multiplier apds9306_gts_mul[] = {
	{
		.part_id = 0xB1,
		.max_scale_int = 16,
		.max_scale_nano = 326432000,
	}, {
		.part_id = 0xB3,
		.max_scale_int = 14,
		.max_scale_nano = 97120000,
	},
};

static const int apds9306_repeat_rate_freq[APDS9306_NUM_REPEAT_RATES][2] = {
	{ 40, 0 },
	{ 20, 0 },
	{ 10, 0 },
	{ 5,  0 },
	{ 2,  0 },
	{ 1,  0 },
	{ 0,  500000 },
};

static const int apds9306_repeat_rate_period[APDS9306_NUM_REPEAT_RATES] = {
	25000, 50000, 100000, 200000, 500000, 1000000, 2000000,
};

/**
 * struct apds9306_regfields - apds9306 regmap fields definitions
 *
 * @sw_reset: Software reset regfield
 * @en: Enable regfield
 * @intg_time: Resolution regfield
 * @repeat_rate: Measurement Rate regfield
 * @gain: Hardware gain regfield
 * @int_src: Interrupt channel regfield
 * @int_thresh_var_en: Interrupt variance threshold regfield
 * @int_en: Interrupt enable regfield
 * @int_persist_val: Interrupt persistence regfield
 * @int_thresh_var_val: Interrupt threshold variance value regfield
 */
struct apds9306_regfields {
	struct regmap_field *sw_reset;
	struct regmap_field *en;
	struct regmap_field *intg_time;
	struct regmap_field *repeat_rate;
	struct regmap_field *gain;
	struct regmap_field *int_src;
	struct regmap_field *int_thresh_var_en;
	struct regmap_field *int_en;
	struct regmap_field *int_persist_val;
	struct regmap_field *int_thresh_var_val;
};

/**
 * struct apds9306_data - apds9306 private data and registers definitions
 *
 * @dev: Pointer to the device structure
 * @gts: IIO Gain Time Scale structure
 * @mutex: Lock for protecting adc reads, device settings changes where
 *         some calculations are required before or after setting or
 *         getting the raw settings values from regmap writes or reads
 *         respectively.
 * @regmap: Regmap structure pointer
 * @rf: Regmap register fields structure

Annotation

Implementation Notes