drivers/iio/adc/rohm-bd79124.c

Source file repositories/reference/linux-study-clean/drivers/iio/adc/rohm-bd79124.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/adc/rohm-bd79124.c
Extension
.c
Size
30604 bytes
Lines
1126
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 bd79124_data {
	s64 timestamp;
	struct regmap *map;
	struct device *dev;
	int vmax;
	/*
	 * Keep measurement status so read_raw() knows if the measurement needs
	 * to be started.
	 */
	int alarm_monitored[BD79124_MAX_NUM_CHANNELS];
	/*
	 * The BD79124 does not allow disabling/enabling limit separately for
	 * one direction only. Hence, we do the disabling by changing the limit
	 * to maximum/minimum measurable value. This means we need to cache
	 * the limit in order to maintain it over the time limit is disabled.
	 */
	u16 alarm_r_limit[BD79124_MAX_NUM_CHANNELS];
	u16 alarm_f_limit[BD79124_MAX_NUM_CHANNELS];
	/* Bitmask of disabled events (for rate limiting) for each channel. */
	int alarm_suppressed[BD79124_MAX_NUM_CHANNELS];
	/*
	 * The BD79124 is configured to run the measurements in the background.
	 * This is done for the event monitoring as well as for the read_raw().
	 * Protect the measurement starting/stopping using a mutex.
	 */
	struct mutex mutex;
	struct delayed_work alm_enable_work;
	struct gpio_chip gc;
	u8 gpio_valid_mask;
};

static const struct regmap_range bd79124_ro_ranges[] = {
	regmap_reg_range(BD79124_REG_EVENT_FLAG, BD79124_REG_EVENT_FLAG),
	regmap_reg_range(BD79124_REG_RECENT_CH0_LSB, BD79124_REG_RECENT_CH7_MSB),
};

static const struct regmap_access_table bd79124_ro_regs = {
	.no_ranges	= &bd79124_ro_ranges[0],
	.n_no_ranges	= ARRAY_SIZE(bd79124_ro_ranges),
};

static const struct regmap_range bd79124_volatile_ranges[] = {
	regmap_reg_range(BD79124_REG_RECENT_CH0_LSB, BD79124_REG_RECENT_CH7_MSB),
	regmap_reg_range(BD79124_REG_EVENT_FLAG, BD79124_REG_EVENT_FLAG),
	regmap_reg_range(BD79124_REG_EVENT_FLAG_HI, BD79124_REG_EVENT_FLAG_HI),
	regmap_reg_range(BD79124_REG_EVENT_FLAG_LO, BD79124_REG_EVENT_FLAG_LO),
	regmap_reg_range(BD79124_REG_SYSTEM_STATUS, BD79124_REG_SYSTEM_STATUS),
};

static const struct regmap_access_table bd79124_volatile_regs = {
	.yes_ranges	= &bd79124_volatile_ranges[0],
	.n_yes_ranges	= ARRAY_SIZE(bd79124_volatile_ranges),
};

static const struct regmap_range bd79124_precious_ranges[] = {
	regmap_reg_range(BD79124_REG_EVENT_FLAG_HI, BD79124_REG_EVENT_FLAG_HI),
	regmap_reg_range(BD79124_REG_EVENT_FLAG_LO, BD79124_REG_EVENT_FLAG_LO),
};

static const struct regmap_access_table bd79124_precious_regs = {
	.yes_ranges	= &bd79124_precious_ranges[0],
	.n_yes_ranges	= ARRAY_SIZE(bd79124_precious_ranges),
};

static const struct regmap_config bd79124_regmap = {
	.reg_bits		= 16,
	.val_bits		= 8,
	.read_flag_mask		= BD79124_I2C_MULTI_READ,
	.write_flag_mask	= BD79124_I2C_MULTI_WRITE,
	.max_register		= BD79124_REG_MAX,
	.cache_type		= REGCACHE_MAPLE,
	.volatile_table		= &bd79124_volatile_regs,
	.wr_table		= &bd79124_ro_regs,
	.precious_table		= &bd79124_precious_regs,
};

static int bd79124gpo_direction_get(struct gpio_chip *gc, unsigned int offset)
{
	return GPIO_LINE_DIRECTION_OUT;
}

static int bd79124gpo_set(struct gpio_chip *gc, unsigned int offset, int value)
{
	struct bd79124_data *data = gpiochip_get_data(gc);

	return regmap_assign_bits(data->map, BD79124_REG_GPO_VAL, BIT(offset),
				  value);
}

static int bd79124gpo_set_multiple(struct gpio_chip *gc, unsigned long *mask,

Annotation

Implementation Notes