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

Commit 3ca3acfc authored by Fenglin Wu's avatar Fenglin Wu
Browse files

power: smb1351-charger: Report charger types in REAL_TYPE



Commit eca542a9 ("power: qpnp-smbcharger: Report charger types in
REAL_TYPE property") changes to use POWER_SUPPLY_PROP_REAL_TYPE
property to report charger types between charger driver and USB
driver, so change the same in this driver to make sure USB driver
could get the correct charger type notification when it is used
as the main charger.

Change-Id: Id83dd378cfc808d787d5b5de20a92ed507557803
Signed-off-by: default avatarFenglin Wu <fenglinw@codeaurora.org>
parent 6214ba0f
Loading
Loading
Loading
Loading
+42 −14
Original line number Diff line number Diff line
@@ -2888,6 +2888,28 @@ static void smb1351_rerun_apsd_work(struct work_struct *work)
	smb1351_relax(&chip->smb1351_ws, RERUN_APSD);
}

static int smb1351_notify_usb_supply_type(struct smb1351_charger *chip,
					enum power_supply_type type)
{
	int rc;
	union power_supply_propval pval = {0, };

	pval.intval = type;
	rc = chip->usb_psy->set_property(chip->usb_psy,
			POWER_SUPPLY_PROP_REAL_TYPE, &pval);
	if (rc < 0) {
		if (rc == -EINVAL) {
			rc = chip->usb_psy->set_property(chip->usb_psy,
					POWER_SUPPLY_PROP_TYPE, &pval);
			if (!rc)
				return 0;
		}
		pr_err("notify charger type to usb_psy failed, rc=%d\n", rc);
	}

	return rc;
}

static void smb1351_hvdcp_det_work(struct work_struct *work)
{
	int rc;
@@ -2907,7 +2929,7 @@ static void smb1351_hvdcp_det_work(struct work_struct *work)
	is_hvdcp = !!(reg & (HVDCP_SEL_5V | HVDCP_SEL_9V | HVDCP_SEL_12V));
	if (is_hvdcp) {
		pr_debug("HVDCP detected; notifying USB PSY\n");
		power_supply_set_supply_type(chip->usb_psy,
		smb1351_notify_usb_supply_type(chip,
				POWER_SUPPLY_TYPE_USB_HVDCP);
	}
end:
@@ -2963,7 +2985,7 @@ static int smb1351_apsd_complete_handler(struct smb1351_charger *chip,
					msecs_to_jiffies(HVDCP_NOTIFY_MS));
			}
		}
		power_supply_set_supply_type(chip->usb_psy, type);
		smb1351_notify_usb_supply_type(chip, type);
		/*
		 * SMB is now done sampling the D+/D- lines,
		 * indicate USB driver
@@ -3015,8 +3037,7 @@ static void smb1351_chg_remove_work(struct work_struct *work)
			pr_debug("set parallel charger un-present!\n");
			power_supply_set_present(parallel_psy, false);
		}
		power_supply_set_supply_type(chip->usb_psy,
						POWER_SUPPLY_TYPE_UNKNOWN);
		smb1351_notify_usb_supply_type(chip, POWER_SUPPLY_TYPE_UNKNOWN);
		power_supply_set_present(chip->usb_psy,
						chip->chg_present);
		pr_debug("Set usb psy dp=r dm=r\n");
@@ -3057,7 +3078,7 @@ static int smb1351_usbin_uv_handler(struct smb1351_charger *chip, u8 status)
			chip->chg_present = true;
			pr_debug("updating usb_psy present=%d\n",
						chip->chg_present);
			power_supply_set_supply_type(chip->usb_psy,
			smb1351_notify_usb_supply_type(chip,
					POWER_SUPPLY_TYPE_USB);
			power_supply_set_present(chip->usb_psy,
						chip->chg_present);
@@ -3075,7 +3096,7 @@ static int smb1351_usbin_uv_handler(struct smb1351_charger *chip, u8 status)
			/* clear parallel slave PRESENT */
			if (parallel_psy && chip->parallel.slave_detected)
				power_supply_set_present(parallel_psy, false);
			power_supply_set_supply_type(chip->usb_psy,
			smb1351_notify_usb_supply_type(chip,
					POWER_SUPPLY_TYPE_UNKNOWN);
			power_supply_set_present(chip->usb_psy,
						chip->chg_present);
@@ -3127,8 +3148,7 @@ static int smb1351_usbin_ov_handler(struct smb1351_charger *chip, u8 status)
		/* clear parallel slave PRESENT */
		if (parallel_psy && chip->parallel.slave_detected)
			power_supply_set_present(parallel_psy, false);
		power_supply_set_supply_type(chip->usb_psy,
						POWER_SUPPLY_TYPE_UNKNOWN);
		smb1351_notify_usb_supply_type(chip, POWER_SUPPLY_TYPE_UNKNOWN);
		power_supply_set_present(chip->usb_psy, chip->chg_present);
	} else {
		chip->usbin_ov = false;
@@ -3648,12 +3668,20 @@ static int smb1351_update_usb_supply_icl(struct smb1351_charger *chip)
	int rc, type, icl;
	union power_supply_propval pval = {0, };

	rc = chip->usb_psy->get_property(chip->usb_psy,
			POWER_SUPPLY_PROP_REAL_TYPE, &pval);
	if (rc == -EINVAL) {
		rc = chip->usb_psy->get_property(chip->usb_psy,
				POWER_SUPPLY_PROP_TYPE, &pval);
	if (rc) {
		pr_err("Get USB supply type failed, rc=%d\n", rc);
		if (rc < 0) {
			pr_err("Get USB supply TYPE failed, rc=%d\n", rc);
			return rc;
		}
	} else if (rc < 0) {
		pr_err("Get USB supply REAL_TYPE failed, rc=%d\n", rc);
		return rc;
	}

	type = pval.intval;
	chip->usb_psy_type = type;
	rc = chip->usb_psy->get_property(chip->usb_psy,