Merge android13-gs-pixel-5.10-tm-qpr2 into android13-gs-pixel-5.10-tm-qpr3

SBMerger: 478053055
Change-Id: Ie3c400b5d7e7a62bf8cd78bc6c85409e9d93e465
Signed-off-by: SecurityBot <[email protected]>
diff --git a/google_battery.c b/google_battery.c
index 55c5bcc..f2eed7f 100644
--- a/google_battery.c
+++ b/google_battery.c
@@ -8491,7 +8491,7 @@
 		pr_err("cannot register power supply notifer, ret=%d\n",
 			ret);
 
-	batt_drv->batt_ws = wakeup_source_register(NULL, gbatt_psy_desc.name);
+	batt_drv->batt_ws = wakeup_source_register(NULL, "google-battery");
 	batt_drv->taper_ws = wakeup_source_register(NULL, "Taper");
 	batt_drv->poll_ws = wakeup_source_register(NULL, "Poll");
 	batt_drv->msc_ws = wakeup_source_register(NULL, "MSC");
diff --git a/google_bms.h b/google_bms.h
index 10fe4b4..1cd3e6a 100644
--- a/google_bms.h
+++ b/google_bms.h
@@ -571,7 +571,8 @@
 
 	GBMS_CHGR_MODE_WLC_TX	= 0x40,
 
-	GBMS_CHGR_MODE_VOUT	= 0x50,
+	GBMS_POGO_VIN		= 0x50,
+	GBMS_POGO_VOUT		= 0x51,
 };
 
 #define GBMS_MODE_VOTABLE "CHARGER_MODE"
diff --git a/google_charger.c b/google_charger.c
index c930773..b2e5e73 100644
--- a/google_charger.c
+++ b/google_charger.c
@@ -110,7 +110,8 @@
 #define EXT2_DETECT_THRESHOLD_UV	(5000000)
 
 #define usb_pd_is_high_volt(ad) \
-	((ad)->ad_type == CHG_EV_ADAPTER_TYPE_USB_PD && \
+	(((ad)->ad_type == CHG_EV_ADAPTER_TYPE_USB_PD || \
+	(ad)->ad_type == CHG_EV_ADAPTER_TYPE_USB_PD_PPS) && \
 	(ad)->ad_voltage * 100 > PD_SNK_MIN_MV)
 
 /*
@@ -588,13 +589,20 @@
 static int info_usb_ad_type(int usb_type, int usbc_type)
 {
 	switch (usb_type) {
-	case POWER_SUPPLY_TYPE_USB:
-		return CHG_EV_ADAPTER_TYPE_USB_SDP;
-	case POWER_SUPPLY_TYPE_USB_CDP:
+	case POWER_SUPPLY_USB_TYPE_SDP:
+		return (usbc_type == POWER_SUPPLY_USB_TYPE_PD_PPS) ?
+			CHG_EV_ADAPTER_TYPE_USB_PD_PPS :
+			CHG_EV_ADAPTER_TYPE_USB_SDP;
+	case POWER_SUPPLY_USB_TYPE_CDP:
 		return CHG_EV_ADAPTER_TYPE_USB_CDP;
-	case POWER_SUPPLY_TYPE_USB_DCP:
-		return CHG_EV_ADAPTER_TYPE_USB_DCP;
-	case POWER_SUPPLY_TYPE_USB_PD:
+	case POWER_SUPPLY_USB_TYPE_DCP:
+		if (usbc_type == POWER_SUPPLY_USB_TYPE_PD)
+			return CHG_EV_ADAPTER_TYPE_USB_PD;
+		else if (usbc_type == POWER_SUPPLY_USB_TYPE_PD_PPS)
+			return CHG_EV_ADAPTER_TYPE_USB_PD_PPS;
+		else
+			return CHG_EV_ADAPTER_TYPE_USB_DCP;
+	case POWER_SUPPLY_USB_TYPE_PD:
 		return (usbc_type == POWER_SUPPLY_USB_TYPE_PD_PPS) ?
 			CHG_EV_ADAPTER_TYPE_USB_PD_PPS :
 			CHG_EV_ADAPTER_TYPE_USB_PD;
@@ -1938,8 +1946,10 @@
 			bd_state->dd_last_update = now;
 
 		time = now - bd_state->dd_last_update;
-		if (bd_state->dd_trigger_time && time >= bd_state->dd_trigger_time)
+		if (bd_state->dd_trigger_time && time >= bd_state->dd_trigger_time) {
 			bd_state->dd_enabled = 1;
+			bd_state->lowerbd_reached = true;
+		}
 	}
 }
 
@@ -1964,7 +1974,7 @@
 	/* update dd_state to user space */
 	bd_state->dd_state = bd_dd_state_update(bd_state->dd_state,
 						bd_state->dd_triggered,
-						(soc >= lowerbd));
+						(soc >= upperbd));
 
 	/* Start DD stats */
 	if (bd_state->dd_state == DOCK_DEFEND_ACTIVE)
@@ -5288,7 +5298,7 @@
 		const bool pps_enable = of_property_read_bool(chg_drv->device->of_node,
 							      "google,pps-enable");
 
-		ret = pps_init(&chg_drv->pps_data, chg_drv->device, tcpm_psy);
+		ret = pps_init(&chg_drv->pps_data, chg_drv->device, tcpm_psy, "gcharger-pps");
 		if (ret < 0) {
 			pr_err("PPS init failure for %s (%d)\n", name, ret);
 		} else if (pps_enable) {
diff --git a/google_cpm.c b/google_cpm.c
index f88e0cc..9d57db4 100644
--- a/google_cpm.c
+++ b/google_cpm.c
@@ -3168,7 +3168,7 @@
 
 			/* PPS charging: needs an APDO */
 			ret = pps_init(&gcpm->tcpm_pps_data, gcpm->device,
-				       gcpm->tcpm_psy);
+				       gcpm->tcpm_psy, "wired-pps");
 			if (ret == 0 && gcpm->debug_entry)
 				pps_init_fs(&gcpm->tcpm_pps_data, gcpm->debug_entry);
 			if (ret < 0) {
@@ -3206,7 +3206,7 @@
 
 			/* PPS charging: needs an APDO */
 			ret = pps_init(&gcpm->wlc_pps_data, gcpm->device,
-					gcpm->wlc_dc_psy);
+					gcpm->wlc_dc_psy, "wireless-pps");
 			if (ret == 0 && gcpm->debug_entry)
 				pps_init_fs(&gcpm->wlc_pps_data, gcpm->debug_entry);
 			if (ret < 0) {
@@ -3838,7 +3838,7 @@
 	INIT_DELAYED_WORK(&gcpm->init_work, gcpm_init_work);
 	mutex_init(&gcpm->chg_psy_lock);
 
-	gcpm->gcpm_ws = wakeup_source_register(NULL, "gcpm");
+	gcpm->gcpm_ws = wakeup_source_register(NULL, "google-cpm");
 	if (!gcpm->gcpm_ws) {
 		dev_err(gcpm->device, "Failed to register wakeup source\n");
 		return -ENODEV;
diff --git a/google_dc_pps.c b/google_dc_pps.c
index 8b10f5e..bca5239 100644
--- a/google_dc_pps.c
+++ b/google_dc_pps.c
@@ -504,7 +504,7 @@
  * pps_data->nr_snk_pdo == 0 means no PPS
  */
 int pps_init(struct pd_pps_data *pps_data, struct device *dev,
-	     struct power_supply *pps_psy)
+	     struct power_supply *pps_psy, const char *pps_ws_name)
 {
 	int ret;
 
@@ -530,8 +530,7 @@
 	pps_data->stay_awake = of_property_read_bool(dev->of_node,
 						     "google,pps-awake");
 	if (pps_data->stay_awake) {
-		pps_data->pps_ws = wakeup_source_register(NULL,
-							  pps_name(pps_psy));
+		pps_data->pps_ws = wakeup_source_register(NULL, pps_ws_name);
 		if (!pps_data->pps_ws) {
 			dev_err(dev, "Failed to register wakeup source\n");
 			return -ENODEV;
diff --git a/google_dc_pps.h b/google_dc_pps.h
index bda5f65..d747988 100644
--- a/google_dc_pps.h
+++ b/google_dc_pps.h
@@ -106,7 +106,7 @@
 
 struct dentry;
 int pps_init(struct pd_pps_data *pps_data, struct device *dev,
-	     struct power_supply *pps_psy);
+	     struct power_supply *pps_psy, const char *pps_ws_name);
 int pps_init_fs(struct pd_pps_data *pps_data, struct dentry *de);
 /* reset state and leave in DISABLED  */
 void pps_init_state(struct pd_pps_data *pps_data);
diff --git a/google_dock.c b/google_dock.c
index c425a3a..77ec0ff 100644
--- a/google_dock.c
+++ b/google_dock.c
@@ -99,7 +99,7 @@
 
 	return gvotable_cast_long_vote(dock->chg_mode_votable,
 				       DOCK_VOUT_VOTER,
-				       GBMS_CHGR_MODE_VOUT,
+				       GBMS_POGO_VOUT,
 				       enabled != 0);
 }
 
diff --git a/max77759.h b/max77759.h
index cc89ff8..35d02ba 100644
--- a/max77759.h
+++ b/max77759.h
@@ -124,6 +124,7 @@
 	u8 raw_value;	/* hard override */
 	bool use_raw;
 
+	bool pogo_vin;	/* pogo ovp_en */
 	bool pogo_vout;	/* pogo 5v vout */
 
 	u8 reg;
diff --git a/max77759_charger.c b/max77759_charger.c
index 7d6cc61..8eac855 100644
--- a/max77759_charger.c
+++ b/max77759_charger.c
@@ -588,11 +588,18 @@
 		pr_debug("%s: WLC_TX vote=%x\n", __func__, mode);
 		cb_data->wlc_tx += 1;
 		break;
+	/* pogo vin */
+	case GBMS_POGO_VIN:
+		if (!cb_data->pogo_vin)
+			cb_data->reason = reason;
+		pr_debug("%s: POGO VIN vote=%x\n", __func__, mode);
+		cb_data->pogo_vin += 1;
+		break;
 	/* pogo vout */
-	case GBMS_CHGR_MODE_VOUT:
+	case GBMS_POGO_VOUT:
 		if (!cb_data->pogo_vout)
 			cb_data->reason = reason;
-		pr_debug("%s: VOUT vote=%x\n", __func__, mode);
+		pr_debug("%s: POGO VOUT vote=%x\n", __func__, mode);
 		cb_data->pogo_vout += 1;
 		break;
 
@@ -831,7 +838,23 @@
 	return usecase;
 }
 
-static int max77759_wcin_is_valid(struct max77759_chgr_data *data);
+static void max77759_set_pogo_ovp_en(struct max77759_usecase_data *uc_data,
+				     const int enabled)
+{
+	const int gpio_en = gpio_get_value_cansleep(uc_data->pogo_ovp_en);
+	const bool pogo_ovp_en = uc_data->pogo_ovp_en_act_low ?
+				 (gpio_en == 0) : (gpio_en == 1);
+
+	/* return if pogo_ovp_en has been set */
+	if ((enabled && pogo_ovp_en) || (!enabled && !pogo_ovp_en))
+		return;
+
+	/* turn on/off pogo_ovp_en */
+	gpio_set_value_cansleep(uc_data->pogo_ovp_en, enabled ?
+				!uc_data->pogo_ovp_en_act_low :
+				uc_data->pogo_ovp_en_act_low);
+}
+
 /*
  * adjust *INSEL (only one source can be enabled at a given time)
  * NOTE: providing compatibility with input_suspend makes this more complex
@@ -889,15 +912,9 @@
 		/* turn off pogo_ovp */
 		if (uc_data->pogo_ovp_en > 0)
 			gpio_set_value_cansleep(uc_data->pogo_ovp_en, uc_data->pogo_ovp_en_act_low);
-	} else if (uc_data->dcin_is_dock && max77759_wcin_is_valid(data) && !cb_data->wlcin_off) {
+	} else if (cb_data->pogo_vin && !cb_data->wlcin_off) {
 		/* always disable USB when Dock is present */
 		insel_value &= ~MAX77759_CHG_CNFG_12_CHGINSEL;
-		/* b/232723240: charge over USB-C
-		 *              set to 1 for POGO_OVP_EN
-		 *              set to 0 for POGO_OVP_EN_L
-		 */
-		if (uc_data->pogo_ovp_en > 0)
-			gpio_set_value_cansleep(uc_data->pogo_ovp_en, !uc_data->pogo_ovp_en_act_low);
 		insel_value |= MAX77759_CHG_CNFG_12_WCINSEL;
 	}
 
@@ -920,6 +937,9 @@
 	/* changing [CHGIN|WCIN]_INSEL: works when protection is disabled  */
 	ret = max77759_chg_insel_write(uc_data->client, insel_mask, insel_value);
 
+	if (uc_data->pogo_ovp_en > 0)
+		max77759_set_pogo_ovp_en(uc_data, cb_data->pogo_vin);
+
 	pr_debug("%s: usecase=%d->%d mask=%x insel=%x wlc_on=%d force_wlc=%d (%d)\n",
 		 __func__, from_uc, use_case, insel_mask, insel_value, wlc_on,
 		 force_wlc, ret);
@@ -1059,7 +1079,7 @@
 	       !cb_data.chgr_on && !cb_data.buck_on && ! cb_data.boost_on &&
 	       !cb_data.otg_on && !cb_data.uno_on && !cb_data.wlc_tx &&
 	       !cb_data.wlc_rx && !cb_data.wlcin_off && !cb_data.chgin_off &&
-	       !cb_data.usb_wlc && !cb_data.pogo_vout;
+	       !cb_data.usb_wlc && !cb_data.pogo_vout && !cb_data.pogo_vin;
 	if (nope) {
 		pr_debug("%s: nope callback\n", __func__);
 		goto unlock_done;
@@ -1067,12 +1087,13 @@
 
 	dev_info(data->dev, "%s:%s full=%d raw=%d stby_on=%d, dc_on=%d, chgr_on=%d, buck_on=%d,"
 		" boost_on=%d, otg_on=%d, uno_on=%d wlc_tx=%d wlc_rx=%d usb_wlc=%d"
-		" chgin_off=%d wlcin_off=%d frs_on=%d pogo_vout=%d\n",
+		" chgin_off=%d wlcin_off=%d frs_on=%d pogo_vout=%d pogo_vin=%d\n",
 		__func__, trigger ? trigger : "<>",
 		data->charge_done, cb_data.use_raw, cb_data.stby_on, cb_data.dc_on,
 		cb_data.chgr_on, cb_data.buck_on, cb_data.boost_on, cb_data.otg_on,
 		cb_data.uno_on, cb_data.wlc_tx, cb_data.wlc_rx, cb_data.usb_wlc,
-		cb_data.chgin_off, cb_data.wlcin_off, cb_data.frs_on, cb_data.pogo_vout);
+		cb_data.chgin_off, cb_data.wlcin_off, cb_data.frs_on, cb_data.pogo_vout,
+		cb_data.pogo_vin);
 
 	/* just use raw "as is", no changes to switches etc */
 	if (cb_data.use_raw) {
diff --git a/pca9468_gbms_pps.c b/pca9468_gbms_pps.c
index 5960269..98c0bab 100644
--- a/pca9468_gbms_pps.c
+++ b/pca9468_gbms_pps.c
@@ -144,7 +144,7 @@
 	}
 
 	/* not needed if tcpm-power-supply is not there */
-	ret = pps_init(&pca9468->pps_data, pca9468->dev, tcpm_psy);
+	ret = pps_init(&pca9468->pps_data, pca9468->dev, tcpm_psy, "pca-pps");
 	if (ret == 0) {
 		pps_set_logbuffer(&pca9468->pps_data, pca9468->log);
 		pps_init_state(&pca9468->pps_data);