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

Commit 10b4674e authored by Umang Agrawal's avatar Umang Agrawal Committed by Gerrit - the friendly Code Review server
Browse files

power: smb1390: add support to disable smb1390 based on SOC



Charger driver disables SMB1390 once charging enters Taper charging
phase, this is to prevent SMB1390 from pumping high current into battery
at higher voltages. There are condition like adapter reset where SMB1390
might get enabled at higher battery voltage and pump current into the
battery before software gets chance to disable it and this could lead to
battery OV.

Fix this by by keeping SMB1390 disabled above a configured battery SOC.

Change-Id: I2b5a93fdebfb4f17f7c97c74775efcdb406308b4
Signed-off-by: default avatarUmang Agrawal <uagrawal@codeaurora.org>
parent 8d9b94b2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -32,6 +32,12 @@ Charger specific properties:
  Definition: For details about IIO bindings see:
	      Documentation/devicetree/bindings/iio/iio-bindings.txt

- qcom,max-cutoff-soc
  Usage:      optional
  Value type: <u32>
  Definition: SOC beyond which SMB1390 is kept disabled.
	      If this value is not specified then default value is 85%.

================================================
Second Level Nodes - SMB1390 Charger Peripherals
================================================
+36 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@
#define WIRELESS_VOTER		"WIRELESS_VOTER"
#define SRC_VOTER		"SRC_VOTER"
#define SWITCHER_TOGGLE_VOTER	"SWITCHER_TOGGLE_VOTER"
#define SOC_LEVEL_VOTER		"SOC_LEVEL_VOTER"

enum {
	SWITCHER_OFF_WINDOW_IRQ = 0,
@@ -141,6 +142,7 @@ struct smb1390 {
	struct smb1390_iio	iio;
	int			irq_status;
	int			taper_entry_fv;
	u32			max_cutoff_soc;
};

struct smb_irq {
@@ -231,6 +233,28 @@ static void cp_toggle_switcher(struct smb1390 *chip)
	vote(chip->disable_votable, SWITCHER_TOGGLE_VOTER, false, 0);
}

static int smb1390_is_batt_soc_valid(struct smb1390 *chip)
{
	int rc;
	union power_supply_propval pval = {0, };

	if (!chip->batt_psy)
		goto out;

	rc = power_supply_get_property(chip->batt_psy,
			POWER_SUPPLY_PROP_CAPACITY, &pval);
	if (rc < 0) {
		pr_err("Couldn't get CAPACITY rc=%d\n", rc);
		goto out;
	}

	if (pval.intval >= chip->max_cutoff_soc)
		return false;

out:
	return true;
}

static irqreturn_t default_irq_handler(int irq, void *data)
{
	struct smb1390 *chip = data;
@@ -561,6 +585,9 @@ static void smb1390_status_change_work(struct work_struct *work)
	if (!is_psy_voter_available(chip))
		goto out;

	vote(chip->disable_votable, SOC_LEVEL_VOTER,
			smb1390_is_batt_soc_valid(chip) ? false : true, 0);

	rc = power_supply_get_property(chip->usb_psy,
			POWER_SUPPLY_PROP_SMB_EN_MODE, &pval);
	if (rc < 0) {
@@ -646,6 +673,7 @@ static void smb1390_status_change_work(struct work_struct *work)
				BATT_PROFILE_VOTER);
		vote(chip->fcc_votable, CP_VOTER,
				max_fcc_ma > 0 ? true : false, max_fcc_ma);
		vote(chip->disable_votable, SOC_LEVEL_VOTER, true, 0);
	}

out:
@@ -724,6 +752,10 @@ static int smb1390_parse_dt(struct smb1390 *chip)
		}
	}

	chip->max_cutoff_soc = 85; /* 85% */
	of_property_read_u32(chip->dev->of_node, "qcom,max-cutoff-soc",
			&chip->max_cutoff_soc);

	return rc;
}

@@ -769,6 +801,9 @@ static int smb1390_init_hw(struct smb1390 *chip)
	 * traditional parallel charging if present
	 */
	vote(chip->disable_votable, USER_VOTER, true, 0);
	/* keep charge pump disabled if SOC is above threshold */
	vote(chip->disable_votable, SOC_LEVEL_VOTER,
			smb1390_is_batt_soc_valid(chip) ? false : true, 0);

	/*
	 * Improve ILIM accuracy:
@@ -952,6 +987,7 @@ static int smb1390_remove(struct platform_device *pdev)

	/* explicitly disable charging */
	vote(chip->disable_votable, USER_VOTER, true, 0);
	vote(chip->disable_votable, SOC_LEVEL_VOTER, true, 0);
	cancel_work(&chip->taper_work);
	cancel_work(&chip->status_change_work);
	wakeup_source_unregister(chip->cp_ws);