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

Commit 53079cc9 authored by Umang Agrawal's avatar Umang Agrawal Committed by Shilpa Suresh
Browse files

power: qcom: smb2: Add toggle stat pin logic to toggle_stat property



The SMB_EN pin of SMB1390 is connected to the STAT pin of the primary
charger. Hence, to prevent ILIM IRQ failure, toggle the stat pin to
reset SMB1390 using the toggle_stat property of the main power supply.

CRs-Fixed: 2200340.

Change-Id: I687d41ec9ab415d5403dc231a204b2c08bbba48a
Signed-off-by: default avatarUmang Agrawal <uagrawal@codeaurora.org>
parent bd5ffdac
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -711,6 +711,7 @@ static enum power_supply_property smb2_usb_main_props[] = {
	POWER_SUPPLY_PROP_INPUT_VOLTAGE_SETTLED,
	POWER_SUPPLY_PROP_FCC_DELTA,
	POWER_SUPPLY_PROP_CURRENT_MAX,
	POWER_SUPPLY_PROP_TOGGLE_STAT,
	/*
	 * TODO move the TEMP and TEMP_MAX properties here,
	 * and update the thermal balancer to look here
@@ -748,6 +749,9 @@ static int smb2_usb_main_get_prop(struct power_supply *psy,
	case POWER_SUPPLY_PROP_CURRENT_MAX:
		rc = smblib_get_icl_current(chg, &val->intval);
		break;
	case POWER_SUPPLY_PROP_TOGGLE_STAT:
		val->intval = 0;
		break;
	default:
		pr_debug("get prop %d is not supported in usb-main\n", psp);
		rc = -EINVAL;
@@ -778,6 +782,9 @@ static int smb2_usb_main_set_prop(struct power_supply *psy,
	case POWER_SUPPLY_PROP_CURRENT_MAX:
		rc = smblib_set_icl_current(chg, val->intval);
		break;
	case POWER_SUPPLY_PROP_TOGGLE_STAT:
		rc = smblib_toggle_stat(chg, val->intval);
		break;
	default:
		pr_err("set prop %d is not supported\n", psp);
		rc = -EINVAL;
@@ -787,6 +794,23 @@ static int smb2_usb_main_set_prop(struct power_supply *psy,
	return rc;
}

static int smb2_usb_main_prop_is_writeable(struct power_supply *psy,
				enum power_supply_property psp)
{
	int rc;

	switch (psp) {
	case POWER_SUPPLY_PROP_TOGGLE_STAT:
		rc = 1;
		break;
	default:
		rc = 0;
		break;
	}

	return rc;
}

static const struct power_supply_desc usb_main_psy_desc = {
	.name		= "main",
	.type		= POWER_SUPPLY_TYPE_MAIN,
@@ -794,6 +818,7 @@ static const struct power_supply_desc usb_main_psy_desc = {
	.num_properties	= ARRAY_SIZE(smb2_usb_main_props),
	.get_property	= smb2_usb_main_get_prop,
	.set_property	= smb2_usb_main_set_prop,
	.property_is_writeable = smb2_usb_main_prop_is_writeable,
};

static int smb2_init_usb_main_psy(struct smb2 *chip)
+42 −0
Original line number Diff line number Diff line
@@ -1106,6 +1106,48 @@ static int __smblib_set_prop_typec_power_role(struct smb_charger *chg,
	return rc;
}

int smblib_toggle_stat(struct smb_charger *chg, int reset)
{
	int rc = 0;

	if (reset) {
		rc = smblib_masked_write(chg, STAT_CFG_REG,
			STAT_SW_OVERRIDE_CFG_BIT | STAT_SW_OVERRIDE_VALUE_BIT,
			STAT_SW_OVERRIDE_CFG_BIT | 0);
		if (rc < 0) {
			smblib_err(chg,
				"Couldn't pull STAT pin low rc=%d\n", rc);
			return rc;
		}

		/*
		 * A minimum of 20us delay is expected before switching on STAT
		 * pin
		 */
		usleep_range(20, 30);

		rc = smblib_masked_write(chg, STAT_CFG_REG,
			STAT_SW_OVERRIDE_CFG_BIT | STAT_SW_OVERRIDE_VALUE_BIT,
			STAT_SW_OVERRIDE_CFG_BIT | STAT_SW_OVERRIDE_VALUE_BIT);
		if (rc < 0) {
			smblib_err(chg,
				"Couldn't pull STAT pin high rc=%d\n", rc);
			return rc;
		}

		rc = smblib_masked_write(chg, STAT_CFG_REG,
			STAT_SW_OVERRIDE_CFG_BIT | STAT_SW_OVERRIDE_VALUE_BIT,
			0);
		if (rc < 0) {
			smblib_err(chg,
				"Couldn't set hardware control rc=%d\n", rc);
			return rc;
		}
	}

	return rc;
}

/*********************
 * VOTABLE CALLBACKS *
 *********************/
+1 −0
Original line number Diff line number Diff line
@@ -542,6 +542,7 @@ int smblib_set_prop_pr_swap_in_progress(struct smb_charger *chg,
				const union power_supply_propval *val);
int smblib_stat_sw_override_cfg(struct smb_charger *chg, bool override);
void smblib_usb_typec_change(struct smb_charger *chg);
int smblib_toggle_stat(struct smb_charger *chg, int reset);

int smblib_init(struct smb_charger *chg);
int smblib_deinit(struct smb_charger *chg);