drivers/iio/light/veml6030.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/veml6030.c
Extension
.c
Size
32916 bytes
Lines
1243
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 veml6030_rf {
	struct regmap_field *it;
	struct regmap_field *gain;
};

struct veml603x_chip {
	const char *name;
	const struct iio_chan_spec *channels;
	const int num_channels;
	const struct reg_field gain_rf;
	const struct reg_field it_rf;
	const int max_scale;
	int (*hw_init)(struct iio_dev *indio_dev, struct device *dev);
	int (*set_info)(struct iio_dev *indio_dev);
};

/*
 * The resolution depends on both gain and integration time. The
 * cur_resolution stores one of the resolution mentioned in the
 * table during startup and gets updated whenever integration time
 * or gain is changed.
 *
 * Table 'resolution and maximum detection range' in the appnotes
 * is visualized as a 2D array. The cur_gain stores index of gain
 * in this table (0-3 for VEML6030, 0-5 for VEML6035) while the
 * cur_integration_time holds index of integration time (0-5).
 */
struct veml6030_data {
	struct i2c_client *client;
	struct regmap *regmap;
	struct veml6030_rf rf;
	const struct veml603x_chip *chip;
	struct iio_gts gts;

};

#define VEML6030_SEL_IT_25MS  0x0C
#define VEML6030_SEL_IT_50MS  0x08
#define VEML6030_SEL_IT_100MS 0x00
#define VEML6030_SEL_IT_200MS 0x01
#define VEML6030_SEL_IT_400MS 0x02
#define VEML6030_SEL_IT_800MS 0x03
static const struct iio_itime_sel_mul veml6030_it_sel[] = {
	GAIN_SCALE_ITIME_US(25000, VEML6030_SEL_IT_25MS, 1),
	GAIN_SCALE_ITIME_US(50000, VEML6030_SEL_IT_50MS, 2),
	GAIN_SCALE_ITIME_US(100000, VEML6030_SEL_IT_100MS, 4),
	GAIN_SCALE_ITIME_US(200000, VEML6030_SEL_IT_200MS, 8),
	GAIN_SCALE_ITIME_US(400000, VEML6030_SEL_IT_400MS, 16),
	GAIN_SCALE_ITIME_US(800000, VEML6030_SEL_IT_800MS, 32),
};

/* Gains are multiplied by 8 to work with integers. The values in the
 * iio-gts tables don't need corrections because the maximum value of
 * the scale refers to GAIN = x1, and the rest of the values are
 * obtained from the resulting linear function.
 */
#define VEML6030_SEL_MILLI_GAIN_X125  2
#define VEML6030_SEL_MILLI_GAIN_X250  3
#define VEML6030_SEL_MILLI_GAIN_X1000 0
#define VEML6030_SEL_MILLI_GAIN_X2000 1
static const struct iio_gain_sel_pair veml6030_gain_sel[] = {
	GAIN_SCALE_GAIN(1, VEML6030_SEL_MILLI_GAIN_X125),
	GAIN_SCALE_GAIN(2, VEML6030_SEL_MILLI_GAIN_X250),
	GAIN_SCALE_GAIN(8, VEML6030_SEL_MILLI_GAIN_X1000),
	GAIN_SCALE_GAIN(16, VEML6030_SEL_MILLI_GAIN_X2000),
};

#define VEML6035_SEL_MILLI_GAIN_X125  4
#define VEML6035_SEL_MILLI_GAIN_X250  5
#define VEML6035_SEL_MILLI_GAIN_X500  7
#define VEML6035_SEL_MILLI_GAIN_X1000 0
#define VEML6035_SEL_MILLI_GAIN_X2000 1
#define VEML6035_SEL_MILLI_GAIN_X4000 3
static const struct iio_gain_sel_pair veml6035_gain_sel[] = {
	GAIN_SCALE_GAIN(1, VEML6035_SEL_MILLI_GAIN_X125),
	GAIN_SCALE_GAIN(2, VEML6035_SEL_MILLI_GAIN_X250),
	GAIN_SCALE_GAIN(4, VEML6035_SEL_MILLI_GAIN_X500),
	GAIN_SCALE_GAIN(8, VEML6035_SEL_MILLI_GAIN_X1000),
	GAIN_SCALE_GAIN(16, VEML6035_SEL_MILLI_GAIN_X2000),
	GAIN_SCALE_GAIN(32, VEML6035_SEL_MILLI_GAIN_X4000),
};

/*
 * Persistence = 1/2/4/8 x integration time
 * Minimum time for which light readings must stay above configured
 * threshold to assert the interrupt.
 */
static const char * const period_values[] = {
		"0.1 0.2 0.4 0.8",
		"0.2 0.4 0.8 1.6",

Annotation

Implementation Notes