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

Commit 11e275dd authored by Xiaozhe Shi's avatar Xiaozhe Shi
Browse files

power: qpnp-smbcharger: charge at 3A for HVDCP chargers



Allow the charger to pull 3A of charge current from HVDCP chargers,
since they are certified to handle that much current.

CRs-Fixed: 918587
Change-Id: I411da6ffe0756ed8c3f3b23d1ed13cd31dbb7fa1
Signed-off-by: default avatarXiaozhe Shi <xiaozhes@codeaurora.org>
parent 153cc9a3
Loading
Loading
Loading
Loading
+60 −46
Original line number Diff line number Diff line
@@ -113,7 +113,6 @@ struct smbchg_chip {
	int				iterm_ma;
	int				usb_max_current_ma;
	int				dc_max_current_ma;
	int				usb_target_current_ma;
	int				dc_target_current_ma;
	int				cfg_fastchg_current_ma;
	int				fastchg_current_ma;
@@ -183,6 +182,7 @@ struct smbchg_chip {
	bool				usb_ov_det;
	bool				otg_pulse_skip_dis;
	const char			*battery_type;
	enum power_supply_type		usb_supply_type;
	bool				very_weak_charger;
	bool				parallel_charger_detected;
	bool				chg_otg_enabled;
@@ -1487,8 +1487,6 @@ static int smbchg_set_usb_current_max(struct smbchg_chip *chip,
							int current_ma)
{
	int rc = 0;
	enum power_supply_type usb_supply_type;
	char *usb_type_name = "null";

	/*
	 * if the battery is not present, do not allow the usb ICL to lower in
@@ -1510,9 +1508,7 @@ static int smbchg_set_usb_current_max(struct smbchg_chip *chip,
		rc = vote(chip->usb_suspend_votable, USB_EN_VOTER, false, 0);
	}

	read_usb_type(chip, &usb_type_name, &usb_supply_type);

	switch (usb_supply_type) {
	switch (chip->usb_supply_type) {
	case POWER_SUPPLY_TYPE_USB:
		if ((current_ma < CURRENT_150_MA) &&
				(chip->wa_flags & SMBCHG_USB100_WA))
@@ -1611,8 +1607,8 @@ static int smbchg_set_usb_current_max(struct smbchg_chip *chip,
	}

out:
	pr_smb(PR_STATUS, "usb type = %s current set to %d mA\n",
			usb_type_name, chip->usb_max_current_ma);
	pr_smb(PR_STATUS, "usb type = %d current set to %d mA\n",
			chip->usb_supply_type, chip->usb_max_current_ma);
	return rc;
}

@@ -3410,9 +3406,8 @@ static void smbchg_external_power_changed(struct power_supply *psy)
	pr_smb(PR_MISC, "usb type = %s current_limit = %d\n",
			usb_type_name, current_limit);

	chip->usb_target_current_ma = current_limit;
	rc = vote(chip->usb_icl_votable, PSY_ICL_VOTER, true,
				chip->usb_target_current_ma);
				current_limit);
	if (rc < 0)
		pr_err("Couldn't update USB PSY ICL vote rc=%d\n", rc);

@@ -4067,6 +4062,55 @@ static int smbchg_charging_status_change(struct smbchg_chip *chip)
	return 0;
}

#define DEFAULT_HVDCP_CHG_MA	3000
#define DEFAULT_WALL_CHG_MA	1800
#define DEFAULT_SDP_MA		100
#define DEFAULT_CDP_MA		1500
static int smbchg_change_usb_supply_type(struct smbchg_chip *chip,
						enum power_supply_type type)
{
	int rc, current_limit_ma;

	/*
	 * if the type is not unknown, set the type before changing ICL vote
	 * in order to ensure that the correct current limit registers are
	 * used
	 */
	if (type != POWER_SUPPLY_TYPE_UNKNOWN)
		chip->usb_supply_type = type;

	if (type == POWER_SUPPLY_TYPE_USB)
		current_limit_ma = DEFAULT_SDP_MA;
	else if (type == POWER_SUPPLY_TYPE_USB)
		current_limit_ma = DEFAULT_SDP_MA;
	else if (type == POWER_SUPPLY_TYPE_USB_CDP)
		current_limit_ma = DEFAULT_CDP_MA;
	else if (type == POWER_SUPPLY_TYPE_USB_HVDCP
			|| type == POWER_SUPPLY_TYPE_USB_HVDCP_3)
		current_limit_ma = DEFAULT_HVDCP_CHG_MA;
	else
		current_limit_ma = DEFAULT_WALL_CHG_MA;

	pr_smb(PR_STATUS, "Type %d: setting mA = %d\n",
		type, current_limit_ma);
	rc = vote(chip->usb_icl_votable, PSY_ICL_VOTER, true,
				current_limit_ma);
	if (rc < 0) {
		pr_err("Couldn't vote for new USB ICL rc=%d\n", rc);
		goto out;
	}

	if (!chip->skip_usb_notification)
		power_supply_set_supply_type(chip->usb_psy, type);

	/* otherwise if it is unknown, set type after the vote */
	if (type == POWER_SUPPLY_TYPE_UNKNOWN)
		chip->usb_supply_type = type;

out:
	return rc;
}

static bool is_hvdcp_present(struct  smbchg_chip *chip)
{
	int rc;
@@ -4155,12 +4199,8 @@ static void smbchg_hvdcp_det_work(struct work_struct *work)
				pr_err("could not force 9V HVDCP continuing rc=%d\n",
						rc);
		}
		if (!chip->skip_usb_notification) {
			pr_smb(PR_MISC, "setting usb psy type = %d\n",
					POWER_SUPPLY_TYPE_USB_HVDCP);
			power_supply_set_supply_type(chip->usb_psy,
		smbchg_change_usb_supply_type(chip,
				POWER_SUPPLY_TYPE_USB_HVDCP);
		}
		if (chip->psy_registered)
			power_supply_changed(&chip->batt_psy);
		smbchg_aicl_deglitch_wa_check(chip);
@@ -4276,11 +4316,8 @@ static void handle_usb_removal(struct smbchg_chip *chip)
	/* Clear the OV detected status set before */
	if (chip->usb_ov_det)
		chip->usb_ov_det = false;
	smbchg_change_usb_supply_type(chip, POWER_SUPPLY_TYPE_UNKNOWN);
	if (!chip->skip_usb_notification) {
		pr_smb(PR_MISC, "setting usb psy type = %d\n",
				POWER_SUPPLY_TYPE_UNKNOWN);
		power_supply_set_supply_type(chip->usb_psy,
				POWER_SUPPLY_TYPE_UNKNOWN);
		pr_smb(PR_MISC, "setting usb psy present = %d\n",
				chip->usb_present);
		power_supply_set_present(chip->usb_psy, chip->usb_present);
@@ -4340,9 +4377,6 @@ static bool is_usbin_uv_high(struct smbchg_chip *chip)
}

#define HVDCP_NOTIFY_MS		2500
#define DEFAULT_WALL_CHG_MA	1800
#define DEFAULT_SDP_MA		100
#define DEFAULT_CDP_MA		1500
static void handle_usb_insertion(struct smbchg_chip *chip)
{
	struct power_supply *parallel_psy = get_parallel_psy(chip);
@@ -4357,10 +4391,8 @@ static void handle_usb_insertion(struct smbchg_chip *chip)
		"inserted type = %d (%s)", usb_supply_type, usb_type_name);

	smbchg_aicl_deglitch_wa_check(chip);
	smbchg_change_usb_supply_type(chip, usb_supply_type);
	if (!chip->skip_usb_notification) {
		pr_smb(PR_MISC, "setting usb psy type = %d\n",
				usb_supply_type);
		power_supply_set_supply_type(chip->usb_psy, usb_supply_type);
		pr_smb(PR_MISC, "setting usb psy present = %d\n",
				chip->usb_present);
		power_supply_set_present(chip->usb_psy, chip->usb_present);
@@ -4391,20 +4423,6 @@ static void handle_usb_insertion(struct smbchg_chip *chip)
		schedule_delayed_work(&chip->hvdcp_det_work,
					msecs_to_jiffies(HVDCP_NOTIFY_MS));

	if (usb_supply_type == POWER_SUPPLY_TYPE_USB)
		chip->usb_target_current_ma = DEFAULT_SDP_MA;
	else if (usb_supply_type == POWER_SUPPLY_TYPE_USB_CDP)
		chip->usb_target_current_ma = DEFAULT_CDP_MA;
	else
		chip->usb_target_current_ma = DEFAULT_WALL_CHG_MA;

	pr_smb(PR_STATUS, "%s detected setting mA = %d\n",
		usb_type_name, chip->usb_target_current_ma);
	rc = vote(chip->usb_icl_votable, PSY_ICL_VOTER, true,
				chip->usb_target_current_ma);
	if (rc < 0)
		pr_err("Couldn't vote for new USB ICL rc=%d\n", rc);

	if (parallel_psy) {
		rc = power_supply_set_present(parallel_psy, true);
		chip->parallel_charger_detected = rc ? false : true;
@@ -5157,12 +5175,8 @@ static int smbchg_hvdcp3_confirmed(struct smbchg_chip *chip)
	if (rc < 0)
		pr_err("Couldn't retract HVDCP ICL vote rc=%d\n", rc);

	pr_smb(PR_MISC, "setting usb psy type = %d\n",
				POWER_SUPPLY_TYPE_USB_HVDCP_3);
	if (!chip->skip_usb_notification) {
		power_supply_set_supply_type(chip->usb_psy,
				POWER_SUPPLY_TYPE_USB_HVDCP_3);
	}
	smbchg_change_usb_supply_type(chip, POWER_SUPPLY_TYPE_USB_HVDCP_3);

	return rc;
}