mainboard/intel/avenuecity_crb: Update full IIO configuration
[coreboot2.git] / src / mainboard / google / asurada / mainboard.c
blob2da9719a193ce6231f1cb3858ec2015c9464af5b
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <bootmode.h>
4 #include <console/console.h>
5 #include <delay.h>
6 #include <device/device.h>
7 #include <device/mmio.h>
8 #include <drivers/analogix/anx7625/anx7625.h>
9 #include <edid.h>
10 #include <framebuffer_info.h>
11 #include <gpio.h>
12 #include <soc/bl31.h>
13 #include <soc/ddp.h>
14 #include <soc/dpm.h>
15 #include <soc/dsi.h>
16 #include <soc/gpio_common.h>
17 #include <soc/i2c.h>
18 #include <soc/msdc.h>
19 #include <soc/mtcmos.h>
20 #include <soc/regulator.h>
21 #include <soc/spm.h>
22 #include <soc/usb.h>
24 #include "gpio.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
42 /* GPIO names */
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);
67 /* Turn on bridge */
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);
72 mdelay(14);
73 gpio_output(GPIO_EDPBRDG_PWREN, 1);
74 mdelay(10);
75 gpio_output(GPIO_EDPBRDG_RST_ODL, 1);
78 static bool configure_display(void)
80 struct edid edid;
81 const u8 i2c_bus = 3;
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__);
90 return false;
93 if (anx7625_dp_get_edid(i2c_bus, &edid)) {
94 printk(BIOS_ERR, "%s: Can't get panel's edid\n", __func__);
95 return false;
98 const char *name = edid.ascii_string;
99 if (name[0] == '\0')
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,
103 edid.mode.refresh);
105 mtcmos_display_power_on();
106 mtcmos_protect_display_bus();
108 edid_set_framebuffer_bits_per_pixel(&edid, 32, 0);
109 mtk_ddp_init();
110 u32 mipi_dsi_flags = (MIPI_DSI_MODE_VIDEO |
111 MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
112 MIPI_DSI_MODE_LPM |
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__);
118 return false;
121 if (anx7625_dp_start(i2c_bus, &edid) < 0) {
122 printk(BIOS_ERR, "%s: Can't start display via ANX7625\n", __func__);
123 return false;
126 mtk_ddp_mode_set(&edid);
127 fb_new_framebuffer_info_from_edid(&edid, (uintptr_t)0);
128 return true;
131 static void configure_audio(void)
133 /* Audio PWR */
134 mtcmos_audio_power_on();
136 /* SoC I2S */
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();
147 configure_audio();
148 setup_usb_host();
150 if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE))
151 register_reset_to_bl31(GPIO_RESET.id, true);
153 if (dpm_init())
154 printk(BIOS_ERR, "dpm init fail, system can't do DVFS switch\n");
156 if (spm_init())
157 printk(BIOS_ERR, "spm init fail, system suspend may stuck\n");
159 if (display_init_required())
160 configure_display();
161 else
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,