mainboard/intel/avenuecity_crb: Update full IIO configuration
[coreboot2.git] / src / mainboard / google / oak / mainboard.c
blob55ef91aad13f57b4b054af562132c4707acafd4f
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <boardid.h>
4 #include <bootmode.h>
5 #include <console/console.h>
6 #include <delay.h>
7 #include <device/device.h>
8 #include <drivers/parade/ps8640/ps8640.h>
9 #include <edid.h>
10 #include <gpio.h>
11 #include <soc/da9212.h>
12 #include <soc/ddp.h>
13 #include <soc/dsi.h>
14 #include <soc/i2c.h>
15 #include <soc/mt6311.h>
16 #include <soc/mt6391.h>
17 #include <soc/mtcmos.h>
18 #include <soc/pll.h>
19 #include <soc/usb.h>
20 #include <framebuffer_info.h>
22 enum {
23 CODEC_I2C_BUS = 0,
24 EXT_BUCK_I2C_BUS = 1,
27 static void configure_ext_buck(void)
29 mtk_i2c_bus_init(EXT_BUCK_I2C_BUS);
31 switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT) {
32 case 3:
33 case 4:
34 /* rev-3 and rev-4 use mt6311 as external buck */
35 gpio_output(GPIO(EINT15), 1);
36 udelay(500);
37 mt6311_probe(EXT_BUCK_I2C_BUS);
38 break;
39 case 2:
40 default:
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);
46 break;
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);
55 udelay(500);
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 */
67 mdelay(1);
68 /* vcama set to 1.8V */
69 mt6391_configure_ldo(LDO_VCAMA, LDO_1P8);
71 /* reset ALC5676 */
72 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 5)
73 gpio_output(GPIO(LCM_RST), 1);
75 /* SoC I2S */
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) {
85 case 2:
86 case 3:
87 case 4:
88 mt6391_gpio_output(MT6391_KP_COL5, 1);
89 break;
90 case 5:
91 case 6:
92 gpio_set_mode(GPIO(UCTS0), PAD_UCTS0_FUNC_I2S2_DI_1);
93 mt6391_gpio_output(MT6391_KP_COL5, 1);
94 break;
95 default:
96 break;
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)
108 setup_usb_host();
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) {
144 case 3:
145 gpio_output(GPIO(UCTS2), 0);
146 break;
147 case 4:
148 gpio_output(GPIO(SRCLKENAI), 0);
149 break;
150 default:
151 gpio_output(GPIO(UTXD2), 0);
152 break;
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);
169 else
170 gpio_output(GPIO(URTS2), 1);
171 /* delay 2ms for vgp2 and PS8640_1V2_ENABLE stable */
172 mdelay(2);
173 /* PS8640_PDN */
174 if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 4)
175 gpio_output(GPIO(LCM_RST), 1);
176 else
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 */
181 udelay(100);
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) {
189 i2c_bus = 0;
190 i2c_addr = 0x8;
191 } else {
192 i2c_bus = 4;
193 i2c_addr = 0x18;
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");
201 return -1;
204 return 0;
207 static void display_startup(void)
209 struct edid edid;
210 int ret;
211 u32 mipi_dsi_flags;
213 if (read_edid_from_ps8640(&edid) < 0)
214 return;
216 mipi_dsi_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE;
217 edid_set_framebuffer_bits_per_pixel(&edid, 32, 0);
219 mtk_ddp_init();
220 ret = mtk_dsi_init(mipi_dsi_flags, MIPI_DSI_FMT_RGB888, 4, &edid, NULL);
221 if (ret < 0) {
222 printk(BIOS_ERR, "dsi init fail\n");
223 return;
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 */
241 configure_audio();
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();
249 configure_display();
250 display_startup();
251 } else {
252 printk(BIOS_INFO, "Skipping display init.\n");
254 configure_usb();
255 configure_usb_hub();
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,