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

Commit eb182d17 authored by qctecmdr Service's avatar qctecmdr Service Committed by Gerrit - the friendly Code Review server
Browse files

Merge "power_supply: Add HVDCP_OPTI_ALLOWED property"

parents 4b106542 93a13954
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -367,6 +367,7 @@ static struct device_attribute power_supply_attrs[] = {
	POWER_SUPPLY_ATTR(batt_profile_version),
	POWER_SUPPLY_ATTR(batt_full_current),
	POWER_SUPPLY_ATTR(recharge_soc),
	POWER_SUPPLY_ATTR(hvdcp_opti_allowed),
	/* Local extensions of type int64_t */
	POWER_SUPPLY_ATTR(charge_counter_ext),
	/* Properties of type `const char *' */
+20 −2
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ struct pl_data {
	int			charge_type;
	int			total_settled_ua;
	int			pl_settled_ua;
	u32			wa_flags;
	struct class		qcom_batt_class;
	struct wakeup_source	*pl_ws;
	struct notifier_block	nb;
@@ -81,6 +82,10 @@ enum print_reason {
	PR_PARALLEL	= BIT(0),
};

enum {
	AICL_RERUN_WA_BIT	= BIT(0),
};

static int debug_mask;
module_param_named(debug_mask, debug_mask, int, 0600);

@@ -539,7 +544,7 @@ static int usb_icl_vote_callback(struct votable *votable, void *data,
	if (icl_ua > pval.intval)
		rerun_aicl = true;

	if (rerun_aicl) {
	if (rerun_aicl && (chip->wa_flags & AICL_RERUN_WA_BIT)) {
		/* set a lower ICL */
		pval.intval = max(pval.intval - ICL_STEP_UA, ICL_STEP_UA);
		power_supply_set_property(chip->main_psy,
@@ -1015,8 +1020,20 @@ static int pl_determine_initial_status(struct pl_data *chip)
	return 0;
}

static void pl_config_init(struct pl_data *chip, int smb_version)
{
	switch (smb_version) {
	case PMI8998_SUBTYPE:
	case PM660_SUBTYPE:
		chip->wa_flags = AICL_RERUN_WA_BIT;
		break;
	default:
		break;
	}
}

#define DEFAULT_RESTRICTED_CURRENT_UA	1000000
int qcom_batt_init(void)
int qcom_batt_init(int smb_version)
{
	struct pl_data *chip;
	int rc = 0;
@@ -1031,6 +1048,7 @@ int qcom_batt_init(void)
	if (!chip)
		return -ENOMEM;
	chip->slave_pct = 50;
	pl_config_init(chip, smb_version);
	chip->restricted_current = DEFAULT_RESTRICTED_CURRENT_UA;

	chip->pl_ws = wakeup_source_register("qcom-battery");
+1 −1
Original line number Diff line number Diff line
@@ -12,6 +12,6 @@

#ifndef __BATTERY_H
#define __BATTERY_H
int qcom_batt_init(void);
int qcom_batt_init(int smb_version);
void qcom_batt_deinit(void);
#endif /* __BATTERY_H */
+1 −1
Original line number Diff line number Diff line
@@ -5047,7 +5047,7 @@ int smblib_init(struct smb_charger *chg)

	switch (chg->mode) {
	case PARALLEL_MASTER:
		rc = qcom_batt_init();
		rc = qcom_batt_init(chg->smb_version);
		if (rc < 0) {
			smblib_err(chg, "Couldn't init qcom_batt_init rc=%d\n",
				rc);
+78 −14
Original line number Diff line number Diff line
@@ -700,6 +700,13 @@ static void smblib_uusb_removal(struct smb_charger *chg)
	chg->pulse_cnt = 0;
	chg->uusb_apsd_rerun_done = false;

	/* write back the default FLOAT charger configuration */
	rc = smblib_masked_write(chg, USBIN_OPTIONS_2_CFG_REG,
				(u8)FLOAT_OPTIONS_MASK, chg->float_cfg);
	if (rc < 0)
		smblib_err(chg, "Couldn't write float charger options rc=%d\n",
			rc);

	/* clear USB ICL vote for USB_PSY_VOTER */
	rc = vote(chg->usb_icl_votable, USB_PSY_VOTER, false, 0);
	if (rc < 0)
@@ -891,6 +898,9 @@ int smblib_set_icl_current(struct smb_charger *chg, int icl_ua)
		goto out;
	}

	/* Re-run AICL */
	if (chg->real_charger_type != POWER_SUPPLY_TYPE_USB)
		rc = smblib_rerun_aicl(chg);
out:
	return rc;
}
@@ -2142,16 +2152,40 @@ static int smblib_handle_usb_current(struct smb_charger *chg,

	if (chg->real_charger_type == POWER_SUPPLY_TYPE_USB_FLOAT) {
		if (usb_current == -ETIMEDOUT) {
			if ((chg->float_cfg & FLOAT_OPTIONS_MASK)
						== FORCE_FLOAT_SDP_CFG_BIT) {
				/*
			 * Valid FLOAT charger, report the current based
			 * of Rp
				 * Confiugure USB500 mode if Float charger is
				 * configured for SDP mode.
				 */
				rc = set_sdp_current(chg, USBIN_500MA);
				if (rc < 0)
					smblib_err(chg,
						"Couldn't set SDP ICL rc=%d\n",
						rc);

				return rc;
			}

			if (chg->connector_type ==
					POWER_SUPPLY_CONNECTOR_TYPEC) {
				/*
				 * Valid FLOAT charger, report the current
				 * based of Rp.
				 */
				typec_mode = smblib_get_prop_typec_mode(chg);
			rp_ua = get_rp_based_dcp_current(chg, typec_mode);
			rc = vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER,
								true, rp_ua);
				rp_ua = get_rp_based_dcp_current(chg,
								typec_mode);
				rc = vote(chg->usb_icl_votable,
						SW_ICL_MAX_VOTER, true, rp_ua);
				if (rc < 0)
					return rc;
			} else {
				rc = vote(chg->usb_icl_votable,
					SW_ICL_MAX_VOTER, true, DCP_CURRENT_UA);
				if (rc < 0)
					return rc;
			}
		} else {
			/*
			 * FLOAT charger detected as SDP by USB driver,
@@ -2171,11 +2205,22 @@ static int smblib_handle_usb_current(struct smb_charger *chg,
	} else {
		rc = vote(chg->usb_icl_votable, USB_PSY_VOTER,
					true, usb_current);
		if (rc < 0) {
			pr_err("Couldn't vote ICL USB_PSY_VOTER rc=%d\n", rc);
			return rc;
		}

		rc = vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, false, 0);
		if (rc < 0) {
			pr_err("Couldn't remove SW_ICL_MAX vote rc=%d\n", rc);
			return rc;
		}

	}

	return 0;
}

int smblib_set_prop_sdp_current_max(struct smb_charger *chg,
				    const union power_supply_propval *val)
{
@@ -2884,9 +2929,13 @@ static void update_sw_icl_max(struct smb_charger *chg, int pst)
	if (chg->pd_active)
		return;

	/* HVDCP 2/3, handled separately */
	/*
	 * HVDCP 2/3, handled separately
	 * For UNKNOWN(input not present) return without updating ICL
	 */
	if (pst == POWER_SUPPLY_TYPE_USB_HVDCP
			|| pst == POWER_SUPPLY_TYPE_USB_HVDCP_3)
			|| pst == POWER_SUPPLY_TYPE_USB_HVDCP_3
			|| pst == POWER_SUPPLY_TYPE_UNKNOWN)
		return;

	/* TypeC rp med or high, use rp value */
@@ -2948,12 +2997,12 @@ static void smblib_handle_apsd_done(struct smb_charger *chg, bool rising)
	switch (apsd_result->bit) {
	case SDP_CHARGER_BIT:
	case CDP_CHARGER_BIT:
	case FLOAT_CHARGER_BIT:
		if ((chg->connector_type == POWER_SUPPLY_CONNECTOR_MICRO_USB)
				|| chg->use_extcon)
			smblib_notify_device_mode(chg, true);
		break;
	case OCP_CHARGER_BIT:
	case FLOAT_CHARGER_BIT:
	case DCP_CHARGER_BIT:
		break;
	default:
@@ -3163,6 +3212,21 @@ static void smblib_handle_rp_change(struct smb_charger *chg, int typec_mode)
{
	const struct apsd_result *apsd = smblib_get_apsd_result(chg);

	/*
	 * We want the ICL vote @ 100mA for a FLOAT charger
	 * until the detection by the USB stack is complete.
	 * Ignore the Rp changes unless there is a
	 * pre-existing valid vote or FLOAT is configured for
	 * SDP current.
	 */
	if (apsd->pst == POWER_SUPPLY_TYPE_USB_FLOAT) {
		if (get_client_vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER)
					<= USBIN_100MA
			|| (chg->float_cfg & FLOAT_OPTIONS_MASK)
					== FORCE_FLOAT_SDP_CFG_BIT)
			return;
	}

	update_sw_icl_max(chg, apsd->pst);

	smblib_dbg(chg, PR_MISC, "CC change old_mode=%d new_mode=%d\n",
@@ -3765,7 +3829,7 @@ int smblib_init(struct smb_charger *chg)

	switch (chg->mode) {
	case PARALLEL_MASTER:
		rc = qcom_batt_init();
		rc = qcom_batt_init(chg->smb_version);
		if (rc < 0) {
			smblib_err(chg, "Couldn't init qcom_batt_init rc=%d\n",
				rc);
Loading