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

Commit 746b23d0 authored by Ashish Chavan's avatar Ashish Chavan Committed by Gerrit - the friendly Code Review server
Browse files

power: battery: Add support to enable PPS to work in CV mode



Add support to enable PPS to work in CV mode by allowing ICL
to be split for PPS adapter where the maximum ILIM  for it is
been limited to min(qc4_icl_ua, pd_current_max).

Change-Id: Iac3b4a4964783eb7f60a93e2237058f687e3de09
Signed-off-by: default avatarAshish Chavan <ashichav@codeaurora.org>
Signed-off-by: default avatarAnirudh Ghayal <aghayal@codeaurora.org>
parent 2dbb68e0
Loading
Loading
Loading
Loading
+42 −14
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@
#define FCC_STEPPER_VOTER		"FCC_STEPPER_VOTER"
#define FCC_VOTER			"FCC_VOTER"
#define MAIN_FCC_VOTER			"MAIN_FCC_VOTER"
#define PD_VOTER			"PD_VOTER"

struct pl_data {
	struct device		*dev;
@@ -292,30 +293,57 @@ static int cp_get_parallel_mode(struct pl_data *chip, int mode)
	return val;
}

static int get_hvdcp3_icl_limit(struct pl_data *chip)
static int get_adapter_icl_based_ilim(struct pl_data *chip)
{
	int main_icl, target_icl = -EINVAL;
	int main_icl = -EINVAL, adapter_icl = -EINVAL, final_icl = -EINVAL;
	int rc = -EINVAL, pval = 0;

	rc = chip->chg_param->iio_read(chip->dev,
			PSY_IIO_PD_ACTIVE, &pval);
	if (rc < 0)
		pr_err("Failed to read PD_ACTIVE status rc=%d\n",
				rc);
	/* Check for QC 3, 3.5 and PPS adapters, return if its none of them */
	if (chip->charger_type != QTI_POWER_SUPPLY_TYPE_USB_HVDCP_3 &&
		chip->charger_type != QTI_POWER_SUPPLY_TYPE_USB_HVDCP_3P5)
		return target_icl;
		chip->charger_type != QTI_POWER_SUPPLY_TYPE_USB_HVDCP_3P5 &&
		pval != QTI_POWER_SUPPLY_PD_PPS_ACTIVE)
		return final_icl;

	/*
	 * For HVDCP3/HVDCP_3P5 adapters, limit max. ILIM as:
	 * HVDCP3_ICL: Maximum ICL of HVDCP3 adapter(from DT
	 * configuration).
	 *
	 * For PPS adapters, limit max. ILIM to
	 * MIN(qc4_max_icl, PD_CURRENT_MAX)
	 */
	if (pval == QTI_POWER_SUPPLY_PD_PPS_ACTIVE) {
		adapter_icl = min_t(int, chip->chg_param->qc4_max_icl_ua,
				get_client_vote_locked(chip->usb_icl_votable,
				PD_VOTER));
		if (adapter_icl <= 0)
			adapter_icl = chip->chg_param->qc4_max_icl_ua;
	} else {
		adapter_icl = chip->chg_param->hvdcp3_max_icl_ua;
	}

	/*
	 * For HVDCP3 adapters, limit max. ILIM as follows:
	 * HVDCP3_ICL: Maximum ICL of HVDCP3 adapter(from DT configuration)
	 * For Parallel input configurations:
	 * VBUS: target_icl = HVDCP3_ICL - main_ICL
	 * VMID: target_icl = HVDCP3_ICL
	 * VBUS: final_icl = adapter_icl - main_ICL
	 * VMID: final_icl = adapter_icl
	 */
	target_icl = chip->chg_param->hvdcp3_max_icl_ua;
	final_icl = adapter_icl;
	if (cp_get_parallel_mode(chip, PARALLEL_INPUT_MODE)
					== QTI_POWER_SUPPLY_PL_USBIN_USBIN) {
		main_icl = get_effective_result_locked(chip->usb_icl_votable);
		if ((main_icl >= 0) && (main_icl < target_icl))
			target_icl -= main_icl;
		if ((main_icl >= 0) && (main_icl < adapter_icl))
			final_icl = adapter_icl - main_icl;
	}

	return target_icl;
	pr_debug("charger_type=%d final_icl=%d adapter_icl=%d main_icl=%d\n",
		chip->charger_type, final_icl, adapter_icl, main_icl);

	return final_icl;
}

/*
@@ -345,7 +373,7 @@ static void cp_configure_ilim(struct pl_data *chip, const char *voter, int ilim)
					== QTI_POWER_SUPPLY_PL_OUTPUT_VPH)
		return;

	target_icl = get_hvdcp3_icl_limit(chip);
	target_icl = get_adapter_icl_based_ilim(chip);
	ilim = (target_icl > 0) ? min(ilim, target_icl) : ilim;

	rc = battery_read_iio_prop(chip, CP, BAT_CP_MIN_ICL, &val);
@@ -833,7 +861,7 @@ static void get_fcc_stepper_params(struct pl_data *chip, int main_fcc_ua,
		if (!chip->cp_ilim_votable)
			chip->cp_ilim_votable = find_votable("CP_ILIM");

		target_icl = get_hvdcp3_icl_limit(chip) * 2;
		target_icl = get_adapter_icl_based_ilim(chip) * 2;
		total_fcc_ua -= chip->main_fcc_ua;

		/*
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ struct charger_param {
	u32 smb_version;
	u32 hvdcp2_max_icl_ua;
	u32 hvdcp3_max_icl_ua;
	u32 qc4_max_icl_ua;
	u32 forced_main_fcc;
	int (*iio_read)(struct device *dev, int iio_chan, int *val);
	int (*iio_write)(struct device *dev, int iio_chan, int val);
+7 −0
Original line number Diff line number Diff line
@@ -412,6 +412,7 @@ static int smb5_configure_internal_pull(struct smb_charger *chg, int type,
#define MICRO_P1A			100000
#define MICRO_1PA			1000000
#define MICRO_3PA			3000000
#define MICRO_4PA			4000000
#define OTG_DEFAULT_DEGLITCH_TIME_MS	50
#define DEFAULT_WD_BARK_TIME		64
#define DEFAULT_WD_SNARL_TIME_8S	0x07
@@ -588,6 +589,12 @@ static int smb5_parse_dt_misc(struct smb5 *chip, struct device_node *node)
	if (chg->chg_param.hvdcp2_max_icl_ua <= 0)
		chg->chg_param.hvdcp2_max_icl_ua = MICRO_3PA;

	/* Used only in Adapter CV mode of operation */
	of_property_read_u32(node, "qcom,qc4-max-icl-ua",
					&chg->chg_param.qc4_max_icl_ua);
	if (chg->chg_param.qc4_max_icl_ua <= 0)
		chg->chg_param.qc4_max_icl_ua = MICRO_4PA;

	return 0;
}