drivers/iio/light/us5182d.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/us5182d.c
Extension
.c
Size
22924 bytes
Lines
981
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 us5182d_data {
	struct i2c_client *client;
	struct mutex lock;

	/* Glass attenuation factor */
	u32 ga;

	/* Dark gain tuning */
	u8 lower_dark_gain;
	u8 upper_dark_gain;
	u16 *us5182d_dark_ths;

	u16 px_low_th;
	u16 px_high_th;

	int rising_en;
	int falling_en;

	u8 opmode;
	u8 power_mode;

	bool als_enabled;
	bool px_enabled;

	bool default_continuous;
};

static IIO_CONST_ATTR(in_illuminance_scale_available,
		      "0.0021 0.0039 0.0076 0.0196 0.0336 0.061 0.1078 0.1885");

static struct attribute *us5182d_attrs[] = {
	&iio_const_attr_in_illuminance_scale_available.dev_attr.attr,
	NULL
};

static const struct attribute_group us5182d_attr_group = {
	.attrs = us5182d_attrs,
};

static const struct {
	u8 reg;
	u8 val;
} us5182d_regvals[] = {
	{US5182D_REG_CFG0, US5182D_CFG0_WORD_ENABLE},
	{US5182D_REG_CFG1, US5182D_CFG1_ALS_RES16},
	{US5182D_REG_CFG2, (US5182D_CFG2_PX_RES16 |
			    US5182D_CFG2_PXGAIN_DEFAULT)},
	{US5182D_REG_CFG3, US5182D_CFG3_LED_CURRENT100 |
			   US5182D_CFG3_INT_SOURCE_PX},
	{US5182D_REG_CFG4, 0x00},
};

static const struct iio_event_spec us5182d_events[] = {
	{
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_RISING,
		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
				BIT(IIO_EV_INFO_ENABLE),
	},
	{
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_FALLING,
		.mask_separate = BIT(IIO_EV_INFO_VALUE) |
				BIT(IIO_EV_INFO_ENABLE),
	},
};

static const struct iio_chan_spec us5182d_channels[] = {
	{
		.type = IIO_LIGHT,
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
				      BIT(IIO_CHAN_INFO_SCALE),
	},
	{
		.type = IIO_PROXIMITY,
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
		.event_spec = us5182d_events,
		.num_event_specs = ARRAY_SIZE(us5182d_events),
	}
};

static int us5182d_oneshot_en(struct us5182d_data *data)
{
	int ret;

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

	/*

Annotation

Implementation Notes