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

Commit d41465fb authored by Fenglin Wu's avatar Fenglin Wu
Browse files

platform: msm: gpio-usbdetect: 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.

Change-Id: Ia70e9a376a494c6c9d8905ff4017996eecc8d503
Signed-off-by: default avatarFenglin Wu <fenglinw@codeaurora.org>
parent fc7eae29
Loading
Loading
Loading
Loading
+27 −5
Original line number Diff line number Diff line
@@ -193,6 +193,28 @@ queue_chg_work:
	return IRQ_HANDLED;
}

static int gpio_usbdetect_notify_usb_type(struct gpio_usbdetect *usb,
					enum power_supply_type type)
{
	int rc;
	union power_supply_propval pval = {0, };

	pval.intval = type;
	rc = usb->usb_psy->set_property(usb->usb_psy,
			POWER_SUPPLY_PROP_REAL_TYPE, &pval);
	if (rc < 0) {
		if (rc == -EINVAL) {
			rc = usb->usb_psy->set_property(usb->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 gpio_usbdetect_chg_work(struct work_struct *w)
{
	struct gpio_usbdetect *usb = container_of(w, struct gpio_usbdetect,
@@ -202,7 +224,7 @@ static void gpio_usbdetect_chg_work(struct work_struct *w)
		dev_dbg(&usb->pdev->dev, "ID:%d VBUS:%d\n",
						usb->id, usb->vbus);
		if (!usb->id) {
			power_supply_set_supply_type(usb->usb_psy,
			gpio_usbdetect_notify_usb_type(usb,
					POWER_SUPPLY_TYPE_UNKNOWN);
			power_supply_set_present(usb->usb_psy, 0);
			power_supply_set_usb_otg(usb->usb_psy, 1);
@@ -217,11 +239,11 @@ static void gpio_usbdetect_chg_work(struct work_struct *w)
			gpio_set_value(usb->dpdm_switch_gpio, 0);

		if (usb->vbus) {
			power_supply_set_supply_type(usb->usb_psy,
			gpio_usbdetect_notify_usb_type(usb,
						POWER_SUPPLY_TYPE_USB);
			power_supply_set_present(usb->usb_psy, usb->vbus);
		} else {
			power_supply_set_supply_type(usb->usb_psy,
			gpio_usbdetect_notify_usb_type(usb,
					POWER_SUPPLY_TYPE_UNKNOWN);
			power_supply_set_present(usb->usb_psy, usb->vbus);
		}
@@ -234,13 +256,13 @@ static void gpio_usbdetect_chg_work(struct work_struct *w)
			power_supply_set_usb_otg(usb->usb_psy, 0);

		if (!usb->disable_device_mode) {
			power_supply_set_supply_type(usb->usb_psy,
			gpio_usbdetect_notify_usb_type(usb,
						POWER_SUPPLY_TYPE_USB);
			power_supply_set_present(usb->usb_psy, usb->vbus);
		}
	} else {
		/* notify gpio_state = LOW as disconnect */
		power_supply_set_supply_type(usb->usb_psy,
		gpio_usbdetect_notify_usb_type(usb,
				POWER_SUPPLY_TYPE_UNKNOWN);
		power_supply_set_present(usb->usb_psy, usb->vbus);