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

Commit 9b2bacf2 authored by Nicholas Troast's avatar Nicholas Troast
Browse files

smb138x-charger: use SW based comparison for connector health



The hardware based threshold comparison requires thermal regulation to
be active. This is a problem for layouts which connect USBIN rather than
MID to the SMB138X since the thermal regulation will throttle the ICL in
the USBIN case.

Read the connector temperature ADC and compare against the thresholds
in software instead of enabling thermal regulation.

Change-Id: I9ecda675947fc6c82a8c8b67d0c9d930365ad02e
Signed-off-by: default avatarNicholas Troast <ntroast@codeaurora.org>
parent ad819206
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -201,6 +201,7 @@ struct smb_iio {
	struct iio_channel	*usbin_i_chan;
	struct iio_channel	*usbin_v_chan;
	struct iio_channel	*batt_i_chan;
	struct iio_channel	*connector_temp_chan;
	struct iio_channel	*connector_temp_thr1_chan;
	struct iio_channel	*connector_temp_thr2_chan;
	struct iio_channel	*connector_temp_thr3_chan;
+52 −1
Original line number Diff line number Diff line
@@ -430,6 +430,57 @@ static int smb138x_init_batt_psy(struct smb138x *chip)
 * PARALLEL PSY REGISTRATION *
 *****************************/

static int smb138x_get_prop_connector_health(struct smb138x *chip)
{
	struct smb_charger *chg = &chip->chg;
	int rc, lb_mdegc, ub_mdegc, rst_mdegc, connector_mdegc;

	if (!chg->iio.connector_temp_chan ||
		PTR_ERR(chg->iio.connector_temp_chan) == -EPROBE_DEFER)
		chg->iio.connector_temp_chan = iio_channel_get(chg->dev,
							"connector_temp");

	if (IS_ERR(chg->iio.connector_temp_chan))
		return POWER_SUPPLY_HEALTH_UNKNOWN;

	rc = iio_read_channel_processed(chg->iio.connector_temp_thr1_chan,
							&lb_mdegc);
	if (rc < 0) {
		pr_err("Couldn't read connector lower bound rc=%d\n", rc);
		return POWER_SUPPLY_HEALTH_UNKNOWN;
	}

	rc = iio_read_channel_processed(chg->iio.connector_temp_thr2_chan,
							&ub_mdegc);
	if (rc < 0) {
		pr_err("Couldn't read connector upper bound rc=%d\n", rc);
		return POWER_SUPPLY_HEALTH_UNKNOWN;
	}

	rc = iio_read_channel_processed(chg->iio.connector_temp_thr3_chan,
							&rst_mdegc);
	if (rc < 0) {
		pr_err("Couldn't read connector reset bound rc=%d\n", rc);
		return POWER_SUPPLY_HEALTH_UNKNOWN;
	}

	rc = iio_read_channel_processed(chg->iio.connector_temp_chan,
							&connector_mdegc);
	if (rc < 0) {
		pr_err("Couldn't read connector temperature rc=%d\n", rc);
		return POWER_SUPPLY_HEALTH_UNKNOWN;
	}

	if (connector_mdegc < lb_mdegc)
		return POWER_SUPPLY_HEALTH_COOL;
	else if (connector_mdegc < ub_mdegc)
		return POWER_SUPPLY_HEALTH_WARM;
	else if (connector_mdegc < rst_mdegc)
		return POWER_SUPPLY_HEALTH_HOT;

	return POWER_SUPPLY_HEALTH_OVERHEAT;
}

static enum power_supply_property smb138x_parallel_props[] = {
	POWER_SUPPLY_PROP_CHARGE_TYPE,
	POWER_SUPPLY_PROP_CHARGING_ENABLED,
@@ -496,7 +547,7 @@ static int smb138x_parallel_get_prop(struct power_supply *psy,
		val->intval = POWER_SUPPLY_PARALLEL_MID_MID;
		break;
	case POWER_SUPPLY_PROP_CONNECTOR_HEALTH:
		rc = smblib_get_prop_die_health(chg, val);
		val->intval = smb138x_get_prop_connector_health(chip);
		break;
	default:
		pr_err("parallel power supply get prop %d not supported\n",