drivers/iio/light/si1133.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/si1133.c
Extension
.c
Size
25383 bytes
Lines
1076
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 si1133_data {
	struct regmap *regmap;
	struct i2c_client *client;

	/* Lock protecting one command at a time can be processed */
	struct mutex mutex;

	int rsp_seq;
	u8 scan_mask;
	u8 adc_sens[6];
	u8 adc_config[6];

	struct completion completion;
};

struct si1133_coeff {
	s16 info;
	u16 mag;
};

struct si1133_lux_coeff {
	struct si1133_coeff coeff_high[4];
	struct si1133_coeff coeff_low[9];
};

static const struct si1133_lux_coeff lux_coeff = {
	{
		{  0,   209},
		{ 1665,  93},
		{ 2064,  65},
		{-2671, 234}
	},
	{
		{    0,     0},
		{ 1921, 29053},
		{-1022, 36363},
		{ 2320, 20789},
		{ -367, 57909},
		{-1774, 38240},
		{ -608, 46775},
		{-1503, 51831},
		{-1886, 58928}
	}
};

static int si1133_calculate_polynomial_inner(s32 input, u8 fraction, u16 mag,
					     s8 shift)
{
	return ((input << fraction) / mag) << shift;
}

static int si1133_calculate_output(s32 x, s32 y, u8 x_order, u8 y_order,
				   u8 input_fraction, s8 sign,
				   const struct si1133_coeff *coeffs)
{
	s8 shift;
	int x1 = 1;
	int x2 = 1;
	int y1 = 1;
	int y2 = 1;

	shift = ((u16)coeffs->info & 0xFF00) >> 8;
	shift ^= 0xFF;
	shift += 1;
	shift = -shift;

	if (x_order > 0) {
		x1 = si1133_calculate_polynomial_inner(x, input_fraction,
						       coeffs->mag, shift);
		if (x_order > 1)
			x2 = x1;
	}

	if (y_order > 0) {
		y1 = si1133_calculate_polynomial_inner(y, input_fraction,
						       coeffs->mag, shift);
		if (y_order > 1)
			y2 = y1;
	}

	return sign * x1 * x2 * y1 * y2;
}

/*
 * The algorithm is from:
 * https://siliconlabs.github.io/Gecko_SDK_Doc/efm32zg/html/si1133_8c_source.html#l00716
 */
static int si1133_calc_polynomial(s32 x, s32 y, u8 input_fraction, u8 num_coeff,
				  const struct si1133_coeff *coeffs)
{

Annotation

Implementation Notes