drivers/iio/light/veml6046x00.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/veml6046x00.c
Extension
.c
Size
27362 bytes
Lines
1031
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 veml6046x00_rf {
	struct regmap_field *int_en;
	struct regmap_field *mode;
	struct regmap_field *trig;
	struct regmap_field *it;
	struct regmap_field *pers;
};

/**
 * struct veml6046x00_data - Private data of driver.
 * @regmap:	Regmap definition of sensor.
 * @trig:	Industrial-IO trigger.
 * @rf:		Regmap field of configuration.
 */
struct veml6046x00_data {
	struct regmap *regmap;
	struct iio_trigger *trig;
	struct veml6046x00_rf rf;
};

/**
 * DOC: Valid integration times (IT)
 *
 * static const int veml6046x00_it contains the array with valid IT.
 *
 * Register value to be read or written in regmap_field it on veml6046x00 is
 * identical with array index.
 * This means there is no separate translation table between valid integration
 * times and register values needed. The index of the array is identical with
 * the register value.
 *
 * The array is in the form as expected by the callback of the sysfs attribute
 * integration_time_available (IIO_CHAN_INFO_INT_TIME). So there is no
 * additional conversion needed.
 */
static const int veml6046x00_it[][2] = {
	{ 0, 3125 },
	{ 0, 6250 },
	{ 0, 12500 },
	{ 0, 25000 },
	{ 0, 50000 },
	{ 0, 100000 },
	{ 0, 200000 },
	{ 0, 400000 },
};

/**
 * DOC: Handling of gain and photodiode size (PD)
 *
 * Gains here in the driver are not exactly the same as in the datasheet of the
 * sensor. The gain in the driver is a combination of the gain of the sensor
 * with the photodiode size (PD).
 * The following combinations are possible:
 *   gain(driver) = gain(sensor) * PD
 *           0.25 = x0.5  * 1/2
 *           0.33 = x0.66 * 1/2
 *           0.5  = x0.5  * 2/2
 *           0.66 = x0.66 * 2/2
 *           1    = x1    * 2/2
 *           2    = x2    * 2/2
 */

/**
 * struct veml6046x00_gain_pd - Translation of gain and photodiode size (PD).
 * @gain_sen:	Gain used in the sensor as described in the datasheet of the
 *		sensor
 * @pd:		Photodiode size in the sensor
 *
 * This is the translation table from the gain used in the driver (and also used
 * by the userspace interface in sysfs) to the gain and PD used in the sensor
 * hardware.
 *
 * There are six gain values visible to the user (0.25 .. 2) which translate to
 * two different gains in the sensor hardware (x0.5 .. x2) and two PD (1/2 and
 * 2/2). Theoretical are there eight combinations, but gain values 0.5 and 1 are
 * doubled and therefore the combination with the larger PD (2/2) is taken as
 * more photodiode cells are supposed to deliver a more precise result.
 */
struct veml6046x00_gain_pd {
	unsigned int gain_sen;
	unsigned int pd;
};

static const struct veml6046x00_gain_pd veml6046x00_gain_pd[] = {
	{ .gain_sen = VEML6046X00_GAIN_0_5, .pd = VEML6046X00_PD_1_2 },
	{ .gain_sen = VEML6046X00_GAIN_0_66, .pd = VEML6046X00_PD_1_2 },
	{ .gain_sen = VEML6046X00_GAIN_0_5, .pd = VEML6046X00_PD_2_2 },
	{ .gain_sen = VEML6046X00_GAIN_0_66, .pd = VEML6046X00_PD_2_2 },
	{ .gain_sen = VEML6046X00_GAIN_1, .pd = VEML6046X00_PD_2_2 },
	{ .gain_sen = VEML6046X00_GAIN_2, .pd = VEML6046X00_PD_2_2 },

Annotation

Implementation Notes