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

Commit 6d951567 authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy
Browse files

power: smb135x-charger: Configure USB to suspend properly



Currently we configure USB to suspend during bootup. When the USB
is removed, smb135x USB path will enter suspend mode. However,
that setting will be cleared when the USB is inserted again. This
makes the USB to consume more than 2mA during suspend.

Configure the smb135x again whenever the parallel charger is set
present so that during suspend, USB will not withdraw more than 2mA.

CRs-Fixed: 705132
Change-Id: I9a5035b2fd548fc4fd90d1dab4a6798375f5506f
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent 9b4d473e
Loading
Loading
Loading
Loading
+28 −6
Original line number Diff line number Diff line
@@ -1677,6 +1677,7 @@ static enum power_supply_property smb135x_parallel_properties[] = {
static int smb135x_parallel_set_chg_present(struct smb135x_chg *chip,
						int present)
{
	u8 val;
	int rc;

	if (present == chip->parallel_charger_present) {
@@ -1775,12 +1776,33 @@ static int smb135x_parallel_set_chg_present(struct smb135x_chg *chip,
	 */
	chip->usb_psy_ma = SUSPEND_CURRENT_MA;
	rc = smb135x_path_suspend(chip, USB, CURRENT, true);
	if (present && rc < 0) {

	if (present) {
		if (rc) {
			dev_err(chip->dev,
				"Couldn't set usb suspend to true rc = %d\n",
				rc);
			return rc;
	} else if (!present) {
		}
		/* Check if the USB is configured for suspend. If not, do it */
		mutex_lock(&chip->path_suspend_lock);
		rc = smb135x_read(chip, CMD_INPUT_LIMIT, &val);
		if (rc) {
			dev_err(chip->dev,
				"Couldn't read 0x%02x rc:%d\n", CMD_INPUT_LIMIT,
				rc);
			mutex_unlock(&chip->path_suspend_lock);
			return rc;
		} else if (!(val & BIT(6))) {
			rc = __smb135x_usb_suspend(chip, 1);
		}
		mutex_unlock(&chip->path_suspend_lock);
		if (rc) {
			dev_err(chip->dev,
				"Couldn't set usb to suspend rc:%d\n", rc);
			return rc;
		}
	} else {
		chip->real_usb_psy_ma = SUSPEND_CURRENT_MA;
	}
	return 0;