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

Commit 29a77faf authored by Jie Cheng's avatar Jie Cheng
Browse files

power: qpnp-linear-charger: Add BMS controlled charging



Allow the BMS to control the charging by writing the STATUS
property of battery power-supply.

To enable this feature, following DT param needs to be defined:
- qcom,bms-controlled-charging: This enables BMS to control the
recharge.

Change-Id: I84471d083c2d101066c483e9a01376f5d2c992a5
Signed-off-by: default avatarJie Cheng <rockiec@codeaurora.org>
parent 6eae9c61
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -97,6 +97,10 @@ Parent node optional properties:
					charger module, it is used to control a
					led which can act as a charger led as well
					as a general notification led.
- qcom,bms-controlled-charging		This property enables BMS to control
					charging. BMS and charger communicates
					with each other via power_supply
					framework.

Sub node required structure:
- A qcom,charger node must be a child of an SPMI node that has specified
+31 −3
Original line number Diff line number Diff line
@@ -320,6 +320,7 @@ struct qpnp_lbc_chip {
	bool				fastchg_on;
	bool				cfg_use_external_charger;
	bool				cfg_chgr_led_support;
	bool				cfg_bms_controlled_charging;
	unsigned int			cfg_warm_bat_chg_ma;
	unsigned int			cfg_cool_bat_chg_ma;
	unsigned int			cfg_safe_voltage_mv;
@@ -1214,7 +1215,8 @@ static int get_prop_capacity(struct qpnp_lbc_chip *chip)
				&& charger_in
				&& !chip->cfg_charging_disabled
				&& chip->cfg_soc_resume_limit
				&& ret.intval <= chip->cfg_soc_resume_limit) {
				&& ret.intval <= chip->cfg_soc_resume_limit
				&& !chip->cfg_bms_controlled_charging) {
			pr_debug("resuming charging at %d%% soc\n",
					ret.intval);
			if (!chip->cfg_disable_vbatdet_based_recharge)
@@ -1489,9 +1491,10 @@ static int qpnp_batt_power_set_property(struct power_supply *psy,

	switch (psp) {
	case POWER_SUPPLY_PROP_STATUS:
		mutex_lock(&chip->chg_enable_lock);

		if (val->intval == POWER_SUPPLY_STATUS_FULL &&
				!chip->cfg_float_charge) {
			mutex_lock(&chip->chg_enable_lock);

			/* Disable charging */
			rc = qpnp_lbc_charger_enable(chip, SOC, 0);
@@ -1518,8 +1521,29 @@ static int qpnp_batt_power_set_property(struct power_supply *psy,
						&chip->irqs[CHG_VBAT_DET_LO]);
			}

			mutex_unlock(&chip->chg_enable_lock);
		}

		if (chip->cfg_bms_controlled_charging) {
			switch (val->intval) {
			case POWER_SUPPLY_STATUS_CHARGING:
				chip->chg_done = false;
				pr_debug("resuming charging by bms\n");
				if (!chip->cfg_disable_vbatdet_based_recharge)
					qpnp_lbc_vbatdet_override(chip,
								OVERRIDE_0);
				qpnp_lbc_charger_enable(chip, SOC, 1);
				break;
			case POWER_SUPPLY_STATUS_DISCHARGING:
				chip->chg_done = false;
				pr_debug("status = DISCHARGING chg_done = %d\n",
						chip->chg_done);
				break;
			default:
				break;
			}
		}

		mutex_unlock(&chip->chg_enable_lock);
		break;
	case POWER_SUPPLY_PROP_COOL_TEMP:
		rc = qpnp_lbc_configure_jeita(chip, psp, val->intval);
@@ -2013,6 +2037,10 @@ static int qpnp_charger_read_dt_props(struct qpnp_lbc_chip *chip)
			of_property_read_bool(chip->spmi->dev.of_node,
					"qcom,chgr-led-support");

	chip->cfg_bms_controlled_charging =
			of_property_read_bool(chip->spmi->dev.of_node,
					"qcom,bms-controlled-charging");

	/* Disable charging when faking battery values */
	if (chip->cfg_use_fake_battery)
		chip->cfg_charging_disabled = true;