drivers/iio/light/ltr501.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/ltr501.c
Extension
.c
Size
41119 bytes
Lines
1638
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 ltr501_samp_table {
	int freq_val;  /* repetition frequency in micro HZ*/
	int time_val; /* repetition rate in micro seconds */
};

#define LTR501_RESERVED_GAIN -1

enum {
	ltr501 = 0,
	ltr559,
	ltr301,
	ltr303,
};

struct ltr501_gain {
	int scale;
	int uscale;
};

static const struct ltr501_gain ltr501_als_gain_tbl[] = {
	{1, 0},
	{0, 5000},
};

static const struct ltr501_gain ltr559_als_gain_tbl[] = {
	{1, 0},
	{0, 500000},
	{0, 250000},
	{0, 125000},
	{LTR501_RESERVED_GAIN, LTR501_RESERVED_GAIN},
	{LTR501_RESERVED_GAIN, LTR501_RESERVED_GAIN},
	{0, 20000},
	{0, 10000},
};

static const struct ltr501_gain ltr501_ps_gain_tbl[] = {
	{1, 0},
	{0, 250000},
	{0, 125000},
	{0, 62500},
};

static const struct ltr501_gain ltr559_ps_gain_tbl[] = {
	{0, 62500}, /* x16 gain */
	{0, 31250}, /* x32 gain */
	{0, 15625}, /* bits X1 are for x64 gain */
	{0, 15624},
};

struct ltr501_chip_info {
	u8 partid;
	const struct ltr501_gain *als_gain;
	int als_gain_tbl_size;
	const struct ltr501_gain *ps_gain;
	int ps_gain_tbl_size;
	u8 als_mode_active;
	u8 als_gain_mask;
	u8 als_gain_shift;
	struct iio_chan_spec const *channels;
	const int no_channels;
	const struct iio_info *info;
	const struct iio_info *info_no_irq;
};

struct ltr501_data {
	struct i2c_client *client;
	struct mutex lock_als, lock_ps;
	const struct ltr501_chip_info *chip_info;
	u8 als_contr, ps_contr;
	int als_period, ps_period; /* period in micro seconds */
	struct regmap *regmap;
	struct regmap_field *reg_it;
	struct regmap_field *reg_als_intr;
	struct regmap_field *reg_ps_intr;
	struct regmap_field *reg_als_rate;
	struct regmap_field *reg_ps_rate;
	struct regmap_field *reg_als_prst;
	struct regmap_field *reg_ps_prst;
	uint32_t near_level;
};

static const struct ltr501_samp_table ltr501_als_samp_table[] = {
			{20000000, 50000}, {10000000, 100000},
			{5000000, 200000}, {2000000, 500000},
			{1000000, 1000000}, {500000, 2000000},
			{500000, 2000000}, {500000, 2000000}
};

static const struct ltr501_samp_table ltr501_ps_samp_table[] = {
			{20000000, 50000}, {14285714, 70000},

Annotation

Implementation Notes