drivers/iio/light/pa12203001.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/pa12203001.c
Extension
.c
Size
11334 bytes
Lines
482
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 pa12203001_data {
	struct i2c_client *client;

	/* protect device states */
	struct mutex lock;

	bool als_enabled;
	bool px_enabled;
	bool als_needs_enable;
	bool px_needs_enable;

	struct regmap *map;
};

static const struct {
	u8 reg;
	u8 val;
} regvals[] = {
	{PA12203001_REG_CFG0, PA12203001_REG_CFG0_DEFAULT},
	{PA12203001_REG_CFG1, PA12203001_REG_CFG1_DEFAULT},
	{PA12203001_REG_CFG2, PA12203001_REG_CFG2_DEFAULT},
	{PA12203001_REG_CFG3, PA12203001_REG_CFG3_DEFAULT},
	{PA12203001_REG_PSET, PA12203001_PSCAN},
};

static IIO_CONST_ATTR(in_illuminance_scale_available,
		      "0.007629 0.061036 0.106813 0.473029");

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

static const struct attribute_group pa12203001_attr_group = {
	.attrs = pa12203001_attrs,
};

static const struct iio_chan_spec pa12203001_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),
	}
};

static const struct regmap_range pa12203001_volatile_regs_ranges[] = {
	regmap_reg_range(PA12203001_REG_ADL, PA12203001_REG_ADL + 1),
	regmap_reg_range(PA12203001_REG_PDH, PA12203001_REG_PDH),
};

static const struct regmap_access_table pa12203001_volatile_regs = {
	.yes_ranges = pa12203001_volatile_regs_ranges,
	.n_yes_ranges = ARRAY_SIZE(pa12203001_volatile_regs_ranges),
};

static const struct regmap_config pa12203001_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.max_register = PA12203001_REG_PSET,
	.cache_type = REGCACHE_RBTREE,
	.volatile_table = &pa12203001_volatile_regs,
};

static inline int pa12203001_als_enable(struct pa12203001_data *data, u8 enable)
{
	int ret;

	ret = regmap_update_bits(data->map, PA12203001_REG_CFG0,
				 PA12203001_ALS_EN_MASK, enable);
	if (ret < 0)
		return ret;

	data->als_enabled = !!enable;

	return 0;
}

static inline int pa12203001_px_enable(struct pa12203001_data *data, u8 enable)
{
	int ret;

	ret = regmap_update_bits(data->map, PA12203001_REG_CFG0,
				 PA12203001_PX_EN_MASK, enable);
	if (ret < 0)
		return ret;

Annotation

Implementation Notes