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

Commit 1173fdd8 authored by Umang Agrawal's avatar Umang Agrawal
Browse files

power: battery: Modify main charger max FCC limiting logic



Primary charger FCC configuration can be limited to an upper bound
due to inductor current saturation limitation. However, in case, when
the charge current from SMB1390 flows through the BATFET of primary
charger, SMB1390 charge current will also be bounded by the FCC limit,
therefore limiting the overall charge current.

Add support to disregard max FCC limit in case SMB1390 switcher is
enabled.

Change-Id: I1542f04e6a65f44b3a82411a1cbfeaa72e0649c7
Signed-off-by: default avatarUmang Agrawal <uagrawal@codeaurora.org>
parent ec32d9d3
Loading
Loading
Loading
Loading
+44 −2
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ struct pl_data {
	struct power_supply	*batt_psy;
	struct power_supply	*usb_psy;
	struct power_supply	*dc_psy;
	struct power_supply	*cp_master_psy;
	int			charge_type;
	int			total_settled_ua;
	int			pl_settled_ua;
@@ -93,6 +94,7 @@ struct pl_data {
	struct wakeup_source	*pl_ws;
	struct notifier_block	nb;
	bool			pl_disable;
	bool			cp_disabled;
	int			taper_entry_fv;
	int			main_fcc_max;
};
@@ -483,6 +485,46 @@ static void get_fcc_split(struct pl_data *chip, int total_ua,
	}
}

static void get_main_fcc_config(struct pl_data *chip, int *total_fcc)
{
	union power_supply_propval pval = {0, };
	int rc;

	if (!chip->cp_master_psy)
		chip->cp_master_psy =
			power_supply_get_by_name("charge_pump_master");
	if (!chip->cp_master_psy)
		goto out;

	rc = power_supply_get_property(chip->cp_master_psy,
			POWER_SUPPLY_PROP_CP_SWITCHER_EN, &pval);
	if (rc < 0) {
		pr_err("Couldn't get switcher enable status, rc=%d\n", rc);
		goto out;
	}

	if (!pval.intval) {
		/*
		 * To honor main charger upper FCC limit, on CP switcher
		 * disable, skip fcc slewing as it will cause delay in limiting
		 * the charge current flowing through main charger.
		 */
		if (!chip->cp_disabled) {
			chip->fcc_stepper_enable = false;
			pl_dbg(chip, PR_PARALLEL,
				"Disabling FCC slewing on CP Switcher disable\n");
		}
		chip->cp_disabled = true;
	} else {
		chip->cp_disabled = false;
		pl_dbg(chip, PR_PARALLEL,
			"CP Switcher is enabled, don't limit main fcc\n");
		return;
	}
out:
	*total_fcc = min(*total_fcc, chip->main_fcc_max);
}

static void get_fcc_stepper_params(struct pl_data *chip, int main_fcc_ua,
			int parallel_fcc_ua)
{
@@ -1178,8 +1220,7 @@ static int pl_disable_vote_callback(struct votable *votable,
			(slave_fcc_ua * 100) / total_fcc_ua);
	} else {
		if (chip->main_fcc_max)
			total_fcc_ua = min(total_fcc_ua,
						chip->main_fcc_max);
			get_main_fcc_config(chip, &total_fcc_ua);

		if (!chip->fcc_stepper_enable) {
			if (IS_USBIN(chip->pl_mode))
@@ -1700,6 +1741,7 @@ int qcom_batt_init(int smb_version)
	}

	chip->pl_disable = true;
	chip->cp_disabled = true;
	chip->qcom_batt_class.name = "qcom-battery",
	chip->qcom_batt_class.owner = THIS_MODULE,
	chip->qcom_batt_class.class_groups = batt_class_groups;
+14 −1
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ struct smb1390 {
	struct smb1390_iio	iio;
	int			irq_status;
	int			taper_entry_fv;
	bool			switcher_disabled;
};

struct smb_irq {
@@ -270,7 +271,8 @@ static int smb1390_get_cp_en_status(struct smb1390 *chip, int id, bool *enable)
static irqreturn_t default_irq_handler(int irq, void *data)
{
	struct smb1390 *chip = data;
	int i;
	int i, rc;
	bool enable;

	for (i = 0; i < NUM_IRQS; ++i) {
		if (irq == chip->irqs[i]) {
@@ -279,8 +281,18 @@ static irqreturn_t default_irq_handler(int irq, void *data)
		}
	}

	rc = smb1390_get_cp_en_status(chip, SWITCHER_EN, &enable);
	if (!rc) {
		if (chip->switcher_disabled == enable) {
			chip->switcher_disabled = !chip->switcher_disabled;
			if (chip->fcc_votable)
				rerun_election(chip->fcc_votable);
		}
	}

	if (chip->cp_master_psy)
		power_supply_changed(chip->cp_master_psy);

	return IRQ_HANDLED;
}

@@ -979,6 +991,7 @@ static int smb1390_probe(struct platform_device *pdev)
	chip->dev = &pdev->dev;
	spin_lock_init(&chip->status_change_lock);
	mutex_init(&chip->die_chan_lock);
	chip->switcher_disabled = true;

	chip->regmap = dev_get_regmap(chip->dev->parent, NULL);
	if (!chip->regmap) {