coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mainboard.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <boardid.h>
4 #include <bootmode.h>
5 #include <console/console.h>
6 #include <delay.h>
7 #include <device/device.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>
21 
22 enum {
25 };
26 
27 static void configure_ext_buck(void)
28 {
30 
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);
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 */
46  break;
47  }
48 }
49 
50 static void configure_touchscreen(void)
51 {
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);
57  }
58 }
59 
60 static void configure_audio(void)
61 {
63 
64  /* vgp1 set to 1.8V */
66  /* delay 1ms for realtek's power sequence request */
67  mdelay(1);
68  /* vcama set to 1.8V */
70 
71  /* reset ALC5676 */
72  if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 5)
73  gpio_output(GPIO(LCM_RST), 1);
74 
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 */
83 
84  switch (board_id() + CONFIG_BOARD_ID_ADJUSTMENT) {
85  case 2:
86  case 3:
87  case 4:
89  break;
90  case 5:
91  case 6:
92  gpio_set_mode(GPIO(UCTS0), PAD_UCTS0_FUNC_I2S2_DI_1);
94  break;
95  default:
96  break;
97  }
98 
99  /* Init i2c bus Timing register for audio codecs */
101 
102  /* set I2S clock to 48KHz */
103  mt_pll_set_aud_div(48 * KHz);
104 }
105 
106 static void configure_usb(void)
107 {
108  setup_usb_host();
109 
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));
120  }
121 
122  if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT > 4 &&
123  board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 7)
124  {
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));
129  }
130 }
131 
132 static void configure_usb_hub(void)
133 {
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);
137 }
138 
139 /* Setup backlight control pins as output pin and power-off by default */
140 static void configure_backlight(void)
141 {
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;
153  }
154 
155  gpio_output(GPIO(DISP_PWM0), 0); /* DISP_PWM0 */
156  gpio_output(GPIO(PCM_TX), 0); /* PANEL_POWER_EN */
157 }
158 
159 static void configure_display(void)
160 {
161  /* board from Rev2 */
162  gpio_output(GPIO(CMMCLK), 1); /* PANEL_3V3_ENABLE */
163  /* vgp2 set to 3.3V for ps8640 */
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);
182 }
183 
184 static int read_edid_from_ps8640(struct edid *edid)
185 {
186  u8 i2c_bus, i2c_addr;
187 
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;
194  }
195 
197 
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;
202  }
203 
204  return 0;
205 }
206 
207 static void display_startup(void)
208 {
209  struct edid edid;
210  int ret;
211  u32 mipi_dsi_flags;
212 
213  if (read_edid_from_ps8640(&edid) < 0)
214  return;
215 
218 
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;
224  }
225 
228 }
229 
230 static void mainboard_init(struct device *dev)
231 {
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.
234  */
235  if (board_id() + CONFIG_BOARD_ID_ADJUSTMENT < 5)
237 
238  /* Config SD card detection pin */
239  gpio_input_pullup(GPIO(EINT1)); /* SD_DET */
240 
241  configure_audio();
242 
243  /* fix dsi lp mode is half voltage attenuation */
245 
246  if (display_init_required()) {
250  display_startup();
251  } else {
252  printk(BIOS_INFO, "Skipping display init.\n");
253  }
254  configure_usb();
258 }
259 
260 static void mainboard_enable(struct device *dev)
261 {
262  dev->ops->init = &mainboard_init;
263 }
264 
267 };
struct chip_operations mainboard_ops
Definition: mainboard.c:19
int display_init_required(void)
Definition: bootmode.c:22
#define KHz
Definition: helpers.h:79
#define printk(level,...)
Definition: stdlib.h:16
void da9212_probe(uint8_t i2c_num)
Definition: da9212.c:53
void mdelay(unsigned int msecs)
Definition: delay.c:2
@ GPIO
Definition: chip.h:84
@ MIPI_DSI_FMT_RGB888
Definition: dsi_common.h:13
@ MIPI_DSI_MODE_VIDEO_SYNC_PULSE
Definition: dsi_common.h:25
@ MIPI_DSI_MODE_VIDEO
Definition: dsi_common.h:21
uint32_t board_id(void)
board_id() - Get the board version
Definition: ec_boardid.c:6
struct fb_info * fb_new_framebuffer_info_from_edid(const struct edid *edid, uintptr_t fb_addr)
Definition: edid_fill_fb.c:162
static void mainboard_init(struct device *dev)
Definition: mainboard.c:230
static void configure_usb_hub(void)
Definition: mainboard.c:132
static void configure_backlight(void)
Definition: mainboard.c:140
static void configure_audio(void)
Definition: mainboard.c:60
static void configure_touchscreen(void)
Definition: mainboard.c:50
static void configure_display(void)
Definition: mainboard.c:159
static int read_edid_from_ps8640(struct edid *edid)
Definition: mainboard.c:184
@ EXT_BUCK_I2C_BUS
Definition: mainboard.c:24
@ CODEC_I2C_BUS
Definition: mainboard.c:23
static void display_startup(void)
Definition: mainboard.c:207
static void configure_ext_buck(void)
Definition: mainboard.c:27
static void configure_usb(void)
Definition: mainboard.c:106
static void mainboard_enable(struct device *dev)
Definition: mainboard.c:260
void edid_set_framebuffer_bits_per_pixel(struct edid *edid, int fb_bpp, int row_byte_alignment)
Definition: edid.c:1667
void gpio_output(gpio_t gpio, int value)
Definition: gpio.c:194
void gpio_input_pullup(gpio_t gpio)
Definition: gpio.c:184
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
int mtk_dsi_init(u32 mode_flags, u32 format, u32 lanes, const struct edid *edid, const u8 *init_commands)
Definition: dsi.c:360
void setup_usb_host(void)
Definition: usb.c:153
void mtk_dsi_pin_drv_ctrl(void)
Definition: dsi.c:116
void mt6311_probe(uint8_t i2c_num)
Definition: mt6311.c:103
void mt6391_configure_ldo(enum ldo_power ldo, enum ldo_voltage vsel)
Definition: mt6391.c:46
@ MT6391_KP_ROW2
Definition: mt6391.h:332
@ MT6391_KP_COL4
Definition: mt6391.h:326
@ MT6391_KP_ROW4
Definition: mt6391.h:334
@ MT6391_KP_COL5
Definition: mt6391.h:327
@ MT6391_KP_ROW3
Definition: mt6391.h:333
@ LDO_1P8
Definition: mt6391.h:267
@ LDO_3P3
Definition: mt6391.h:271
void mt6391_gpio_output(u32 gpio, int value)
Definition: mt6391.c:574
@ LDO_VCAMD
Definition: mt6391.h:253
@ LDO_VCAMA
Definition: mt6391.h:260
@ LDO_VGP2
Definition: mt6391.h:254
void mtk_ddp_init(void)
Definition: ddp.c:61
void mtk_ddp_mode_set(const struct edid *edid)
Definition: ddp.c:66
void mt_pll_set_aud_div(u32 rate)
Definition: pll.c:386
void mtcmos_audio_power_on(void)
Definition: mtcmos.c:52
void mtcmos_display_power_on(void)
Definition: mtcmos.c:44
int ps8640_init(uint8_t bus, uint8_t chip)
Definition: ps8640.c:45
int ps8640_get_edid(uint8_t bus, uint8_t chip, struct edid *out)
Definition: ps8640.c:11
void gpio_set_mode(gpio_t gpio, int mode)
Definition: gpio.c:45
void mtk_i2c_bus_init(uint8_t bus)
Definition: i2c.c:65
static const uintptr_t i2c_bus[]
Definition: i2c.c:41
#define NULL
Definition: stddef.h:19
uint32_t u32
Definition: stdint.h:51
unsigned long uintptr_t
Definition: stdint.h:21
uint8_t u8
Definition: stdint.h:45
void(* enable_dev)(struct device *dev)
Definition: device.h:24
void(* init)(struct device *dev)
Definition: device.h:42
Definition: device.h:107
struct device_operations * ops
Definition: device.h:143
Definition: edid.h:49
Definition: i2c.c:65
void udelay(uint32_t us)
Definition: udelay.c:15