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

Commit a0bfb856 authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: qpnp-smbcharger: support configuring fast charge current dynamically



During parallel charging, there might be a need to configure
fast charge current dynamically. If the fast charge current is
less than 1800 mA, then do the configuration only on main
charger and suspend the parallel charger. If the fast charge
current is more than 1800 mA, then configure the charge current
on both main and parallel chargers with half of that value.

CRs-Fixed: 782147
Change-Id: I1c66349ea3b35a9871f2fa77c71c534061c70529
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent 9097bde8
Loading
Loading
Loading
Loading
+42 −4
Original line number Diff line number Diff line
@@ -1522,10 +1522,10 @@ static int smbchg_set_fastchg_current_raw(struct smbchg_chip *chip,
		dev_err(chip->dev, "cannot write to fcc cfg rc = %d\n", rc);
		return rc;
	}
	pr_smb(PR_STATUS, "fastcharge current set to %d\n",
			current_ma);
	pr_smb(PR_STATUS, "fastcharge current requested %d, set to %d\n",
			current_ma, usb_current_table[cur_val]);

	chip->fastchg_current_ma = usb_current_table[i];
	chip->fastchg_current_ma = usb_current_table[cur_val];
	return rc;
}

@@ -1716,6 +1716,7 @@ static int smbchg_get_aicl_level_ma(struct smbchg_chip *chip)
	return usb_current_table[reg];
}

#define PARALLEL_CHG_THRESHOLD_CURRENT	1800
static void smbchg_parallel_usb_enable(struct smbchg_chip *chip)
{
	struct power_supply *parallel_psy = get_parallel_psy(chip);
@@ -1727,6 +1728,12 @@ static void smbchg_parallel_usb_enable(struct smbchg_chip *chip)
		return;

	pr_smb(PR_STATUS, "Attempting to enable parallel charger\n");
	/* Suspend the parallel charger if the charging current is < 1800 mA */
	if (chip->cfg_fastchg_current_ma < PARALLEL_CHG_THRESHOLD_CURRENT) {
		pr_smb(PR_STATUS, "suspend parallel charger as FCC is %d\n",
			chip->cfg_fastchg_current_ma);
		goto disable_parallel;
	}
	min_current_thr_ma = smbchg_get_min_parallel_current_ma(chip);
	if (min_current_thr_ma <= 0) {
		pr_smb(PR_STATUS, "parallel charger unavailable for thr: %d\n",
@@ -1858,6 +1865,37 @@ static int smbchg_usb_en(struct smbchg_chip *chip, bool enable,
	return rc;
}

static int smbchg_set_fastchg_current_user(struct smbchg_chip *chip,
							int current_ma)
{
	int rc = 0;

	mutex_lock(&chip->parallel.lock);
	pr_smb(PR_STATUS, "User setting FCC to %d\n", current_ma);
	chip->cfg_fastchg_current_ma = current_ma;
	if (smbchg_is_parallel_usb_ok(chip)) {
		smbchg_parallel_usb_enable(chip);
	} else {
		if (chip->parallel.current_max_ma != 0) {
			/*
			 * If parallel charging is not available, disable it.
			 * FCC for main charger will be configured in that.
			 */
			pr_smb(PR_STATUS, "parallel charging unavailable\n");
			smbchg_parallel_usb_disable(chip);
			goto out;
		}
		rc = smbchg_set_fastchg_current(chip,
				chip->cfg_fastchg_current_ma);
		if (rc)
			pr_err("Couldn't set fastchg current rc: %d\n",
				rc);
	}
out:
	mutex_unlock(&chip->parallel.lock);
	return rc;
}

static struct ilim_entry *smbchg_wipower_find_entry(struct smbchg_chip *chip,
				struct ilim_map *map, int uv)
{
@@ -2466,7 +2504,7 @@ static int smbchg_battery_set_property(struct power_supply *psy,
		smbchg_system_temp_level_set(chip, val->intval);
		break;
	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
		rc = smbchg_set_fastchg_current(chip, val->intval / 1000);
		rc = smbchg_set_fastchg_current_user(chip, val->intval / 1000);
		break;
	case POWER_SUPPLY_PROP_VOLTAGE_MAX:
		rc = smbchg_float_voltage_set(chip, val->intval);