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

Commit 2d5771c4 authored by Xiaozhe Shi's avatar Xiaozhe Shi
Browse files

power: smb1351-charger: report icl status in parallel mode



Report the input current limited status via the power supply in parallel
mode in order to better optimize for HVDCP usecases.

CRs-Fixed: 930588
Change-Id: I9d802227ebd0289b796477020a51826717fc908f
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent 2449babe
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -1356,6 +1356,7 @@ static enum power_supply_property smb1351_parallel_properties[] = {
	POWER_SUPPLY_PROP_PRESENT,
	POWER_SUPPLY_PROP_CURRENT_MAX,
	POWER_SUPPLY_PROP_VOLTAGE_MAX,
	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMITED,
	POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
};

@@ -1486,6 +1487,20 @@ static int smb1351_get_closest_usb_setpoint(int val)
		return i + 1;
}

static bool smb1351_is_input_current_limited(struct smb1351_charger *chip)
{
	int rc;
	u8 reg;

	rc = smb1351_read_reg(chip, IRQ_H_REG, &reg);
	if (rc) {
		pr_err("Failed to read IRQ_H_REG for ICL status: %d\n", rc);
		return false;
	}

	return !!(reg & IRQ_IC_LIMIT_STATUS_BIT);
}

static int smb1351_parallel_set_property(struct power_supply *psy,
				       enum power_supply_property prop,
				       const union power_supply_propval *val)
@@ -1585,6 +1600,13 @@ static int smb1351_parallel_get_property(struct power_supply *psy,
		else
			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
		break;
	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMITED:
		if (chip->parallel_charger_present)
			val->intval =
				smb1351_is_input_current_limited(chip) ? 1 : 0;
		else
			val->intval = 0;
		break;
	default:
		return -EINVAL;
	}