drivers/iio/light/vcnl4000.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/vcnl4000.c
Extension
.c
Size
54554 bytes
Lines
2162
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 vcnl4200_channel {
	u8 reg;
	ktime_t last_measurement;
	ktime_t sampling_rate;
	struct mutex lock;
};

struct vcnl4000_data {
	struct i2c_client *client;
	enum vcnl4000_device_ids id;
	int rev;
	int al_scale;
	int ps_scale;
	u8 ps_int;		/* proximity interrupt mode */
	u8 als_int;		/* ambient light interrupt mode*/
	const struct vcnl4000_chip_spec *chip_spec;
	struct mutex vcnl4000_lock;
	struct vcnl4200_channel vcnl4200_al;
	struct vcnl4200_channel vcnl4200_ps;
	uint32_t near_level;
};

struct vcnl4000_chip_spec {
	const char *prod;
	struct iio_chan_spec const *channels;
	const int num_channels;
	const struct iio_info *info;
	const struct iio_buffer_setup_ops *buffer_setup_ops;
	int (*init)(struct vcnl4000_data *data);
	int (*measure_light)(struct vcnl4000_data *data, int *val);
	int (*measure_proximity)(struct vcnl4000_data *data, int *val);
	int (*set_power_state)(struct vcnl4000_data *data, bool on);
	irqreturn_t (*irq_thread)(int irq, void *priv);
	irqreturn_t (*trig_buffer_func)(int irq, void *priv);

	u8 int_reg;
	const int(*ps_it_times)[][2];
	const int num_ps_it_times;
	const int(*als_it_times)[][2];
	const int num_als_it_times;
	const unsigned int ulux_step;
};

static const struct i2c_device_id vcnl4000_id[] = {
	{ "cm36672p", CM36672P },
	{ "cm36686", VCNL4040 },
	{ "vcnl4000", VCNL4000 },
	{ "vcnl4010", VCNL4010 },
	{ "vcnl4020", VCNL4010 },
	{ "vcnl4040", VCNL4040 },
	{ "vcnl4200", VCNL4200 },
	{ }
};
MODULE_DEVICE_TABLE(i2c, vcnl4000_id);

static int vcnl4000_set_power_state(struct vcnl4000_data *data, bool on)
{
	/* no suspend op */
	return 0;
}

static int vcnl4000_init(struct vcnl4000_data *data)
{
	int ret, prod_id;

	ret = i2c_smbus_read_byte_data(data->client, VCNL4000_PROD_REV);
	if (ret < 0)
		return ret;

	prod_id = ret >> 4;
	switch (prod_id) {
	case VCNL4000_PROD_ID:
		if (data->id != VCNL4000)
			dev_warn(&data->client->dev,
					"wrong device id, use vcnl4000");
		break;
	case VCNL4010_PROD_ID:
		if (data->id != VCNL4010)
			dev_warn(&data->client->dev,
					"wrong device id, use vcnl4010/4020");
		break;
	default:
		return -ENODEV;
	}

	data->rev = ret & 0xf;
	data->al_scale = 250000;

	return 0;
};

Annotation

Implementation Notes