1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <boardid.h>
4 #include <cbfs.h>
5 #include <console/console.h>
6 #include <delay.h>
7 #include <gpio.h>
8 #include <identity.h>
9 #include <soc/gpio_common.h>
10 #include <soc/i2c.h>
11 #include <soc/pmif.h>
12 #include <soc/regulator.h>
13
14 #include "gpio.h"
15 #include "panel.h"
16
get_panel_description(uint32_t panel_id)17 struct panel_description __weak *get_panel_description(uint32_t panel_id)
18 {
19 printk(BIOS_WARNING, "%s: %s: the panel configuration is not ready\n",
20 __func__, mainboard_part_number);
21 return NULL;
22 }
23
get_active_panel(void)24 struct panel_description *get_active_panel(void)
25 {
26 uint32_t active_panel_id = panel_id();
27 return get_panel_description(active_panel_id);
28 }
29
configure_mipi_pwm_backlight(void)30 void configure_mipi_pwm_backlight(void)
31 {
32 gpio_output(GPIO_AP_DISP_BKLTEN, 0);
33 gpio_output(GPIO_MIPI_BL_PWM_1V8, 0);
34 }
35
fill_lp_backlight_gpios(struct lb_gpios * gpios)36 void fill_lp_backlight_gpios(struct lb_gpios *gpios)
37 {
38 struct panel_description *panel = get_active_panel();
39 if (!panel || panel->disp_path == DISP_PATH_NONE)
40 return;
41
42 struct lb_gpio mipi_pwm_gpios[] = {
43 {GPIO_MIPI_BL_PWM_1V8.id, ACTIVE_HIGH, -1, "PWM control"},
44 };
45
46 struct lb_gpio edp_pwm_gpios[] = {
47 {GPIO_EDP_BL_PWM_1V8.id, ACTIVE_HIGH, -1, "PWM control"},
48 };
49
50 if (panel->pwm_ctrl_gpio) {
51 /* PWM control for typical eDP and MIPI panels */
52 if (panel->disp_path == DISP_PATH_MIPI)
53 lb_add_gpios(gpios, mipi_pwm_gpios, ARRAY_SIZE(mipi_pwm_gpios));
54 else
55 lb_add_gpios(gpios, edp_pwm_gpios, ARRAY_SIZE(edp_pwm_gpios));
56 }
57
58 struct lb_gpio backlight_gpios[] = {
59 {GPIO_AP_DISP_BKLTEN.id, ACTIVE_HIGH, -1, "backlight enable"},
60 };
61
62 lb_add_gpios(gpios, backlight_gpios, ARRAY_SIZE(backlight_gpios));
63 }
64
power_on_mipi_panel(const struct tps65132s_cfg * cfg)65 void power_on_mipi_panel(const struct tps65132s_cfg *cfg)
66 {
67 mtk_i2c_bus_init(cfg->i2c_bus, I2C_SPEED_FAST);
68
69 /* Enable VM18V */
70 mainboard_enable_regulator(MTK_REGULATOR_VDD18, true);
71 mdelay(2);
72 if (tps65132s_setup(cfg) != CB_SUCCESS)
73 printk(BIOS_ERR, "Failed to set up voltage regulator tps65132s\n");
74 gpio_output(GPIO_DISP_RST_1V8_L, 0);
75 mdelay(1);
76 gpio_output(GPIO_DISP_RST_1V8_L, 1);
77 mdelay(1);
78 gpio_output(GPIO_DISP_RST_1V8_L, 0);
79 mdelay(1);
80 gpio_output(GPIO_DISP_RST_1V8_L, 1);
81 mdelay(6);
82 }
83