mb/google/geralt: Set +-5.7V to TPS65132s EEPROM

It is necessary to increase the AVDD/AVEE of TPS65132s PMIC to +-5.7V
for powering on BOE_TV110C9M_LL0. So we set the default value to +-5.7V
and program the value to the EEPROM when configuring the display at the
first time. In this way, TPS65132s could load the correct setting from
the EEPROM after booting into kernel.

BUG=b:268292556
TEST=test firmware display pass and AVDD/AVEE is +-5.7V on Geralt.

Change-Id: I29236818444cac84d42386a371cd8934048ff948
Signed-off-by: yangcong <yangcong5@huaqin.corp-partner.google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/73443
Reviewed-by: Rex-BC Chen <rex-bc.chen@mediatek.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Reviewed-by: Yidi Lin <yidilin@google.com>
diff --git a/src/mainboard/google/geralt/display.c b/src/mainboard/google/geralt/display.c
index bbdd808..243ed6d 100644
--- a/src/mainboard/google/geralt/display.c
+++ b/src/mainboard/google/geralt/display.c
@@ -3,6 +3,7 @@
 #include <assert.h>
 #include <console/console.h>
 #include <delay.h>
+#include <device/i2c_simple.h>
 #include <edid.h>
 #include <framebuffer_info.h>
 #include <gpio.h>
@@ -10,11 +11,16 @@
 #include <soc/dptx.h>
 #include <soc/dsi.h>
 #include <soc/gpio_common.h>
+#include <soc/i2c.h>
 #include <soc/mtcmos.h>
 
 #include "display.h"
+#include "gpio.h"
 #include "panel.h"
 
+#define PMIC_TPS65132_I2C	I2C3
+#define PMIC_TPS65132_SLAVE	0x3E
+
 int configure_display(void)
 {
 	struct edid edid;
@@ -72,3 +78,44 @@
 
 	return 0;
 }
+
+void tps65132s_program_eeprom(void)
+{
+	u8 value = 0;
+	u8 value1 = 0;
+
+	/* Initialize I2C3 for PMIC TPS65132 */
+	mtk_i2c_bus_init(PMIC_TPS65132_I2C, I2C_SPEED_FAST);
+	mdelay(10);
+
+	gpio_output(GPIO_EN_PPVAR_MIPI_DISP, 1);
+	gpio_output(GPIO_EN_PPVAR_MIPI_DISP_150MA, 1);
+	mdelay(10);
+
+	i2c_read_field(PMIC_TPS65132_I2C, PMIC_TPS65132_SLAVE, 0x00, &value, 0xFF, 0);
+	i2c_read_field(PMIC_TPS65132_I2C, PMIC_TPS65132_SLAVE, 0x01, &value1, 0xFF, 0);
+
+	if (value != 0x11 || value1 != 0x11) {
+		printk(BIOS_INFO, "Just set AVDD AVEE 5.7V to EEPROM Data in first time.\n");
+
+		/* Set AVDD = 5.7V */
+		if (panel_pmic_reg_mask(PMIC_TPS65132_I2C, PMIC_TPS65132_SLAVE, 0x00, 0x11,
+					0x1F) < 0)
+			return;
+
+		/* Set AVEE = -5.7V */
+		if (panel_pmic_reg_mask(PMIC_TPS65132_I2C, PMIC_TPS65132_SLAVE, 0x01, 0x11,
+					0x1F) < 0)
+			return;
+
+		/* Set EEPROM Data */
+		if (panel_pmic_reg_mask(PMIC_TPS65132_I2C, PMIC_TPS65132_SLAVE, 0xFF, 0x80,
+					0xFC) < 0)
+			return;
+		mdelay(50);
+	}
+
+	gpio_output(GPIO_EN_PPVAR_MIPI_DISP, 0);
+	gpio_output(GPIO_EN_PPVAR_MIPI_DISP_150MA, 0);
+	mdelay(5);
+}
diff --git a/src/mainboard/google/geralt/display.h b/src/mainboard/google/geralt/display.h
index 29153b3..71e0e08 100644
--- a/src/mainboard/google/geralt/display.h
+++ b/src/mainboard/google/geralt/display.h
@@ -4,5 +4,6 @@
 #define __MAINBOARD_GOOGLE_GERALT_DISPLAY_H__
 
 int configure_display(void);
+void tps65132s_program_eeprom(void);
 
 #endif
diff --git a/src/mainboard/google/geralt/panel_geralt.c b/src/mainboard/google/geralt/panel_geralt.c
index 2991360..7828651 100644
--- a/src/mainboard/google/geralt/panel_geralt.c
+++ b/src/mainboard/google/geralt/panel_geralt.c
@@ -11,11 +11,10 @@
 #include <soc/pmif.h>
 #include <string.h>
 
+#include "display.h"
 #include "gpio.h"
 #include "panel.h"
 
-#define PMIC_TPS65132_I2C	I2C3
-#define PMIC_TPS65132_SLAVE	0x3E
 
 static void configure_mipi_pwm_backlight(void)
 {
@@ -30,28 +29,17 @@
 
 static void power_on_mipi_boe_tv110c9m_ll0(void)
 {
+	tps65132s_program_eeprom();
+
 	/* Enable VM18V */
 	mainboard_enable_regulator(MTK_REGULATOR_VDD18, true);
 
-	/* Initialize I2C3 for PMIC TPS65132 */
-	mtk_i2c_bus_init(PMIC_TPS65132_I2C, I2C_SPEED_FAST);
-	mdelay(10);
-
 	gpio_output(GPIO_DISP_RST_1V8_L, 0);
 	mdelay(1);
 
 	gpio_output(GPIO_EN_PPVAR_MIPI_DISP, 1);
 	gpio_output(GPIO_EN_PPVAR_MIPI_DISP_150MA, 1);
 	mdelay(10);
-
-	/* Set AVDD = 5.7V */
-	if (panel_pmic_reg_mask(PMIC_TPS65132_I2C, PMIC_TPS65132_SLAVE, 0x00, 0x11, 0x1F) < 0)
-		return;
-
-	/* Set AVEE = -5.7V */
-	if (panel_pmic_reg_mask(PMIC_TPS65132_I2C, PMIC_TPS65132_SLAVE, 0x01, 0x11, 0x1F) < 0)
-		return;
-
 	gpio_output(GPIO_DISP_RST_1V8_L, 1);
 	mdelay(1);
 	gpio_output(GPIO_DISP_RST_1V8_L, 0);