coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
gpio_init.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <soc/gpio.h>
5 #include <soc/mipi.h>
6 
7 /*
8  * GPIO 47-56 are controlled by MIPI register by default.
9  * When they are used as GPI, we have to set IES of MIPI register to 1.
10  * Additionally, pulls of these pins are controlled by MIPI,
11  * and pull-setting of these pins are forbidden in our driver.
12  */
13 static void set_gpi_from_mipi(void)
14 {
16  1 << 0 | /* RG_MIPI_GPI0_IES GPI47 */
17  1 << 6 | /* RG_MIPI_GPI1_IES GPI48 */
18  1 << 12 | /* RG_MIPI_GPI2_IES GPI49 */
19  1 << 18 | /* RG_MIPI_GPI3_IES GPI50 */
20  1 << 24); /* RF_MIPI_GPI4_IES GPI51 */
21 
23  1 << 0 | /* RG_MIPI_GPI5_IES GPI52 */
24  1 << 6 | /* RG_MIPI_GPI6_IES GPI53 */
25  1 << 12 | /* RG_MIPI_GPI7_IES GPI54 */
26  1 << 18 | /* RG_MIPI_GPI8_IES GPI55 */
27  1 << 24); /* RF_MIPI_GPI9_IES GPI56 */
28 }
29 
30 /*
31  * overwrite the T/RDSEL default value of exmd_ctrl and
32  * msdc2_ctrl5 as b'1010
33  */
34 static void gpio_set_duty(enum external_power ext_power)
35 {
36  /* EXMD control reg */
37  if (ext_power == GPIO_EINT_1P8V) {
38  /* exmd_ctrl[9:4] = b`000000, [3:0] = b`1010 */
39  write16(&mtk_gpio->exmd_ctrl[0].rst, 0x3F5);
40  write16(&mtk_gpio->exmd_ctrl[0].set, 0xA);
41  } else if (ext_power == GPIO_EINT_3P3V) {
42  /* exmd_ctrl[9:4] = b`001100, [3:0] = b`1010 */
43  write16(&mtk_gpio->exmd_ctrl[0].rst, 0x335);
44  write16(&mtk_gpio->exmd_ctrl[0].set, 0xCA);
45  }
46 
47  /* other R/TDSEL */
48  /* msdc2_ctrl5, bit[3:0] = b`1010 */
51 }
52 
53 void gpio_init(enum external_power ext_power)
54 {
56  gpio_set_duty(ext_power);
57 }
static void write16(void *addr, uint16_t val)
Definition: mmio.h:35
static void gpio_set_duty(enum external_power ext_power)
Definition: gpio_init.c:34
static void set_gpi_from_mipi(void)
Definition: gpio_init.c:13
void gpio_init(enum external_power ext_power)
Definition: gpio_init.c:53
#define setbits32(addr, set)
Definition: mmio.h:21
static struct mipi_rx_regs *const mt8173_mipi
Definition: mipi.h:19
static struct gpio_regs *const mtk_gpio
Definition: gpio.h:347
external_power
Definition: gpio.h:15
@ GPIO_EINT_1P8V
Definition: gpio.h:17
@ GPIO_EINT_3P3V
Definition: gpio.h:16
struct val_regs msdc2_ctrl5
Definition: gpio.h:335
struct val_regs exmd_ctrl[1]
Definition: gpio.h:338
uint32_t mipi_rx_ana4c
Definition: mipi.h:11
uint32_t mipi_rx_ana50
Definition: mipi.h:12
uint32_t set
Definition: gpio.h:307
uint32_t rst
Definition: gpio.h:308