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

Commit 0c1fec17 authored by Channagoud Kadabi's avatar Channagoud Kadabi
Browse files

drivers: eud: Set the default state for charger & usb



When EUD CSR is enabled set the default cable state and charger state to
enable. If the default state is not enabled the first spoof attach or
charger enable wont work. Add check to make sure if usb is present and
charger is of type SDP/CDP before enabling eud otherwise the initial
state of the extcon will not be correct and we will end up powering on
usb controller by sending spoof attach exton state even though usb is
not really connected.

Change-Id: Icfe3609d116e48251c133f7142e2e19b476f5a4b
Signed-off-by: default avatarChannagoud Kadabi <ckadabi@codeaurora.org>
parent ea5149e3
Loading
Loading
Loading
Loading
+45 −7
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <linux/serial_core.h>
#include <linux/serial.h>
#include <linux/workqueue.h>
#include <linux/power_supply.h>

#define EUD_ENABLE_CMD 1
#define EUD_DISABLE_CMD 0
@@ -87,7 +88,33 @@ static struct platform_device *eud_private;
static void enable_eud(struct platform_device *pdev)
{
	struct eud_chip *priv = platform_get_drvdata(pdev);
	struct power_supply *usb_psy = NULL;
	union power_supply_propval pval = {0};
	union power_supply_propval tval = {0};
	int ret;

	usb_psy = power_supply_get_by_name("usb");
	if (!usb_psy) {
		dev_warn(&pdev->dev, "Could not get usb power_supply\n");
		return;
	}

	ret = power_supply_get_property(usb_psy,
			POWER_SUPPLY_PROP_PRESENT, &pval);
	if (ret) {
		dev_err(&pdev->dev, "Unable to read USB PRESENT: %x\n", ret);
		return;
	}

	ret = power_supply_get_property(usb_psy,
			POWER_SUPPLY_PROP_REAL_TYPE, &tval);
	if (ret) {
		dev_err(&pdev->dev, "Unable to read USB TYPE: %x\n", ret);
		return;
	}

	if (pval.intval && (tval.intval == POWER_SUPPLY_TYPE_USB ||
	    tval.intval == POWER_SUPPLY_TYPE_USB_CDP)) {
		/* write into CSR to enable EUD */
		writel_relaxed(BIT(0), priv->eud_reg_base + EUD_REG_CSR_EUD_EN);
		/* Enable vbus, chgr & safe mode warning interrupts */
@@ -97,6 +124,17 @@ static void enable_eud(struct platform_device *pdev)
		/* Ensure Register Writes Complete */
		wmb();

		/*
		 * Set the default cable state to usb connect and charger
		 * enable
		 */
		extcon_set_state_sync(priv->extcon, EXTCON_USB, true);
		extcon_set_state_sync(priv->extcon, EXTCON_CHG_USB_SDP, true);
	} else {
		dev_warn(&pdev->dev, "Connect USB cable before enabling EUD\n");
		return;
	}

	dev_dbg(&pdev->dev, "%s: EUD Enabled!\n", __func__);
}