drivers/iio/light/tsl2591.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/tsl2591.c
Extension
.c
Size
32890 bytes
Lines
1222
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 tsl2591_als_settings {
	u16 als_lower_thresh;
	u16 als_upper_thresh;
	u8 als_int_time;
	u8 als_persist;
	u8 als_gain;
};

struct tsl2591_chip {
	struct tsl2591_als_settings als_settings;
	struct i2c_client *client;
	/*
	 * Keep als_settings in sync with hardware state
	 * and ensure multiple readers are serialized.
	 */
	struct mutex als_mutex;
	bool events_enabled;
};

/*
 * Period table is ALS persist cycle x integration time setting
 * Integration times: 100ms, 200ms, 300ms, 400ms, 500ms, 600ms
 * ALS cycles: 1, 2, 3, 5, 10, 20, 25, 30, 35, 40, 45, 50, 55, 60
 */
static const char * const tsl2591_als_period_list[] = {
	"0.1 0.2 0.3 0.5 1.0 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0",
	"0.2 0.4 0.6 1.0 2.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0",
	"0.3 0.6 0.9 1.5 3.0 6.0 7.5 9.0 10.5 12.0 13.5 15.0 16.5 18.0",
	"0.4 0.8 1.2 2.0 4.0 8.0 10.0 12.0 14.0 16.0 18.0 20.0 22.0 24.0",
	"0.5 1.0 1.5 2.5 5.0 10.0 12.5 15.0 17.5 20.0 22.5 25.0 27.5 30.0",
	"0.6 1.2 1.8 3.0 6.0 12.0 15.0 18.0 21.0 24.0 27.0 30.0 33.0 36.0",
};

static const int tsl2591_int_time_available[] = {
	1, 2, 3, 4, 5, 6,
};

static const int tsl2591_calibscale_available[] = {
	1, 25, 428, 9876,
};

static int tsl2591_set_als_lower_threshold(struct tsl2591_chip *chip,
					   u16 als_lower_threshold);
static int tsl2591_set_als_upper_threshold(struct tsl2591_chip *chip,
					   u16 als_upper_threshold);

static int tsl2591_gain_to_multiplier(const u8 als_gain)
{
	switch (als_gain) {
	case TSL2591_CTRL_ALS_LOW_GAIN:
		return TSL2591_CTRL_ALS_LOW_GAIN_MULTIPLIER;
	case TSL2591_CTRL_ALS_MED_GAIN:
		return TSL2591_CTRL_ALS_MED_GAIN_MULTIPLIER;
	case TSL2591_CTRL_ALS_HIGH_GAIN:
		return TSL2591_CTRL_ALS_HIGH_GAIN_MULTIPLIER;
	case TSL2591_CTRL_ALS_MAX_GAIN:
		return TSL2591_CTRL_ALS_MAX_GAIN_MULTIPLIER;
	default:
		return -EINVAL;
	}
}

static int tsl2591_multiplier_to_gain(const u32 multiplier)
{
	switch (multiplier) {
	case TSL2591_CTRL_ALS_LOW_GAIN_MULTIPLIER:
		return TSL2591_CTRL_ALS_LOW_GAIN;
	case TSL2591_CTRL_ALS_MED_GAIN_MULTIPLIER:
		return TSL2591_CTRL_ALS_MED_GAIN;
	case TSL2591_CTRL_ALS_HIGH_GAIN_MULTIPLIER:
		return TSL2591_CTRL_ALS_HIGH_GAIN;
	case TSL2591_CTRL_ALS_MAX_GAIN_MULTIPLIER:
		return TSL2591_CTRL_ALS_MAX_GAIN;
	default:
		return -EINVAL;
	}
}

static int tsl2591_persist_cycle_to_lit(const u8 als_persist)
{
	switch (als_persist) {
	case TSL2591_PRST_ALS_INT_CYCLE_ANY:
		return 1;
	case TSL2591_PRST_ALS_INT_CYCLE_2:
		return 2;
	case TSL2591_PRST_ALS_INT_CYCLE_3:
		return 3;
	case TSL2591_PRST_ALS_INT_CYCLE_5:
		return 5;
	case TSL2591_PRST_ALS_INT_CYCLE_10:

Annotation

Implementation Notes