1 /* SPDX-License-Identifier: GPL-2.0-only */
5 #include <console/console.h>
7 #include <device/device.h>
8 #include <drivers/parade/ps8640/ps8640.h>
11 #include <soc/da9212.h>
15 #include <soc/mt6311.h>
16 #include <soc/mt6391.h>
17 #include <soc/mtcmos.h>
20 #include <framebuffer_info.h>
27 static void configure_ext_buck(void)
29 mtk_i2c_bus_init(EXT_BUCK_I2C_BUS
);
31 switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
) {
34 /* rev-3 and rev-4 use mt6311 as external buck */
35 gpio_output(GPIO(EINT15
), 1);
37 mt6311_probe(EXT_BUCK_I2C_BUS
);
41 /* rev-2 and rev-5 use da9212 as external buck */
42 mt6391_gpio_output(MT6391_KP_ROW3
, 1); /* DA9212_IC_EN */
43 mt6391_gpio_output(MT6391_KP_ROW4
, 1); /* DA9212_EN_A */
44 udelay(500); /* add 500us delay for powering on da9212 */
45 da9212_probe(EXT_BUCK_I2C_BUS
);
50 static void configure_touchscreen(void)
52 /* Pull low reset gpio for 500us and then pull high */
53 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
>= 7) {
54 gpio_output(GPIO(PCM_SYNC
), 0);
56 gpio_output(GPIO(PCM_SYNC
), 1);
60 static void configure_audio(void)
62 mtcmos_audio_power_on();
64 /* vgp1 set to 1.8V */
65 mt6391_configure_ldo(LDO_VCAMD
, LDO_1P8
);
66 /* delay 1ms for realtek's power sequence request */
68 /* vcama set to 1.8V */
69 mt6391_configure_ldo(LDO_VCAMA
, LDO_1P8
);
72 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
< 5)
73 gpio_output(GPIO(LCM_RST
), 1);
76 gpio_set_mode(GPIO(I2S0_LRCK
), PAD_I2S0_LRCK_FUNC_I2S1_WS
);
77 gpio_set_mode(GPIO(I2S0_BCK
), PAD_I2S0_BCK_FUNC_I2S1_BCK
);
78 gpio_set_mode(GPIO(I2S0_MCK
), PAD_I2S0_MCK_FUNC_I2S1_MCK
);
79 gpio_set_mode(GPIO(I2S0_DATA0
), PAD_I2S0_DATA0_FUNC_I2S1_DO_1
);
80 gpio_set_mode(GPIO(I2S0_DATA1
), PAD_I2S0_DATA1_FUNC_I2S2_DI_2
);
81 /* codec ext MCLK ON */
82 mt6391_gpio_output(MT6391_KP_COL4
, 1);
84 switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
) {
88 mt6391_gpio_output(MT6391_KP_COL5
, 1);
92 gpio_set_mode(GPIO(UCTS0
), PAD_UCTS0_FUNC_I2S2_DI_1
);
93 mt6391_gpio_output(MT6391_KP_COL5
, 1);
99 /* Init i2c bus Timing register for audio codecs */
100 mtk_i2c_bus_init(CODEC_I2C_BUS
);
102 /* set I2S clock to 48KHz */
103 mt_pll_set_aud_div(48 * KHz
);
106 static void configure_usb(void)
110 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
> 3) {
111 /* Type C port 0 Over current alert pin */
112 gpio_input_pullup(GPIO(MSDC3_DSL
));
113 /* Enable USB3 type A port 0 5V load switch */
114 gpio_output(GPIO(CM2MCLK
), 1);
115 /* USB3 Type A port 0 power over current alert pin */
116 gpio_input_pullup(GPIO(CMPCLK
));
117 /* Type C port 1 over current alert pin */
118 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
< 7)
119 gpio_input_pullup(GPIO(PCM_SYNC
));
122 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
> 4 &&
123 board_id() + CONFIG_BOARD_ID_ADJUSTMENT
< 7)
125 /* USB 2.0 type A port over current interrupt pin(low active) */
126 gpio_input_pullup(GPIO(UCTS2
));
127 /* USB 2.0 type A port BC1.2 STATUS(low active) */
128 gpio_input_pullup(GPIO(AUD_DAT_MISO
));
132 static void configure_usb_hub(void)
134 /* set USB hub reset pin (low active) to high */
135 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
> 4)
136 gpio_output(GPIO(UTXD3
), 1);
139 /* Setup backlight control pins as output pin and power-off by default */
140 static void configure_backlight(void)
142 /* Configure PANEL_LCD_POWER_EN */
143 switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
) {
145 gpio_output(GPIO(UCTS2
), 0);
148 gpio_output(GPIO(SRCLKENAI
), 0);
151 gpio_output(GPIO(UTXD2
), 0);
155 gpio_output(GPIO(DISP_PWM0
), 0); /* DISP_PWM0 */
156 gpio_output(GPIO(PCM_TX
), 0); /* PANEL_POWER_EN */
159 static void configure_display(void)
161 /* board from Rev2 */
162 gpio_output(GPIO(CMMCLK
), 1); /* PANEL_3V3_ENABLE */
163 /* vgp2 set to 3.3V for ps8640 */
164 mt6391_configure_ldo(LDO_VGP2
, LDO_3P3
);
165 gpio_output(GPIO(URTS0
), 0); /* PS8640_SYSRSTN */
166 /* PS8640_1V2_ENABLE */
167 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
== 4)
168 gpio_output(GPIO(SRCLKENAI2
), 1);
170 gpio_output(GPIO(URTS2
), 1);
171 /* delay 2ms for vgp2 and PS8640_1V2_ENABLE stable */
174 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
> 4)
175 gpio_output(GPIO(LCM_RST
), 1);
177 gpio_output(GPIO(UCTS0
), 1);
178 gpio_output(GPIO(PCM_CLK
), 1); /* PS8640_MODE_CONF */
179 gpio_output(GPIO(URTS0
), 1); /* PS8640_SYSRSTN */
180 /* for level shift(1.8V to 3.3V) on */
184 static int read_edid_from_ps8640(struct edid
*edid
)
186 u8 i2c_bus
, i2c_addr
;
188 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
> 6) {
196 mtk_i2c_bus_init(i2c_bus
);
198 ps8640_init(i2c_bus
, i2c_addr
);
199 if (ps8640_get_edid(i2c_bus
, i2c_addr
, edid
)) {
200 printk(BIOS_ERR
, "Can't get panel's edid\n");
207 static void display_startup(void)
213 if (read_edid_from_ps8640(&edid
) < 0)
216 mipi_dsi_flags
= MIPI_DSI_MODE_VIDEO
| MIPI_DSI_MODE_VIDEO_SYNC_PULSE
;
217 edid_set_framebuffer_bits_per_pixel(&edid
, 32, 0);
220 ret
= mtk_dsi_init(mipi_dsi_flags
, MIPI_DSI_FMT_RGB888
, 4, &edid
, NULL
);
222 printk(BIOS_ERR
, "dsi init fail\n");
226 mtk_ddp_mode_set(&edid
);
227 fb_new_framebuffer_info_from_edid(&edid
, (uintptr_t)0);
230 static void mainboard_init(struct device
*dev
)
232 /* TP_SHIFT_EN: Enables the level shifter for I2C bus 4 (TPAD), which
233 * also contains the PS8640 eDP bridge and the USB hub.
235 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT
< 5)
236 mt6391_gpio_output(MT6391_KP_ROW2
, 1);
238 /* Config SD card detection pin */
239 gpio_input_pullup(GPIO(EINT1
)); /* SD_DET */
243 /* fix dsi lp mode is half voltage attenuation */
244 mtk_dsi_pin_drv_ctrl();
246 if (display_init_required()) {
247 mtcmos_display_power_on();
248 configure_backlight();
252 printk(BIOS_INFO
, "Skipping display init.\n");
256 configure_ext_buck();
257 configure_touchscreen();
260 static void mainboard_enable(struct device
*dev
)
262 dev
->ops
->init
= &mainboard_init
;
265 struct chip_operations mainboard_ops
= {
266 .enable_dev
= mainboard_enable
,