drivers/power/supply/axp20x_battery.c

Source file repositories/reference/linux-study-clean/drivers/power/supply/axp20x_battery.c

File Facts

System
Linux kernel
Corpus path
drivers/power/supply/axp20x_battery.c
Extension
.c
Size
30789 bytes
Lines
1158
Domain
Driver Families
Bucket
drivers/power
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 axp_data {
	int		ccc_scale;
	int		ccc_offset;
	unsigned int	ccc_reg;
	unsigned int	ccc_mask;
	bool		has_fg_valid;
	const struct	power_supply_desc *bat_ps_desc;
	int	(*get_max_voltage)(struct axp20x_batt_ps *batt, int *val);
	int	(*set_max_voltage)(struct axp20x_batt_ps *batt, int val);
	int	(*cfg_iio_chan)(struct platform_device *pdev,
				struct axp20x_batt_ps *axp_batt);
	void	(*set_bat_info)(struct platform_device *pdev,
				struct axp20x_batt_ps *axp_batt,
				struct power_supply_battery_info *info);
};

struct axp20x_batt_ps {
	struct regmap *regmap;
	struct power_supply *batt;
	struct device *dev;
	struct iio_channel *batt_chrg_i;
	struct iio_channel *batt_dischrg_i;
	struct iio_channel *batt_v;
	/* Maximum constant charge current */
	unsigned int max_ccc;
	const struct axp_data	*data;
	bool ts_disable;
};

static int axp20x_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
					  int *val)
{
	int ret, reg;

	ret = regmap_read(axp20x_batt->regmap, AXP20X_CHRG_CTRL1, &reg);
	if (ret)
		return ret;

	switch (reg & AXP20X_CHRG_CTRL1_TGT_VOLT) {
	case AXP20X_CHRG_CTRL1_TGT_4_1V:
		*val = 4100000;
		break;
	case AXP20X_CHRG_CTRL1_TGT_4_15V:
		*val = 4150000;
		break;
	case AXP20X_CHRG_CTRL1_TGT_4_2V:
		*val = 4200000;
		break;
	case AXP20X_CHRG_CTRL1_TGT_4_36V:
		*val = 4360000;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

static int axp22x_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
					  int *val)
{
	int ret, reg;

	ret = regmap_read(axp20x_batt->regmap, AXP20X_CHRG_CTRL1, &reg);
	if (ret)
		return ret;

	switch (reg & AXP20X_CHRG_CTRL1_TGT_VOLT) {
	case AXP20X_CHRG_CTRL1_TGT_4_1V:
		*val = 4100000;
		break;
	case AXP20X_CHRG_CTRL1_TGT_4_2V:
		*val = 4200000;
		break;
	case AXP22X_CHRG_CTRL1_TGT_4_22V:
		*val = 4220000;
		break;
	case AXP22X_CHRG_CTRL1_TGT_4_24V:
		*val = 4240000;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

static int axp717_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
					  int *val)
{

Annotation

Implementation Notes