Macpaul Lin | 5d16f8d | 2022-08-11 16:27:10 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only OR MIT */ |
Rex-BC Chen | 15486f4 | 2021-11-12 18:28:18 +0800 | [diff] [blame] | 2 | |
| 3 | #include <device/mmio.h> |
Elyes Haouas | 5316abe | 2023-01-11 09:46:57 +0100 | [diff] [blame] | 4 | #include <gpio.h> |
Rex-BC Chen | 15486f4 | 2021-11-12 18:28:18 +0800 | [diff] [blame] | 5 | #include <soc/addressmap.h> |
Rex-BC Chen | 15486f4 | 2021-11-12 18:28:18 +0800 | [diff] [blame] | 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++) |
| 51 | gpio_set_pull(emmc_pu_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 52 | |
| 53 | for (i = 0; i < ARRAY_SIZE(emmc_pd_pin); i++) |
| 54 | gpio_set_pull(emmc_pd_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_DOWN); |
| 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) |
| 60 | mtk_emmc_early_init((void *)MSDC0_BASE, (void *)MSDC0_TOP_BASE); |
| 61 | } |
| 62 | |
| 63 | void mtk_msdc_configure_sdcard(void) |
| 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 | |
| 101 | mtk_i2c_bus_init(I2C7, I2C_SPEED_FAST); |
| 102 | |
| 103 | if (CONFIG(BOARD_GOOGLE_CHERRY)) |
| 104 | mt6360_init(I2C7); |
| 105 | |
Rex-BC Chen | c5d4d96 | 2022-07-20 11:35:57 +0800 | [diff] [blame] | 106 | mainboard_enable_regulator(MTK_REGULATOR_VCCQ, true); |
| 107 | mainboard_enable_regulator(MTK_REGULATOR_VCC, true); |
Rex-BC Chen | 15486f4 | 2021-11-12 18:28:18 +0800 | [diff] [blame] | 108 | } |