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

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

Merge "power: smb5: fix FLOAT charger ICL handling"

parents 9c4a6b22 9ad97867
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ struct pl_data {
	int			total_settled_ua;
	int			pl_settled_ua;
	int			pl_fcc_max;
	u32			wa_flags;
	struct class		qcom_batt_class;
	struct wakeup_source	*pl_ws;
	struct notifier_block	nb;
@@ -85,6 +86,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);

@@ -620,7 +625,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,
@@ -1190,8 +1195,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;
@@ -1206,6 +1223,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
@@ -5228,7 +5228,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);
+53 −23
Original line number Diff line number Diff line
@@ -654,6 +654,7 @@ int smblib_mapping_cc_delta_from_field_value(struct smb_chg_param *param,
	return 0;
}

#define USBIN_100MA	100000
static void smblib_uusb_removal(struct smb_charger *chg)
{
	int rc;
@@ -697,6 +698,15 @@ 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);

	/* leave the ICL configured to 100mA for next insertion */
	vote(chg->usb_icl_votable, DEFAULT_100MA_VOTER, true, USBIN_100MA);
	/* clear USB ICL vote for USB_PSY_VOTER */
	rc = vote(chg->usb_icl_votable, USB_PSY_VOTER, false, 0);
	if (rc < 0)
@@ -762,7 +772,6 @@ static int smblib_get_pulse_cnt(struct smb_charger *chg, int *count)
}

#define USBIN_25MA	25000
#define USBIN_100MA	100000
#define USBIN_150MA	150000
#define USBIN_500MA	500000
#define USBIN_900MA	900000
@@ -884,6 +893,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;
}
@@ -2112,12 +2124,20 @@ static int smblib_handle_usb_current(struct smb_charger *chg,
			 * Valid FLOAT charger, report the current based
			 * of Rp
			 */
			if (chg->connector_type ==
					POWER_SUPPLY_CONNECTOR_TYPEC) {
				typec_mode = smblib_get_prop_typec_mode(chg);
			rp_ua = get_rp_based_dcp_current(chg, typec_mode);
			rc = vote(chg->usb_icl_votable, LEGACY_UNKNOWN_VOTER,
								true, rp_ua);
			if (rc < 0)
				rp_ua = get_rp_based_dcp_current(chg,
								typec_mode);
				rc = vote(chg->usb_icl_votable,
						DYNAMIC_RP_VOTER, true, rp_ua);
				if (rc < 0) {
					pr_err("Couldn't vote ICL DYNAMIC_RP_VOTER rc=%d\n",
							rc);
					return rc;
				}
			}
			/* No specific handling required for micro-USB */
		} else {
			/*
			 * FLOAT charger detected as SDP by USB driver,
@@ -2127,21 +2147,31 @@ static int smblib_handle_usb_current(struct smb_charger *chg,
			chg->real_charger_type = POWER_SUPPLY_TYPE_USB;
			rc = vote(chg->usb_icl_votable, USB_PSY_VOTER,
							true, usb_current);
			if (rc < 0)
				return rc;
			rc = vote(chg->usb_icl_votable, LEGACY_UNKNOWN_VOTER,
							false, 0);
			if (rc < 0)
			if (rc < 0) {
				pr_err("Couldn't vote ICL USB_PSY_VOTER rc=%d\n",
						rc);
				return rc;
			}
		}
	} 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, DEFAULT_100MA_VOTER, false, 0);
	if (rc < 0) {
		pr_err("Couldn't unvote ICL DEFAULT_100MA_VOTER 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)
{
@@ -2276,9 +2306,6 @@ static int __smblib_set_prop_pd_active(struct smb_charger *chg, bool pd_active)
			smblib_err(chg, "Couldn't vote for USB ICL rc=%d\n",
									rc);

		/* since PD was found the cable must be non-legacy */
		vote(chg->usb_icl_votable, LEGACY_UNKNOWN_VOTER, false, 0);

		/* clear USB ICL vote for DCP_VOTER */
		rc = vote(chg->usb_icl_votable, DCP_VOTER, false, 0);
		if (rc < 0)
@@ -2886,6 +2913,7 @@ 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 not DCP then no hvdcp timeout happens. Enable pd here */
		vote(chg->pd_disallowed_votable_indirect, APSD_VOTER,
				false, 0);
@@ -2894,12 +2922,13 @@ static void smblib_handle_apsd_done(struct smb_charger *chg, bool rising)
			smblib_notify_device_mode(chg, true);
		break;
	case OCP_CHARGER_BIT:
	case FLOAT_CHARGER_BIT:
		vote(chg->usb_icl_votable, DEFAULT_100MA_VOTER, false, 0);
		/* if not DCP then no hvdcp timeout happens, Enable pd here. */
		vote(chg->pd_disallowed_votable_indirect, APSD_VOTER,
				false, 0);
		break;
	case DCP_CHARGER_BIT:
		vote(chg->usb_icl_votable, DEFAULT_100MA_VOTER, false, 0);
		break;
	default:
		break;
@@ -3011,7 +3040,7 @@ static void smblib_handle_typec_removal(struct smb_charger *chg)
	cancel_delayed_work_sync(&chg->pl_enable_work);

	/* reset input current limit voters */
	vote(chg->usb_icl_votable, LEGACY_UNKNOWN_VOTER, true, 100000);
	vote(chg->usb_icl_votable, DEFAULT_100MA_VOTER, true, USBIN_100MA);
	vote(chg->usb_icl_votable, PD_VOTER, false, 0);
	vote(chg->usb_icl_votable, USB_PSY_VOTER, false, 0);
	vote(chg->usb_icl_votable, DCP_VOTER, false, 0);
@@ -3019,6 +3048,7 @@ static void smblib_handle_typec_removal(struct smb_charger *chg)
	vote(chg->usb_icl_votable, SW_QC3_VOTER, false, 0);
	vote(chg->usb_icl_votable, OTG_VOTER, false, 0);
	vote(chg->usb_icl_votable, CTM_VOTER, false, 0);
	vote(chg->usb_icl_votable, DYNAMIC_RP_VOTER, false, 0);

	/* reset power delivery voters */
	vote(chg->pd_allowed_votable, PD_VOTER, false, 0);
@@ -3149,8 +3179,8 @@ static void smblib_handle_rp_change(struct smb_charger *chg, int typec_mode)
	 * pre-existing valid vote.
	 */
	if (apsd->pst == POWER_SUPPLY_TYPE_USB_FLOAT &&
		get_client_vote(chg->usb_icl_votable,
			LEGACY_UNKNOWN_VOTER) <= 100000)
		(get_client_vote(chg->usb_icl_votable, DEFAULT_100MA_VOTER)
					<= USBIN_100MA))
		return;

	/*
@@ -3162,7 +3192,7 @@ static void smblib_handle_rp_change(struct smb_charger *chg, int typec_mode)
						chg->typec_mode, typec_mode);

	rp_ua = get_rp_based_dcp_current(chg, typec_mode);
	vote(chg->usb_icl_votable, LEGACY_UNKNOWN_VOTER, true, rp_ua);
	vote(chg->usb_icl_votable, DYNAMIC_RP_VOTER, true, rp_ua);
}

static void smblib_handle_typec_cc_state_change(struct smb_charger *chg)
@@ -3731,7 +3761,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);
+2 −1
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ enum print_reason {
#define CTM_VOTER			"CTM_VOTER"
#define SW_QC3_VOTER			"SW_QC3_VOTER"
#define AICL_RERUN_VOTER		"AICL_RERUN_VOTER"
#define LEGACY_UNKNOWN_VOTER		"LEGACY_UNKNOWN_VOTER"
#define QNOVO_VOTER			"QNOVO_VOTER"
#define BATT_PROFILE_VOTER		"BATT_PROFILE_VOTER"
#define OTG_DELAY_VOTER			"OTG_DELAY_VOTER"
@@ -66,6 +65,8 @@ enum print_reason {
#define PL_FCC_LOW_VOTER		"PL_FCC_LOW_VOTER"
#define WBC_VOTER			"WBC_VOTER"
#define HW_LIMIT_VOTER			"HW_LIMIT_VOTER"
#define DYNAMIC_RP_VOTER		"DYNAMIC_RP_VOTER"
#define DEFAULT_100MA_VOTER		"DEFAULT_100MA_VOTER"

#define BOOST_BACK_STORM_COUNT	3
#define WEAK_CHG_STORM_COUNT	8