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