power: pm8921-charger: fix host mode charging state

While the phone is in usb host mode (supplying power to a usb peripheral)
a charging state is reported. The phone cannot be charging from usb while
supplying power to a usb peripheral.

The fix is to make the usb vbus power code disable charging from usb before
enabling the otg regulators. In addition, the power supply class should not
show a usb charger source present or online when charging is disabled.

CRs-Fixed: 322516
Change-Id: I2eb91f1ea70665b7753924537982b183eb3e8894
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
diff --git a/drivers/power/pm8921-charger.c b/drivers/power/pm8921-charger.c
index c169025..490a8db 100644
--- a/drivers/power/pm8921-charger.c
+++ b/drivers/power/pm8921-charger.c
@@ -391,6 +391,14 @@
 				disable ? CHG_CHARGE_DIS_BIT : 0);
 }
 
+static bool pm_is_chg_charge_dis_bit_set(struct pm8921_chg_chip *chip)
+{
+	u8 temp = 0;
+
+	pm8xxx_readb(chip->dev->parent, CHG_CNTRL, &temp);
+	return !!(temp & CHG_CHARGE_DIS_BIT);
+}
+
 #define PM8921_CHG_V_MIN_MV	3240
 #define PM8921_CHG_V_STEP_MV	20
 #define PM8921_CHG_VDDMAX_MAX	4500
@@ -901,7 +909,10 @@
 			psy->type == POWER_SUPPLY_TYPE_USB_ACA) {
 			chip = container_of(psy, struct pm8921_chg_chip,
 							usb_psy);
-			val->intval = is_usb_chg_plugged_in(chip);
+			if (pm_is_chg_charge_dis_bit_set(chip))
+				val->intval = 0;
+			else
+				val->intval = is_usb_chg_plugged_in(chip);
 		}
 		break;
 	default:
diff --git a/drivers/usb/otg/msm_otg.c b/drivers/usb/otg/msm_otg.c
index f2279be..56559bf 100644
--- a/drivers/usb/otg/msm_otg.c
+++ b/drivers/usb/otg/msm_otg.c
@@ -970,6 +970,11 @@
 		return;
 	}
 
+	/*
+	 * if entering host mode tell the charger to not draw any current
+	 * from usb - if exiting host mode let the charger draw current
+	 */
+	pm8921_disable_source_current(on);
 	if (on) {
 		ret = regulator_enable(vbus_otg);
 		if (ret) {