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

Commit 2b85a265 authored by Fenglin Wu's avatar Fenglin Wu Committed by Gustavo Solaira
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 518a6a46
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
/* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -173,6 +173,28 @@ static irqreturn_t gpio_usbdetect_vbus_irq(int irq, void *data)
	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,
@@ -183,13 +205,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);