google/chromeec: Revise parameters of EC USB PD API call

This patch adds voltage and curent parameters in
google_chromeec_get_usb_pd_power_info and remove power parameter. Caller could
use the voltage and current information to calculate charger power rating.
The reason for this change is, some applications need the voltage information
to calculate correct system power eg PsysPmax.

BUG=b:151972149
TEST=emerge-puff coreboot; emerge-fizz coreboot

Change-Id: I11efe6f45f2f929fcb2763d192268e677d7426cb
Signed-off-by: Gaggery Tsai <gaggery.tsai@intel.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/39849
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c
index 17e110c..73baec6 100644
--- a/src/ec/google/chromeec/ec.c
+++ b/src/ec/google/chromeec/ec.c
@@ -1120,9 +1120,9 @@
 	return google_chromeec_command(&cmd);
 }
 
-/* Get charger power info in Watts.  Also returns type of charger */
+/* Get charger voltage and current.  Also returns type of charger */
 int google_chromeec_get_usb_pd_power_info(enum usb_chg_type *type,
-					  uint32_t *max_watts)
+					  uint16_t *current_max, uint16_t *voltage_max)
 {
 	struct ec_params_usb_pd_power_info params = {
 		.port = PD_POWER_CHARGING_PORT,
@@ -1147,8 +1147,8 @@
 	/* values are given in milliAmps and milliVolts */
 	*type = resp.type;
 	m = resp.meas;
-	*max_watts = (m.current_max * m.voltage_max) / 1000000;
-
+	*voltage_max = m.voltage_max;
+	*current_max = m.current_max;
 	return 0;
 }
 
diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h
index 13e3bd9..64d7e52 100644
--- a/src/ec/google/chromeec/ec.h
+++ b/src/ec/google/chromeec/ec.h
@@ -102,11 +102,12 @@
  * Retrieve the charger type and max wattage.
  *
  * @param type      charger type
- * @param max_watts charger max wattage
+ * @param current_max charger max current
+ * @param voltage_max charger max voltage
  * @return non-zero for error, otherwise 0.
  */
 int google_chromeec_get_usb_pd_power_info(enum usb_chg_type *type,
-					  uint32_t *max_watts);
+					  uint16_t *current_max, uint16_t *voltage_max);
 
 /*
  * Set max current and voltage of a dedicated charger.
diff --git a/src/mainboard/google/fizz/mainboard.c b/src/mainboard/google/fizz/mainboard.c
index daf9da4..9f35411 100644
--- a/src/mainboard/google/fizz/mainboard.c
+++ b/src/mainboard/google/fizz/mainboard.c
@@ -104,8 +104,9 @@
 {
 	enum usb_chg_type type;
 	u32 watts;
+	u16 volts_mv, current_ma;
 	u32 pl2, psyspl2;
-	int rv = google_chromeec_get_usb_pd_power_info(&type, &watts);
+	int rv = google_chromeec_get_usb_pd_power_info(&type, &current_ma, &volts_mv);
 	uint8_t sku = board_sku_id();
 	const uint32_t u42_mask = (1 << FIZZ_SKU_ID_I7_U42) |
 				  (1 << FIZZ_SKU_ID_I5_U42) |
@@ -126,6 +127,7 @@
 			psyspl2 = FIZZ_PSYSPL2_U42;
 	} else {
 		/* Detected TypeC.  Base on max value of adapter */
+		watts = ((u32)volts_mv * current_ma) / 1000000;
 		psyspl2 = watts;
 		conf->tdp_psyspl3 = SET_PSYSPL2(psyspl2);
 		/* set max possible time window */
diff --git a/src/mainboard/google/hatch/variants/puff/mainboard.c b/src/mainboard/google/hatch/variants/puff/mainboard.c
index e8098b9..3f74c96 100644
--- a/src/mainboard/google/hatch/variants/puff/mainboard.c
+++ b/src/mainboard/google/hatch/variants/puff/mainboard.c
@@ -90,8 +90,9 @@
 {
 	enum usb_chg_type type;
 	u32 watts;
+	u16 volts_mv, current_ma;
 	u32 psyspl2 = PUFF_PSYSPL2; // default barrel jack value for U22
-	int rv = google_chromeec_get_usb_pd_power_info(&type, &watts);
+	int rv = google_chromeec_get_usb_pd_power_info(&type, &current_ma, &volts_mv);
 
 	/* use SoC default value for PsysPL3 and PL4 unless we're on USB-PD*/
 	conf->tdp_psyspl3 = 0;
@@ -99,6 +100,7 @@
 
 	if (rv == 0 && type == USB_CHG_TYPE_PD) {
 		/* Detected USB-PD.  Base on max value of adapter */
+		watts = ((u32)current_ma * volts_mv) / 1000000;
 		psyspl2 = watts;
 		conf->tdp_psyspl3 = SET_PSYSPL2(psyspl2);
 		/* set max possible time window */