Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc1a7598 authored by Anirudh Ghayal's avatar Anirudh Ghayal
Browse files

power: qcom-battery: Add sysfs to restrict charging



Add sysfs files for user applications to restrict
the battery charge current (FCC). The two files in
/sys/class/qcom-battery/ are -

1. restricted_charging: To enable/disable this feature
2. restricted_current: Restricted FCC (uA)

The default restricted_current value is 1A.

CRs-Fixed: 1113761
Change-Id: I23a6796eaa0c41c2e93a52c45f6200326d262e99
Signed-off-by: default avatarAnirudh Ghayal <aghayal@codeaurora.org>
parent 541fe938
Loading
Loading
Loading
Loading
+75 −0
Original line number Diff line number Diff line
@@ -35,12 +35,15 @@
#define PARALLEL_PSY_VOTER		"PARALLEL_PSY_VOTER"
#define PL_HW_ABSENT_VOTER		"PL_HW_ABSENT_VOTER"
#define PL_VOTER			"PL_VOTER"
#define RESTRICT_CHG_VOTER		"RESTRICT_CHG_VOTER"

struct pl_data {
	int			pl_mode;
	int			slave_pct;
	int			taper_pct;
	int			slave_fcc_ua;
	int			restricted_current;
	bool			restricted_charging_enabled;
	struct votable		*fcc_votable;
	struct votable		*fv_votable;
	struct votable		*pl_disable_votable;
@@ -80,6 +83,8 @@ module_param_named(debug_mask, debug_mask, int, S_IRUSR | S_IWUSR);
enum {
	VER = 0,
	SLAVE_PCT,
	RESTRICT_CHG_ENABLE,
	RESTRICT_CHG_CURRENT,
};

/*******
@@ -180,10 +185,78 @@ static ssize_t slave_pct_store(struct class *c, struct class_attribute *attr,
	return count;
}

/**********************
* RESTICTED CHARGIGNG *
***********************/
static ssize_t restrict_chg_show(struct class *c, struct class_attribute *attr,
			char *ubuf)
{
	struct pl_data *chip = container_of(c, struct pl_data,
			qcom_batt_class);

	return snprintf(ubuf, PAGE_SIZE, "%d\n",
			chip->restricted_charging_enabled);
}

static ssize_t restrict_chg_store(struct class *c, struct class_attribute *attr,
			const char *ubuf, size_t count)
{
	struct pl_data *chip = container_of(c, struct pl_data,
			qcom_batt_class);
	unsigned long val;

	if (kstrtoul(ubuf, 10, &val))
		return -EINVAL;

	if (chip->restricted_charging_enabled == !!val)
		goto no_change;

	chip->restricted_charging_enabled = !!val;

	vote(chip->fcc_votable, RESTRICT_CHG_VOTER,
				chip->restricted_charging_enabled,
				chip->restricted_current);

no_change:
	return count;
}

static ssize_t restrict_cur_show(struct class *c, struct class_attribute *attr,
			char *ubuf)
{
	struct pl_data *chip = container_of(c, struct pl_data,
			qcom_batt_class);

	return snprintf(ubuf, PAGE_SIZE, "%d\n", chip->restricted_current);
}

static ssize_t restrict_cur_store(struct class *c, struct class_attribute *attr,
			const char *ubuf, size_t count)
{
	struct pl_data *chip = container_of(c, struct pl_data,
			qcom_batt_class);
	unsigned long val;

	if (kstrtoul(ubuf, 10, &val))
		return -EINVAL;

	chip->restricted_current = val;

	vote(chip->fcc_votable, RESTRICT_CHG_VOTER,
				chip->restricted_charging_enabled,
				chip->restricted_current);

	return count;
}

static struct class_attribute pl_attributes[] = {
	[VER]			= __ATTR_RO(version),
	[SLAVE_PCT]		= __ATTR(parallel_pct, S_IRUGO | S_IWUSR,
					slave_pct_show, slave_pct_store),
	[RESTRICT_CHG_ENABLE]	= __ATTR(restricted_charging, S_IRUGO | S_IWUSR,
					restrict_chg_show, restrict_chg_store),
	[RESTRICT_CHG_CURRENT]	= __ATTR(restricted_current, S_IRUGO | S_IWUSR,
					restrict_cur_show, restrict_cur_store),
	__ATTR_NULL,
};

@@ -750,6 +823,7 @@ static int pl_determine_initial_status(struct pl_data *chip)
	return 0;
}

#define DEFAULT_RESTRICTED_CURRENT_UA	1000000
static int pl_init(void)
{
	struct pl_data *chip;
@@ -759,6 +833,7 @@ static int pl_init(void)
	if (!chip)
		return -ENOMEM;
	chip->slave_pct = 50;
	chip->restricted_current = DEFAULT_RESTRICTED_CURRENT_UA;

	chip->pl_ws = wakeup_source_register("qcom-battery");
	if (!chip->pl_ws)