coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
msdc.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/addressmap.h>
5 #include <soc/gpio.h>
6 #include <soc/i2c.h>
7 #include <soc/regulator.h>
8 #include <soc/msdc.h>
9 #include <soc/mt6360.h>
10 
11 DEFINE_BITFIELD(MSDC0_DRV, 29, 0)
12 DEFINE_BITFIELD(MSDC1_DRV, 17, 0)
13 DEFINE_BITFIELD(MSDC1_GPIO_MODE0_0, 26, 24)
14 DEFINE_BITFIELD(MSDC1_GPIO_MODE0_1, 30, 28)
15 DEFINE_BITFIELD(MSDC1_GPIO_MODE1_0, 2, 0)
16 DEFINE_BITFIELD(MSDC1_GPIO_MODE1_1, 6, 4)
17 DEFINE_BITFIELD(MSDC1_GPIO_MODE1_2, 10, 8)
18 DEFINE_BITFIELD(MSDC1_GPIO_MODE1_3, 14, 12)
19 
20 #define MSDC0_BASE 0x11230000
21 #define MSDC0_TOP_BASE 0x11f50000
22 
23 #define MSDC0_DRV_VALUE 0x1b6db6db
24 #define MSDC1_DRV_VALUE 0x1b6db
25 #define MSDC1_GPIO_MODE0_VALUE 0x1
26 #define MSDC1_GPIO_MODE1_VALUE 0x1
27 
28 enum {
29  MSDC1_GPIO_MODE0_BASE = 0x100053d0,
30  MSDC1_GPIO_MODE1_BASE = 0x100053e0,
31 };
32 
33 void mtk_msdc_configure_emmc(bool is_early_init)
34 {
35  void *gpio_base = (void *)IOCFG_TL_BASE;
36  int i;
37 
38  const gpio_t emmc_pu_pin[] = {
39  GPIO(EMMC_DAT0), GPIO(EMMC_DAT1),
40  GPIO(EMMC_DAT2), GPIO(EMMC_DAT3),
41  GPIO(EMMC_DAT4), GPIO(EMMC_DAT5),
42  GPIO(EMMC_DAT6), GPIO(EMMC_DAT7),
43  GPIO(EMMC_CMD), GPIO(EMMC_RSTB),
44  };
45 
46  const gpio_t emmc_pd_pin[] = {
47  GPIO(EMMC_DSL), GPIO(EMMC_CLK),
48  };
49 
50  for (i = 0; i < ARRAY_SIZE(emmc_pu_pin); i++)
52 
53  for (i = 0; i < ARRAY_SIZE(emmc_pd_pin); i++)
55 
56  /* set eMMC cmd/dat/clk/ds/rstb pins driving to 8mA */
57  SET32_BITFIELDS(gpio_base, MSDC0_DRV, MSDC0_DRV_VALUE);
58 
59  if (is_early_init)
61 }
62 
64 {
65  void *gpio_base = (void *)IOCFG_RB_BASE;
66  void *gpio_mode0_base = (void *)MSDC1_GPIO_MODE0_BASE;
67  void *gpio_mode1_base = (void *)MSDC1_GPIO_MODE1_BASE;
68  int i;
69 
70  const gpio_t sdcard_pu_pin[] = {
71  GPIO(MSDC1_DAT0), GPIO(MSDC1_DAT1),
72  GPIO(MSDC1_DAT2), GPIO(MSDC1_DAT3),
73  GPIO(MSDC1_CMD),
74  };
75 
76  const gpio_t sdcard_pd_pin[] = {
77  GPIO(MSDC1_CLK),
78  };
79 
80  for (i = 0; i < ARRAY_SIZE(sdcard_pu_pin); i++)
81  gpio_set_pull(sdcard_pu_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_UP);
82 
83  for (i = 0; i < ARRAY_SIZE(sdcard_pd_pin); i++)
84  gpio_set_pull(sdcard_pd_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_DOWN);
85 
86  /* set sdcard cmd/dat/clk pins driving to 8mA */
87  SET32_BITFIELDS(gpio_base, MSDC1_DRV, MSDC1_DRV_VALUE);
88 
89  /* set sdcard dat2/dat0/dat3/cmd/clk pins to msdc1 mode */
90  SET32_BITFIELDS(gpio_mode0_base,
91  MSDC1_GPIO_MODE0_0, MSDC1_GPIO_MODE0_VALUE,
92  MSDC1_GPIO_MODE0_1, MSDC1_GPIO_MODE0_VALUE);
93 
94  /* set sdcard dat1 pin to msdc1 mode */
95  SET32_BITFIELDS(gpio_mode1_base,
96  MSDC1_GPIO_MODE1_0, MSDC1_GPIO_MODE1_VALUE,
97  MSDC1_GPIO_MODE1_1, MSDC1_GPIO_MODE1_VALUE,
98  MSDC1_GPIO_MODE1_2, MSDC1_GPIO_MODE1_VALUE,
99  MSDC1_GPIO_MODE1_3, MSDC1_GPIO_MODE1_VALUE);
100 
102 
103  if (CONFIG(BOARD_GOOGLE_CHERRY))
104  mt6360_init(I2C7);
105 
108 }
int mainboard_enable_regulator(enum mtk_regulator regulator, uint8_t enable)
Definition: regulator.c:98
#define ARRAY_SIZE(a)
Definition: helpers.h:12
int mtk_emmc_early_init(void *base, void *top_base)
Definition: msdc.c:457
@ GPIO
Definition: chip.h:84
@ CONFIG
Definition: dsi_common.h:201
@ I2C_SPEED_FAST
Definition: i2c.h:45
#define DEFINE_BITFIELD(name, high_bit, low_bit)
Definition: mmio.h:124
#define SET32_BITFIELDS(addr,...)
Definition: mmio.h:201
@ GPIO_PULL_ENABLE
Definition: gpio_common.h:13
void gpio_set_pull(gpio_t gpio, enum pull_enable enable, enum pull_select select)
Definition: gpio.c:17
@ MSDC1_GPIO_MODE1_BASE
Definition: msdc.c:33
@ MSDC1_GPIO_MODE0_BASE
Definition: msdc.c:32
void mtk_msdc_configure_sdcard(void)
Definition: msdc.c:66
void mtk_msdc_configure_emmc(bool is_early_init)
Definition: msdc.c:36
void mt6360_init(uint8_t bus)
Definition: mt6360.c:382
#define MSDC0_TOP_BASE
Definition: msdc.c:21
#define MSDC0_DRV_VALUE
Definition: msdc.c:23
#define MSDC1_GPIO_MODE1_VALUE
Definition: msdc.c:26
#define MSDC0_BASE
Definition: msdc.c:20
#define MSDC1_GPIO_MODE0_VALUE
Definition: msdc.c:25
#define MSDC1_DRV_VALUE
Definition: msdc.c:24
@ MTK_REGULATOR_VCCQ
Definition: regulator.h:15
@ MTK_REGULATOR_VCC
Definition: regulator.h:14
void mtk_i2c_bus_init(uint8_t bus)
Definition: i2c.c:65
@ IOCFG_RB_BASE
Definition: addressmap.h:40
@ IOCFG_TL_BASE
Definition: addressmap.h:47
@ I2C7
Definition: i2c.h:57
#define GPIO_PULL_UP
Definition: gpio.h:24
#define GPIO_PULL_DOWN
Definition: gpio.h:23