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

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

Merge "smb138x-charger: use SW based comparison for connector health"

parents a49e87ee 9b2bacf2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -203,6 +203,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_PL_USBMID_USBMID;
		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",