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

Commit 0cd6c7d9 authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar
Browse files

power: qpnp-smbcharger: allow lowering of charger current



Once parallel charger is activated, the next AICL could result in
lower charge current than the initial one. Allow for lowering
the charger current, since enabling charging via two sources
reduces thermal losses.

At the same time restrict the lowering of current to prevent
any unreasonable charger current drops.

CRs-Fixed: 733213
Change-Id: I70cd64b67112bb26e9afd5b9d1b04ed9a407ba8e
Signed-off-by: default avatarAbhijeet Dharmapurikar <adharmap@codeaurora.org>
parent 511c34bf
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -173,6 +173,11 @@ Optional Properties:
					charger if one exists. Do not define
					charger if one exists. Do not define
					this property if no parallel chargers
					this property if no parallel chargers
					exist.
					exist.
- qcom,parallel-allowed-lowering-ma	Acceptable current drop from the initial limit
					to keep parallel charger activated. If the
					charger current reduces beyond this threshold
					parallel charger is disabled. Must be specified
					if parallel charger is used.


Example:
Example:
	qcom,qpnp-smbcharger {
	qcom,qpnp-smbcharger {
+1 −0
Original line number Original line Diff line number Diff line
@@ -171,6 +171,7 @@
			qcom,thermal-mitigation = <1500 700 600 0>;
			qcom,thermal-mitigation = <1500 700 600 0>;
			qcom,parallel-usb-min-current-ma = <1400>;
			qcom,parallel-usb-min-current-ma = <1400>;
			qcom,parallel-9v-usb-min-current-ma = <900>;
			qcom,parallel-9v-usb-min-current-ma = <900>;
			qcom,parallel-allowed-lowering-ma = <500>;
			regulator-name = "pmi8994_otg_vreg";
			regulator-name = "pmi8994_otg_vreg";


			qcom,chgr@1000 {
			qcom,chgr@1000 {
+23 −4
Original line number Original line Diff line number Diff line
@@ -47,9 +47,11 @@ struct parallel_usb_cfg {
	struct power_supply		*psy;
	struct power_supply		*psy;
	int				min_current_thr_ma;
	int				min_current_thr_ma;
	int				min_9v_current_thr_ma;
	int				min_9v_current_thr_ma;
	int				allowed_lowering_ma;
	int				current_max_ma;
	int				current_max_ma;
	bool				avail;
	bool				avail;
	struct mutex			lock;
	struct mutex			lock;
	int				initial_aicl_ma;
};
};


struct smbchg_chip {
struct smbchg_chip {
@@ -1139,7 +1141,7 @@ static bool smbchg_is_parallel_usb_ok(struct smbchg_chip *chip)
		return false;
		return false;
	}
	}
	if (chip->usb_tl_current_ma < min_current_thr_ma) {
	if (chip->usb_tl_current_ma < min_current_thr_ma) {
		pr_smb(PR_STATUS, "Too little current to enable: %d < %d\n",
		pr_smb(PR_STATUS, "Weak USB chg skip enable: %d < %d\n",
			chip->usb_tl_current_ma, min_current_thr_ma);
			chip->usb_tl_current_ma, min_current_thr_ma);
		return false;
		return false;
	}
	}
@@ -1225,6 +1227,7 @@ static void smbchg_parallel_usb_disable(struct smbchg_chip *chip)
		return;
		return;
	pr_smb(PR_STATUS, "disabling parallel charger\n");
	pr_smb(PR_STATUS, "disabling parallel charger\n");
	taper_irq_en(chip, false);
	taper_irq_en(chip, false);
	chip->parallel.initial_aicl_ma = 0;
	chip->parallel.current_max_ma = 0;
	chip->parallel.current_max_ma = 0;
	power_supply_set_current_limit(parallel_psy,
	power_supply_set_current_limit(parallel_psy,
				SUSPEND_CURRENT_MA * 1000);
				SUSPEND_CURRENT_MA * 1000);
@@ -1335,6 +1338,15 @@ static void smbchg_parallel_usb_enable(struct smbchg_chip *chip)
	if (current_limit_ma <= 0)
	if (current_limit_ma <= 0)
		goto disable_parallel;
		goto disable_parallel;


	if (chip->parallel.initial_aicl_ma == 0) {
		if (current_limit_ma < min_current_thr_ma) {
			pr_smb(PR_STATUS, "Initial AICL very low: %d < %d\n",
				current_limit_ma, min_current_thr_ma);
			goto disable_parallel;
		}
		chip->parallel.initial_aicl_ma = current_limit_ma;
	}

	/*
	/*
	 * Use the previous set current from the parallel charger.
	 * Use the previous set current from the parallel charger.
	 * Treat 2mA as 0 because that is the suspend current setting
	 * Treat 2mA as 0 because that is the suspend current setting
@@ -1349,9 +1361,14 @@ static void smbchg_parallel_usb_enable(struct smbchg_chip *chip)
	 */
	 */
	total_current_ma = current_limit_ma + parallel_cl_ma;
	total_current_ma = current_limit_ma + parallel_cl_ma;


	if (total_current_ma < min_current_thr_ma) {
	if (total_current_ma < chip->parallel.initial_aicl_ma
		pr_smb(PR_STATUS, "Too little current to enable: %d < %d\n",
			- chip->parallel.allowed_lowering_ma) {
				total_current_ma, min_current_thr_ma);
		pr_smb(PR_STATUS,
			"Too little total current : %d (%d + %d) < %d - %d\n",
			total_current_ma,
			current_limit_ma, parallel_cl_ma,
			chip->parallel.initial_aicl_ma,
			chip->parallel.allowed_lowering_ma);
		goto disable_parallel;
		goto disable_parallel;
	}
	}


@@ -2912,6 +2929,8 @@ static int smb_parse_dt(struct smbchg_chip *chip)
			"parallel-usb-min-current-ma", rc, 1);
			"parallel-usb-min-current-ma", rc, 1);
	OF_PROP_READ(chip, chip->parallel.min_9v_current_thr_ma,
	OF_PROP_READ(chip, chip->parallel.min_9v_current_thr_ma,
			"parallel-usb-9v-min-current-ma", rc, 1);
			"parallel-usb-9v-min-current-ma", rc, 1);
	OF_PROP_READ(chip, chip->parallel.allowed_lowering_ma,
			"parallel-allowed-lowering-ma", rc, 1);
	if (chip->parallel.min_current_thr_ma != -EINVAL)
	if (chip->parallel.min_current_thr_ma != -EINVAL)
		chip->parallel.avail = true;
		chip->parallel.avail = true;
	pr_smb(PR_STATUS, "parallel usb thr: %d, 9v thr: %d\n",
	pr_smb(PR_STATUS, "parallel usb thr: %d, 9v thr: %d\n",