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

Commit e148e353 authored by Guru Das Srinagesh's avatar Guru Das Srinagesh
Browse files

power: smb5: Enable updating of RECHARGE_SOC PSY property



Currently, reading the POWER_SUPPLY_PROP_RECHARGE_SOC property returns
a static, cached value initially set to the threshold value specified in
the device tree. Update this cached value whenever the threshold value
is successfully written to.

Also, move the setting of the threshold value to a separate function.

CRs-Fixed: 2249337
Change-Id: I2a476f59cde21540ee10d0623724105df7933b14
Signed-off-by: default avatarGuru Das Srinagesh <gurus@codeaurora.org>
parent 9ee89464
Loading
Loading
Loading
Loading
+8 −3
Original line number Original line Diff line number Diff line
@@ -1225,6 +1225,9 @@ static int smb5_batt_set_prop(struct power_supply *psy,
		chg->die_health = val->intval;
		chg->die_health = val->intval;
		power_supply_changed(chg->batt_psy);
		power_supply_changed(chg->batt_psy);
		break;
		break;
	case POWER_SUPPLY_PROP_RECHARGE_SOC:
		rc = smblib_set_prop_rechg_soc_thresh(chg, val);
		break;
	default:
	default:
		rc = -EINVAL;
		rc = -EINVAL;
	}
	}
@@ -1436,6 +1439,7 @@ static int smb5_init_hw(struct smb5 *chip)
	struct smb_charger *chg = &chip->chg;
	struct smb_charger *chg = &chip->chg;
	int rc, type = 0;
	int rc, type = 0;
	u8 val = 0;
	u8 val = 0;
	union power_supply_propval pval;


	if (chip->dt.no_battery)
	if (chip->dt.no_battery)
		chg->fake_capacity = 50;
		chg->fake_capacity = 50;
@@ -1715,13 +1719,14 @@ static int smb5_init_hw(struct smb5 *chip)


	/* program the auto-recharge threshold */
	/* program the auto-recharge threshold */
	if (chip->dt.auto_recharge_soc != -EINVAL) {
	if (chip->dt.auto_recharge_soc != -EINVAL) {
		rc = smblib_write(chg, CHARGE_RCHG_SOC_THRESHOLD_CFG_REG,
		pval.intval = chip->dt.auto_recharge_soc;
				(chip->dt.auto_recharge_soc * 255) / 100);
		rc = smblib_set_prop_rechg_soc_thresh(chg, &pval);
		if (rc < 0) {
		if (rc < 0) {
			dev_err(chg->dev, "Couldn't configure CHG_RCHG_SOC_REG rc=%d\n",
			dev_err(chg->dev, "Couldn't configure CHG_RCHG_SOC_REG rc=%d\n",
					rc);
					rc);
			return rc;
			return rc;
		}
		}

		/* Program the sample count for SOC based recharge to 1 */
		/* Program the sample count for SOC based recharge to 1 */
		rc = smblib_masked_write(chg, CHGR_NO_SAMPLE_TERM_RCHG_CFG_REG,
		rc = smblib_masked_write(chg, CHGR_NO_SAMPLE_TERM_RCHG_CFG_REG,
						NO_OF_SAMPLE_FOR_RCHG, 0);
						NO_OF_SAMPLE_FOR_RCHG, 0);
+19 −0
Original line number Original line Diff line number Diff line
@@ -1617,6 +1617,25 @@ int smblib_set_prop_input_current_limited(struct smb_charger *chg,
	return 0;
	return 0;
}
}


int smblib_set_prop_rechg_soc_thresh(struct smb_charger *chg,
				const union power_supply_propval *val)
{
	int rc;
	u8 new_thr = DIV_ROUND_CLOSEST(val->intval * 255, 100);

	rc = smblib_write(chg, CHARGE_RCHG_SOC_THRESHOLD_CFG_REG,
			new_thr);
	if (rc < 0) {
		smblib_err(chg, "Couldn't write to RCHG_SOC_THRESHOLD_CFG_REG rc=%d\n",
				rc);
		return rc;
	}

	chg->auto_recharge_soc = val->intval;

	return rc;
}

int smblib_rerun_aicl(struct smb_charger *chg)
int smblib_rerun_aicl(struct smb_charger *chg)
{
{
	int rc;
	int rc;
+2 −0
Original line number Original line Diff line number Diff line
@@ -541,6 +541,8 @@ int smblib_set_prop_pd_in_hard_reset(struct smb_charger *chg,
				const union power_supply_propval *val);
				const union power_supply_propval *val);
int smblib_set_prop_ship_mode(struct smb_charger *chg,
int smblib_set_prop_ship_mode(struct smb_charger *chg,
				const union power_supply_propval *val);
				const union power_supply_propval *val);
int smblib_set_prop_rechg_soc_thresh(struct smb_charger *chg,
				const union power_supply_propval *val);
void smblib_suspend_on_debug_battery(struct smb_charger *chg);
void smblib_suspend_on_debug_battery(struct smb_charger *chg);
int smblib_rerun_apsd_if_required(struct smb_charger *chg);
int smblib_rerun_apsd_if_required(struct smb_charger *chg);
int smblib_get_prop_fcc_delta(struct smb_charger *chg,
int smblib_get_prop_fcc_delta(struct smb_charger *chg,