drivers/mfd/rohm-bd71828.c

Source file repositories/reference/linux-study-clean/drivers/mfd/rohm-bd71828.c

File Facts

System
Linux kernel
Corpus path
drivers/mfd/rohm-bd71828.c
Extension
.c
Size
48369 bytes
Lines
1086
Domain
Driver Families
Bucket
drivers/mfd
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 bd72720_regmaps {
	struct regmap *map1_4b;
	struct regmap *map2_4c;
};

/* Translate the slave 0x4c wrapper register address to a real one */
#define BD72720_REG_UNWRAP(reg) ((reg) - BD72720_SECONDARY_I2C_REG_OFFSET)

/* Ranges given to 'real' 0x4c regmap must use unwrapped addresses. */
#define BD72720_UNWRAP_REG_RANGE(startreg, endreg)					\
	regmap_reg_range(BD72720_REG_UNWRAP(startreg), BD72720_REG_UNWRAP(endreg))

static const struct regmap_range bd72720_volatile_ranges_4c[] = {
	/* Status information */
	BD72720_UNWRAP_REG_RANGE(BD72720_REG_CHG_STATE, BD72720_REG_CHG_EN),
	/*
	 * Under certain circumstances, write to some bits may be
	 * ignored
	 */
	BD72720_UNWRAP_REG_RANGE(BD72720_REG_CHG_CTRL, BD72720_REG_CHG_CTRL),
	/*
	 * TODO: Ensure this is used to advertise state, not (only?) to
	 * control it.
	 */
	BD72720_UNWRAP_REG_RANGE(BD72720_REG_VSYS_STATE_STAT, BD72720_REG_VSYS_STATE_STAT),
	/* Measured data */
	BD72720_UNWRAP_REG_RANGE(BD72720_REG_VM_VBAT_U, BD72720_REG_VM_VF_L),
	/* Self clearing bits */
	BD72720_UNWRAP_REG_RANGE(BD72720_REG_VM_VSYS_SA_MINMAX_CTRL,
				 BD72720_REG_VM_VSYS_SA_MINMAX_CTRL),
	/* Counters, self clearing bits */
	BD72720_UNWRAP_REG_RANGE(BD72720_REG_CC_CURCD_U, BD72720_REG_CC_CTRL),
	/* Self clearing bits */
	BD72720_UNWRAP_REG_RANGE(BD72720_REG_CC_CCNTD_CTRL, BD72720_REG_CC_CCNTD_CTRL),
	/* Self clearing bits */
	BD72720_UNWRAP_REG_RANGE(BD72720_REG_IMPCHK_CTRL, BD72720_REG_IMPCHK_CTRL),
};

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

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

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

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

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

static const struct regmap_config bd71815_regmap = {
	.reg_bits = 8,
	.val_bits = 8,
	.volatile_table = &bd71815_volatile_regs,
	.max_register = BD71815_MAX_REGISTER - 1,
	.cache_type = REGCACHE_MAPLE,
};

static const struct regmap_config bd71828_regmap = {
	.reg_bits = 8,
	.val_bits = 8,
	.volatile_table = &bd71828_volatile_regs,
	.max_register = BD71828_MAX_REGISTER,
	.cache_type = REGCACHE_MAPLE,
};

static int regmap_write_wrapper(void *context, unsigned int reg, unsigned int val)
{
	struct bd72720_regmaps *maps = context;

	if (reg < BD72720_SECONDARY_I2C_REG_OFFSET)
		return regmap_write(maps->map1_4b, reg, val);

	reg = BD72720_REG_UNWRAP(reg);

	return regmap_write(maps->map2_4c, reg, val);
}

Annotation

Implementation Notes