1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <console/console.h>
6 #include <device/device.h>
7 #include <device/mmio.h>
8 #include <drivers/analogix/anx7625/anx7625.h>
10 #include <framebuffer_info.h>
16 #include <soc/gpio_common.h>
19 #include <soc/mtcmos.h>
20 #include <soc/regulator.h>
26 #define MSDC0_BASE 0x11f60000
27 #define MSDC0_TOP_BASE 0x11f50000
29 #define MSDC0_DRV_MASK 0x3fffffff
30 #define MSDC1_DRV_MASK 0x3ffff000
31 #define MSDC0_DRV_VALUE 0x24924924
32 #define MSDC1_DRV_VALUE 0x1b6db000
34 #define MSDC1_GPIO_MODE0_BASE 0x10005360
35 #define MSDC1_GPIO_MODE0_MASK 0x77777000
36 #define MSDC1_GPIO_MODE0_VALUE 0x11111000
38 #define MSDC1_GPIO_MODE1_BASE 0x10005370
39 #define MSDC1_GPIO_MODE1_MASK 0x7
40 #define MSDC1_GPIO_MODE1_VALUE 0x1
43 #define GPIO_EDPBRDG_INT_ODL GPIO(EINT6) /* 6 */
44 #define GPIO_EDPBRDG_PWREN GPIO(DSI_TE) /* 41 */
45 #define GPIO_EDPBRDG_RST_ODL GPIO(LCM_RST) /* 42 */
46 #define GPIO_EN_PP3300_EDP_DX GPIO(PERIPHERAL_EN1) /* 127 */
47 #define GPIO_EN_PP1800_EDPBRDG_DX GPIO(PERIPHERAL_EN2) /* 128 */
48 #define GPIO_EN_PP1000_EDPBRDG GPIO(PERIPHERAL_EN3) /* 129 */
49 #define GPIO_EN_PP3300_DISPLAY_DX GPIO(CAM_CLK3) /* 136 */
50 #define GPIO_AP_EDP_BKLTEN GPIO(KPROW1) /* 152 */
51 #define GPIO_BL_PWM_1V8 GPIO(DISP_PWM) /* 40 */
53 /* Override hs_da_trail for ANX7625 */
54 void mtk_dsi_override_phy_timing(struct mtk_phy_timing
*timing
)
56 timing
->da_hs_trail
+= 9;
59 /* Set up backlight control pins as output pin and power-off by default */
60 static void configure_backlight_and_bridge(void)
62 /* Disable backlight before turning on bridge */
63 gpio_output(GPIO_AP_EDP_BKLTEN
, 0);
64 gpio_output(GPIO_BL_PWM_1V8
, 0);
65 gpio_output(GPIO_EN_PP3300_DISPLAY_DX
, 1);
68 gpio_output(GPIO_EDPBRDG_RST_ODL
, 0);
69 gpio_output(GPIO_EN_PP1000_EDPBRDG
, 1);
70 gpio_output(GPIO_EN_PP1800_EDPBRDG_DX
, 1);
71 gpio_output(GPIO_EN_PP3300_EDP_DX
, 1);
73 gpio_output(GPIO_EDPBRDG_PWREN
, 1);
75 gpio_output(GPIO_EDPBRDG_RST_ODL
, 1);
78 static bool configure_display(void)
83 printk(BIOS_INFO
, "%s: Starting display init\n", __func__
);
85 configure_backlight_and_bridge();
86 mtk_i2c_bus_init(i2c_bus
);
88 if (anx7625_init(i2c_bus
)) {
89 printk(BIOS_ERR
, "%s: Can't init ANX7625 bridge\n", __func__
);
93 if (anx7625_dp_get_edid(i2c_bus
, &edid
)) {
94 printk(BIOS_ERR
, "%s: Can't get panel's edid\n", __func__
);
98 const char *name
= edid
.ascii_string
;
100 name
= "unknown name";
101 printk(BIOS_INFO
, "%s: '%s %s' %dx%d@%dHz\n", __func__
,
102 edid
.manufacturer_name
, name
, edid
.mode
.ha
, edid
.mode
.va
,
105 mtcmos_display_power_on();
106 mtcmos_protect_display_bus();
108 edid_set_framebuffer_bits_per_pixel(&edid
, 32, 0);
110 u32 mipi_dsi_flags
= (MIPI_DSI_MODE_VIDEO
|
111 MIPI_DSI_MODE_VIDEO_SYNC_PULSE
|
113 MIPI_DSI_MODE_LINE_END
|
114 MIPI_DSI_MODE_EOT_PACKET
);
116 if (mtk_dsi_init(mipi_dsi_flags
, MIPI_DSI_FMT_RGB888
, 4, &edid
, NULL
) < 0) {
117 printk(BIOS_ERR
, "%s: Failed in DSI init\n", __func__
);
121 if (anx7625_dp_start(i2c_bus
, &edid
) < 0) {
122 printk(BIOS_ERR
, "%s: Can't start display via ANX7625\n", __func__
);
126 mtk_ddp_mode_set(&edid
);
127 fb_new_framebuffer_info_from_edid(&edid
, (uintptr_t)0);
131 static void configure_audio(void)
134 mtcmos_audio_power_on();
137 gpio_set_mode(GPIO(I2S3_MCK
), PAD_I2S3_MCK_FUNC_I2S3_MCK
);
138 gpio_set_mode(GPIO(I2S3_BCK
), PAD_I2S3_BCK_FUNC_I2S3_BCK
);
139 gpio_set_mode(GPIO(I2S3_LRCK
), PAD_I2S3_LRCK_FUNC_I2S3_LRCK
);
140 gpio_set_mode(GPIO(I2S3_DO
), PAD_I2S3_DO_FUNC_I2S3_DO
);
143 static void mainboard_init(struct device
*dev
)
145 mtk_msdc_configure_emmc(true);
146 mtk_msdc_configure_sdcard();
150 if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE
))
151 register_reset_to_bl31(GPIO_RESET
.id
, true);
154 printk(BIOS_ERR
, "dpm init fail, system can't do DVFS switch\n");
157 printk(BIOS_ERR
, "spm init fail, system suspend may stuck\n");
159 if (display_init_required())
162 printk(BIOS_INFO
, "%s: Skipped display init\n", __func__
);
165 static void mainboard_enable(struct device
*dev
)
167 dev
->ops
->init
= &mainboard_init
;
170 struct chip_operations mainboard_ops
= {
171 .enable_dev
= mainboard_enable
,