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

Commit f3da875d authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "power: smb358-charger: Add BMS controlled termination/recharge"

parents ab5f68db 569b1ace
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -33,6 +33,11 @@ Optional Properties:
- qcom,charger-disabled		This is a bool property which disables charging.
- qcom,using-pmic-therm		This property indicates thermal pin connected to pmic or smb.
- qcom,vcc-i2c-supply           Power source required to power up i2c bus.
- qcom,bms-controlled-charging	This property indicates integrating with VMBMS, charger
				driver and BMS communicates with each other via power_supply
				framework. Property "qcom,iterm-disabled" also needs defined
				if using this feature to make sure that the charger doesn't
				terminate charging on its own.
- qcom,iterm-ma			Specifies the termination current to indicate end-of-charge.
				Possible values in mA - 30, 40, 60, 80, 100, 125, 150, 200.
- qcom,iterm-disabled		Disables the termination current feature. This is a bool
@@ -64,6 +69,7 @@ Example:
			qcom,float-voltage-mv = <4350>;
			qcom,disable-apsd;
			qcom,chg-inhibit-disabled;
			qcom,bms-controlled-charging;
			qcom,fastchg-current-max-ma = <1500>;
			qcom,bms-psy-name = "bms";
			qcom,chg-vadc = <&pm8226_vadc>;
+59 −0
Original line number Diff line number Diff line
@@ -174,6 +174,7 @@ enum {
	USER	= BIT(0),
	THERMAL = BIT(1),
	CURRENT = BIT(2),
	SOC	= BIT(3),
};

struct smb358_regulator {
@@ -202,6 +203,7 @@ struct smb358_charger {
	const char		*bms_psy_name;
	bool			resume_completed;
	bool			irq_waiting;
	bool			bms_controlled_charging;
	struct mutex		read_write_lock;
	struct mutex		path_suspend_lock;
	struct mutex		irq_complete;
@@ -1094,10 +1096,49 @@ static int smb358_battery_set_property(struct power_supply *psy,
					enum power_supply_property prop,
					const union power_supply_propval *val)
{
	int rc;
	struct smb358_charger *chip = container_of(psy,
				struct smb358_charger, batt_psy);

	switch (prop) {
	case POWER_SUPPLY_PROP_STATUS:
		if (!chip->bms_controlled_charging)
			return -EINVAL;
		switch (val->intval) {
		case POWER_SUPPLY_STATUS_FULL:
			rc = smb358_charging_disable(chip, SOC, true);
			if (rc < 0) {
				dev_err(chip->dev,
					"Couldn't set charging disable rc = %d\n",
					rc);
			} else {
				chip->batt_full = true;
				dev_dbg(chip->dev, "status = FULL, batt_full = %d\n",
							chip->batt_full);
			}
			break;
		case POWER_SUPPLY_STATUS_DISCHARGING:
			chip->batt_full = false;
			power_supply_changed(&chip->batt_psy);
			dev_dbg(chip->dev, "status = DISCHARGING, batt_full = %d\n",
							chip->batt_full);
			break;
		case POWER_SUPPLY_STATUS_CHARGING:
			rc = smb358_charging_disable(chip, SOC, false);
			if (rc < 0) {
				dev_err(chip->dev,
				"Couldn't set charging disable rc = %d\n",
								rc);
			} else {
				chip->batt_full = false;
				dev_dbg(chip->dev, "status = CHARGING, batt_full = %d\n",
							chip->batt_full);
			}
			break;
		default:
			return -EINVAL;
		}
		break;
	case POWER_SUPPLY_PROP_CHARGING_ENABLED:
		smb358_charging_disable(chip, USER, !val->intval);
		smb358_path_suspend(chip, USER, !val->intval);
@@ -1224,6 +1265,7 @@ static int apsd_complete(struct smb358_charger *chip, u8 status)

static int chg_uv(struct smb358_charger *chip, u8 status)
{
	int rc;
	/* use this to detect USB insertion only if !apsd */
	if (chip->disable_apsd && status == 0) {
		chip->chg_present = true;
@@ -1232,6 +1274,17 @@ static int chg_uv(struct smb358_charger *chip, u8 status)
		power_supply_set_supply_type(chip->usb_psy,
						POWER_SUPPLY_TYPE_USB);
		power_supply_set_present(chip->usb_psy, chip->chg_present);

		if (chip->bms_controlled_charging)
			/*
			* Disable SOC based USB suspend to enable charging on
			* USB insertion.
			*/
			rc = smb358_charging_disable(chip, SOC, false);
			if (rc < 0)
				dev_err(chip->dev,
					"Couldn't disable usb suspend rc = %d\n",
									rc);
	}

	if (status != 0) {
@@ -1263,9 +1316,13 @@ static int chg_ov(struct smb358_charger *chip, u8 status)
	return 0;
}

#define STATUS_FAST_CHARGING BIT(6)
static int fast_chg(struct smb358_charger *chip, u8 status)
{
	dev_dbg(chip->dev, "%s\n", __func__);

	if (status & STATUS_FAST_CHARGING)
		chip->batt_full = false;
	return 0;
}

@@ -1927,6 +1984,8 @@ static int smb_parse_dt(struct smb358_charger *chip)

	chip->using_pmic_therm = of_property_read_bool(node,
						"qcom,using-pmic-therm");
	chip->bms_controlled_charging = of_property_read_bool(node,
						"qcom,bms-controlled-charging");

	rc = of_property_read_string(node, "qcom,bms-psy-name",
						&chip->bms_psy_name);