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

Commit b3a9d317 authored by Xiaozhe Shi's avatar Xiaozhe Shi
Browse files

power: smb1351: report real fastchg current



Report the real set fast charge current through the power supply
framework in order to allow the primary charge to better optimize
current distributions.

CRs-Fixed: 930588
Change-Id: Ia0bbcfb91482bd47bab01e5fdaf29e5ea55d7b97
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent cca4a347
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -439,6 +439,7 @@ struct smb1351_charger {

	int			charging_disabled_status;
	int			usb_suspended_status;
	int			target_fastchg_current_max_ma;
	int			fastchg_current_max_ma;
	int			workaround_flags;

@@ -636,6 +637,9 @@ static int smb1351_fastchg_current_set(struct smb1351_charger *chip,
		}
		if (i < 0)
			i = 0;
		chip->fastchg_current_max_ma = pre_chg_current[i];
		pr_debug("prechg setting %02x\n", i);

		if (i == 0)
			i = 0x7 << SMB1351_CHG_PRE_SHIFT;
		else if (i == 1)
@@ -643,13 +647,12 @@ static int smb1351_fastchg_current_set(struct smb1351_charger *chip,
		else
			i = (i - 2) << SMB1351_CHG_PRE_SHIFT;

		pr_debug("prechg setting %02x\n", i);

		rc = smb1351_masked_write(chip, CHG_OTH_CURRENT_CTRL_REG,
				PRECHG_CURRENT_MASK, i);
		if (rc)
			pr_err("Couldn't write CHG_OTH_CURRENT_CTRL_REG rc=%d\n",
									rc);

		return smb1351_masked_write(chip, VARIOUS_FUNC_2_REG,
				PRECHG_TO_FASTCHG_BIT, PRECHG_TO_FASTCHG_BIT);
	} else {
@@ -660,6 +663,8 @@ static int smb1351_fastchg_current_set(struct smb1351_charger *chip,
		}
		if (i < 0)
			i = 0;
		chip->fastchg_current_max_ma = fast_chg_current[i];

		i = i << SMB1351_CHG_FAST_SHIFT;
		pr_debug("fastchg limit=%d setting %02x\n",
					chip->fastchg_current_max_ma, i);
@@ -898,7 +903,8 @@ static int smb1351_hw_init(struct smb1351_charger *chip)
		}
	}
	/* set the fast charge current limit */
	rc = smb1351_fastchg_current_set(chip, chip->fastchg_current_max_ma);
	rc = smb1351_fastchg_current_set(chip,
			chip->target_fastchg_current_max_ma);
	if (rc) {
		pr_err("Couldn't set fastchg current rc=%d\n", rc);
		return rc;
@@ -1439,9 +1445,9 @@ static int smb1351_parallel_set_chg_present(struct smb1351_charger *chip,
		}

		/* set fast charging current limit */
		chip->fastchg_current_max_ma = SMB1351_CHG_FAST_MIN_MA;
		chip->target_fastchg_current_max_ma = SMB1351_CHG_FAST_MIN_MA;
		rc = smb1351_fastchg_current_set(chip,
						chip->fastchg_current_max_ma);
					chip->target_fastchg_current_max_ma);
		if (rc) {
			pr_err("Couldn't set fastchg current rc=%d\n", rc);
			return rc;
@@ -1502,9 +1508,10 @@ static int smb1351_parallel_set_property(struct power_supply *psy,
		break;
	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
		if (chip->parallel_charger_present) {
			chip->fastchg_current_max_ma = val->intval / 1000;
			chip->target_fastchg_current_max_ma =
						val->intval / 1000;
			rc = smb1351_fastchg_current_set(chip,
						chip->fastchg_current_max_ma);
					chip->target_fastchg_current_max_ma);
		}
		break;
	case POWER_SUPPLY_PROP_CURRENT_MAX:
@@ -1588,7 +1595,7 @@ static void smb1351_chg_set_appropriate_battery_current(
				struct smb1351_charger *chip)
{
	int rc;
	unsigned int current_max = chip->fastchg_current_max_ma;
	unsigned int current_max = chip->target_fastchg_current_max_ma;

	if (chip->batt_cool)
		current_max = min(current_max, chip->batt_cool_ma);
@@ -2596,9 +2603,9 @@ static int smb1351_parse_dt(struct smb1351_charger *chip)
		chip->bms_psy_name = NULL;

	rc = of_property_read_u32(node, "qcom,fastchg-current-max-ma",
						&chip->fastchg_current_max_ma);
					&chip->target_fastchg_current_max_ma);
	if (rc)
		chip->fastchg_current_max_ma = SMB1351_CHG_FAST_MAX_MA;
		chip->target_fastchg_current_max_ma = SMB1351_CHG_FAST_MAX_MA;

	chip->iterm_disabled = of_property_read_bool(node,
					"qcom,iterm-disabled");