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

Commit 01806dea authored by Harry Yang's avatar Harry Yang
Browse files

power: smb1390: add wireless charging support



Add parallel wireless charging support in SMB1390 driver,
maintaining ILIM = MIN(TOTAL_FCC/2, TOTAL_ICL), where
TOTAL_ICL is DC Input current limit.

Change-Id: I73444ee72ad10f9bf3aeb93d5859e58eba20080f
Signed-off-by: default avatarHarry Yang <harryy@codeaurora.org>
parent 2bf2ab5a
Loading
Loading
Loading
Loading
+38 −8
Original line number Diff line number Diff line
@@ -86,7 +86,8 @@
#define ILIM_VOTER	"ILIM_VOTER"
#define FCC_VOTER	"FCC_VOTER"
#define ICL_VOTER	"ICL_VOTER"
#define USB_VOTER	"USB_VOTER"
#define WIRELESS_VOTER	"WIRELESS_VOTER"
#define SRC_VOTER	"SRC_VOTER"

enum {
	SWITCHER_OFF_WINDOW_IRQ = 0,
@@ -126,6 +127,7 @@ struct smb1390 {
	/* power supplies */
	struct power_supply	*usb_psy;
	struct power_supply	*batt_psy;
	struct power_supply	*dc_psy;

	int			irqs[NUM_IRQS];
	bool			status_change_running;
@@ -184,6 +186,14 @@ static bool is_psy_voter_available(struct smb1390 *chip)
		}
	}

	if (!chip->dc_psy) {
		chip->dc_psy = power_supply_get_by_name("dc");
		if (!chip->dc_psy) {
			pr_debug("Couldn't find dc psy\n");
			return false;
		}
	}

	if (!chip->fcc_votable) {
		chip->fcc_votable = find_votable("FCC");
		if (!chip->fcc_votable) {
@@ -479,19 +489,39 @@ static void smb1390_status_change_work(struct work_struct *work)
	}

	if (pval.intval == POWER_SUPPLY_CHARGER_SEC_CP) {
		vote(chip->disable_votable, USB_VOTER, false, 0);
		rc = power_supply_get_property(chip->usb_psy,
				POWER_SUPPLY_PROP_SMB_EN_REASON, &pval);
		if (rc < 0) {
			pr_err("Couldn't get cp reason rc=%d\n", rc);
			goto out;
		}

		vote(chip->disable_votable, SRC_VOTER, false, 0);

		/*
		 * ILIM is set based on the primary chargers AICL result. This
		 * ensures VBUS does not collapse due to the current drawn via
		 * MID.
		 */
		if (pval.intval == POWER_SUPPLY_CP_WIRELESS) {
			vote(chip->ilim_votable, ICL_VOTER, false, 0);
			rc = power_supply_get_property(chip->dc_psy,
					POWER_SUPPLY_PROP_CURRENT_MAX, &pval);
			if (rc < 0)
				pr_err("Couldn't get dc icl rc=%d\n", rc);
			else
				vote(chip->ilim_votable, WIRELESS_VOTER, true,
								pval.intval);
		} else { /* QC3 or PPS */
			vote(chip->ilim_votable, WIRELESS_VOTER, false, 0);
			rc = power_supply_get_property(chip->usb_psy,
				POWER_SUPPLY_PROP_INPUT_CURRENT_SETTLED, &pval);
			if (rc < 0)
				pr_err("Couldn't get usb icl rc=%d\n", rc);
			else
			vote(chip->ilim_votable, ICL_VOTER, true, pval.intval);
				vote(chip->ilim_votable, ICL_VOTER, true,
								pval.intval);
		}

		/* input current is always half the charge current */
		vote(chip->ilim_votable, FCC_VOTER, true,
@@ -522,7 +552,7 @@ static void smb1390_status_change_work(struct work_struct *work)
			}
		}
	} else {
		vote(chip->disable_votable, USB_VOTER, true, 0);
		vote(chip->disable_votable, SRC_VOTER, true, 0);
		vote(chip->fcc_votable, CP_VOTER, false, 0);
	}