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

Commit 24d8f022 authored by Xiaozhe Shi's avatar Xiaozhe Shi Committed by Abhijeet Dharmapurikar
Browse files

power: qpnp-smbcharger: disable charging for unknown batteries



Currently, we disable the charging only when the battery is not
recognized. Also if a battery happens to match the default
OTP profile, then the charging should be disabled. In addition,
charging is disabled by using USB_SUSPEND_SRC_BIT which is
not desirable as it limits the inflow current.

Disable the charging by using the charge_en bit which will still
allow the USB current in and block it going into the battery.

CRs-Fixed: 810866
Change-Id: I55549938f514780701a10e3239b6172c9dbd1108
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent a55f0ba3
Loading
Loading
Loading
Loading
+25 −31
Original line number Diff line number Diff line
@@ -116,7 +116,6 @@ struct smbchg_chip {
	bool				bmd_algo_disabled;
	bool				soft_vfloat_comp_disabled;
	bool				chg_enabled;
	bool				battery_unknown;
	bool				charge_unknown_battery;
	bool				chg_inhibit_en;
	bool				chg_inhibit_source_fg;
@@ -1157,7 +1156,7 @@ enum battchg_enable_reason {
	/* userspace has disabled battery charging */
	REASON_BATTCHG_USER		= BIT(0),
	/* battery charging disabled while loading battery profiles */
	REASON_BATTCHG_LOADING_PROFILE	= BIT(1),
	REASON_BATTCHG_UNKNOWN_BATTERY	= BIT(1),
};

static struct power_supply *get_parallel_psy(struct smbchg_chip *chip)
@@ -2889,24 +2888,6 @@ static int smbchg_dc_is_writeable(struct power_supply *psy,
	return rc;
}

#define USBIN_SUSPEND_SRC_BIT		BIT(6)
static void smbchg_unknown_battery_en(struct smbchg_chip *chip, bool en)
{
	int rc;

	if (en == chip->battery_unknown || chip->charge_unknown_battery)
		return;

	chip->battery_unknown = en;
	rc = smbchg_sec_masked_write(chip,
		chip->usb_chgpth_base + CHGPTH_CFG,
		USBIN_SUSPEND_SRC_BIT, en ? 0 : USBIN_SUSPEND_SRC_BIT);
	if (rc < 0) {
		dev_err(chip->dev, "Couldn't set usb_chgpth cfg rc=%d\n", rc);
		return;
	}
}

static void smbchg_vfloat_adjust_check(struct smbchg_chip *chip)
{
	if (!chip->use_vfloat_adjustments)
@@ -3217,14 +3198,32 @@ static int smbchg_config_chg_battery_type(struct smbchg_chip *chip)
	return rc;
}

static void check_battery_type(struct smbchg_chip *chip)
{
	union power_supply_propval prop = {0,};
	bool en;
	bool unused;

	if (!chip->bms_psy && chip->bms_psy_name)
		chip->bms_psy =
			power_supply_get_by_name((char *)chip->bms_psy_name);
	if (chip->bms_psy) {
		chip->bms_psy->get_property(chip->bms_psy,
				POWER_SUPPLY_PROP_BATTERY_TYPE, &prop);
		en = (strcmp(prop.strval, UNKNOWN_BATT_TYPE) != 0
				&& !chip->charge_unknown_battery)
			|| strcmp(prop.strval, LOADING_BATT_TYPE) != 0;
		smbchg_battchg_en(chip, en, REASON_BATTCHG_UNKNOWN_BATTERY,
				&unused);
	}
}

static void smbchg_external_power_changed(struct power_supply *psy)
{
	struct smbchg_chip *chip = container_of(psy,
				struct smbchg_chip, batt_psy);
	union power_supply_propval prop = {0,};
	int rc, current_limit = 0, soc;
	bool en;
	bool unused;

	if (chip->bms_psy_name)
		chip->bms_psy =
@@ -3232,13 +3231,7 @@ static void smbchg_external_power_changed(struct power_supply *psy)

	smbchg_aicl_deglitch_wa_check(chip);
	if (chip->bms_psy) {
		chip->bms_psy->get_property(chip->bms_psy,
				POWER_SUPPLY_PROP_BATTERY_TYPE, &prop);
		en = strcmp(prop.strval, UNKNOWN_BATT_TYPE) != 0;
		smbchg_unknown_battery_en(chip, en);
		en = strcmp(prop.strval, LOADING_BATT_TYPE) != 0;
		smbchg_battchg_en(chip, en, REASON_BATTCHG_LOADING_PROFILE,
				&unused);
		check_battery_type(chip);
		soc = get_prop_batt_capacity(chip);
		if (chip->previous_soc != soc) {
			chip->previous_soc = soc;
@@ -4934,13 +4927,14 @@ static int smbchg_hw_init(struct smbchg_chip *chip)
	 * polarity on the usb current
	 */
	rc = smbchg_sec_masked_write(chip, chip->usb_chgpth_base + CHGPTH_CFG,
		USBIN_SUSPEND_SRC_BIT | USB51_COMMAND_POL | USB51AC_CTRL,
		(chip->charge_unknown_battery ? 0 : USBIN_SUSPEND_SRC_BIT));
		USB51_COMMAND_POL | USB51AC_CTRL, 0);
	if (rc < 0) {
		dev_err(chip->dev, "Couldn't set usb_chgpth cfg rc=%d\n", rc);
		return rc;
	}

	check_battery_type(chip);

	/* set the float voltage */
	if (chip->vfloat_mv != -EINVAL) {
		rc = smbchg_float_voltage_set(chip, chip->vfloat_mv);