drivers/iio/light/bh1745.c

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

File Facts

System
Linux kernel
Corpus path
drivers/iio/light/bh1745.c
Extension
.c
Size
22548 bytes
Lines
902
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 bh1745_data {
	/*
	 * Lock to prevent device setting update or read before
	 * related calculations are completed
	 */
	struct mutex lock;
	struct regmap *regmap;
	struct device *dev;
	struct iio_trigger *trig;
	struct iio_gts gts;
};

static const struct regmap_range bh1745_volatile_ranges[] = {
	regmap_reg_range(BH1745_MODE_CTRL2, BH1745_MODE_CTRL2), /* VALID */
	regmap_reg_range(BH1745_RED_LSB, BH1745_CLEAR_MSB), /* Data */
	regmap_reg_range(BH1745_INTR, BH1745_INTR), /* Interrupt */
};

static const struct regmap_access_table bh1745_volatile_regs = {
	.yes_ranges = bh1745_volatile_ranges,
	.n_yes_ranges = ARRAY_SIZE(bh1745_volatile_ranges),
};

static const struct regmap_range bh1745_readable_ranges[] = {
	regmap_reg_range(BH1745_SYS_CTRL, BH1745_MODE_CTRL2),
	regmap_reg_range(BH1745_RED_LSB, BH1745_CLEAR_MSB),
	regmap_reg_range(BH1745_INTR, BH1745_INTR),
	regmap_reg_range(BH1745_PERSISTENCE, BH1745_TL_MSB),
	regmap_reg_range(BH1745_MANU_ID_REG, BH1745_MANU_ID_REG),
};

static const struct regmap_access_table bh1745_readable_regs = {
	.yes_ranges = bh1745_readable_ranges,
	.n_yes_ranges = ARRAY_SIZE(bh1745_readable_ranges),
};

static const struct regmap_range bh1745_writable_ranges[] = {
	regmap_reg_range(BH1745_SYS_CTRL, BH1745_MODE_CTRL2),
	regmap_reg_range(BH1745_INTR, BH1745_INTR),
	regmap_reg_range(BH1745_PERSISTENCE, BH1745_TL_MSB),
};

static const struct regmap_access_table bh1745_writable_regs = {
	.yes_ranges = bh1745_writable_ranges,
	.n_yes_ranges = ARRAY_SIZE(bh1745_writable_ranges),
};

static const struct regmap_config bh1745_regmap = {
	.reg_bits = 8,
	.val_bits = 8,
	.max_register = BH1745_MANU_ID_REG,
	.cache_type = REGCACHE_RBTREE,
	.volatile_table = &bh1745_volatile_regs,
	.wr_table = &bh1745_writable_regs,
	.rd_table = &bh1745_readable_regs,
};

static const struct iio_event_spec bh1745_event_spec[] = {
	{
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_RISING,
		.mask_shared_by_type = BIT(IIO_EV_INFO_VALUE),
	},
	{
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_FALLING,
		.mask_shared_by_type = BIT(IIO_EV_INFO_VALUE),
	},
	{
		.type = IIO_EV_TYPE_THRESH,
		.dir = IIO_EV_DIR_EITHER,
		.mask_shared_by_type = BIT(IIO_EV_INFO_PERIOD),
		.mask_separate = BIT(IIO_EV_INFO_ENABLE),
	},
};

#define BH1745_CHANNEL(_colour, _si, _addr)                             \
	{                                                               \
		.type = IIO_INTENSITY, .modified = 1,                   \
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE) |   \
					   BIT(IIO_CHAN_INFO_INT_TIME), \
		.info_mask_shared_by_all_available =                    \
			BIT(IIO_CHAN_INFO_SCALE) |                      \
			BIT(IIO_CHAN_INFO_INT_TIME),                    \
		.event_spec = bh1745_event_spec,                        \
		.num_event_specs = ARRAY_SIZE(bh1745_event_spec),       \
		.channel2 = IIO_MOD_LIGHT_##_colour, .address = _addr,  \
		.scan_index = _si,                                      \
		.scan_type = {                                          \

Annotation

Implementation Notes