Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame^] | 3 | #include <bl31.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 4 | #include <bootmode.h> |
| 5 | #include <console/console.h> |
| 6 | #include <delay.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/mmio.h> |
| 9 | #include <gpio.h> |
| 10 | #include <soc/gpio.h> |
| 11 | #include <soc/i2c.h> |
| 12 | #include <soc/mt6360.h> |
| 13 | #include <soc/regulator.h> |
Yuchen Huang | 144237f | 2021-03-01 14:39:33 +0800 | [diff] [blame] | 14 | #include <soc/usb.h> |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 15 | |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame^] | 16 | #include "gpio.h" |
| 17 | |
| 18 | #include <arm-trusted-firmware/include/export/plat/mediatek/common/plat_params_exp.h> |
| 19 | |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 20 | DEFINE_BITFIELD(MSDC0_DRV, 29, 0) |
| 21 | DEFINE_BITFIELD(MSDC1_DRV, 17, 0) |
| 22 | DEFINE_BITFIELD(MSDC1_GPIO_MODE0_0, 26, 24) |
| 23 | DEFINE_BITFIELD(MSDC1_GPIO_MODE0_1, 30, 28) |
| 24 | DEFINE_BITFIELD(MSDC1_GPIO_MODE1_0, 2, 0) |
| 25 | DEFINE_BITFIELD(MSDC1_GPIO_MODE1_1, 6, 4) |
| 26 | DEFINE_BITFIELD(MSDC1_GPIO_MODE1_2, 10, 8) |
| 27 | DEFINE_BITFIELD(MSDC1_GPIO_MODE1_3, 14, 12) |
| 28 | |
| 29 | #define MSDC0_DRV_VALUE 0x1b6db6db |
| 30 | #define MSDC1_DRV_VALUE 0x1b6db |
| 31 | #define MSDC1_GPIO_MODE0_VALUE 0x1 |
| 32 | #define MSDC1_GPIO_MODE1_VALUE 0x1 |
| 33 | |
| 34 | enum { |
| 35 | MSDC1_GPIO_MODE0_BASE = 0x100053d0, |
| 36 | MSDC1_GPIO_MODE1_BASE = 0x100053e0, |
| 37 | }; |
| 38 | |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame^] | 39 | static void register_reset_to_bl31(void) |
| 40 | { |
| 41 | static struct bl_aux_param_gpio param_reset = { |
| 42 | .h = { .type = BL_AUX_PARAM_MTK_RESET_GPIO }, |
| 43 | .gpio = { .polarity = ARM_TF_GPIO_LEVEL_HIGH }, |
| 44 | }; |
| 45 | |
| 46 | param_reset.gpio.index = GPIO_RESET.id; |
| 47 | register_bl31_aux_param(¶m_reset.h); |
| 48 | } |
| 49 | |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 50 | static void configure_emmc(void) |
| 51 | { |
| 52 | void *gpio_base = (void *)IOCFG_TL_BASE; |
| 53 | int i; |
| 54 | |
| 55 | const gpio_t emmc_pu_pin[] = { |
| 56 | GPIO(EMMC_DAT0), GPIO(EMMC_DAT1), |
| 57 | GPIO(EMMC_DAT2), GPIO(EMMC_DAT3), |
| 58 | GPIO(EMMC_DAT4), GPIO(EMMC_DAT5), |
| 59 | GPIO(EMMC_DAT6), GPIO(EMMC_DAT7), |
| 60 | GPIO(EMMC_CMD), GPIO(EMMC_RSTB), |
| 61 | }; |
| 62 | |
| 63 | const gpio_t emmc_pd_pin[] = { |
| 64 | GPIO(EMMC_DSL), GPIO(EMMC_CLK), |
| 65 | }; |
| 66 | |
| 67 | for (i = 0; i < ARRAY_SIZE(emmc_pu_pin); i++) |
| 68 | gpio_set_pull(emmc_pu_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 69 | |
| 70 | for (i = 0; i < ARRAY_SIZE(emmc_pd_pin); i++) |
| 71 | gpio_set_pull(emmc_pd_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_DOWN); |
| 72 | |
| 73 | /* set eMMC cmd/dat/clk/ds/rstb pins driving to 8mA */ |
| 74 | SET32_BITFIELDS(gpio_base, MSDC0_DRV, MSDC0_DRV_VALUE); |
| 75 | } |
| 76 | |
| 77 | static void configure_sdcard(void) |
| 78 | { |
| 79 | void *gpio_base = (void *)IOCFG_RB_BASE; |
| 80 | void *gpio_mode0_base = (void *)MSDC1_GPIO_MODE0_BASE; |
| 81 | void *gpio_mode1_base = (void *)MSDC1_GPIO_MODE1_BASE; |
| 82 | int i; |
| 83 | |
| 84 | const gpio_t sdcard_pu_pin[] = { |
| 85 | GPIO(MSDC1_DAT0), GPIO(MSDC1_DAT1), |
| 86 | GPIO(MSDC1_DAT2), GPIO(MSDC1_DAT3), |
| 87 | GPIO(MSDC1_CMD), |
| 88 | }; |
| 89 | |
| 90 | const gpio_t sdcard_pd_pin[] = { |
| 91 | GPIO(MSDC1_CLK), |
| 92 | }; |
| 93 | |
| 94 | for (i = 0; i < ARRAY_SIZE(sdcard_pu_pin); i++) |
| 95 | gpio_set_pull(sdcard_pu_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_UP); |
| 96 | |
| 97 | for (i = 0; i < ARRAY_SIZE(sdcard_pd_pin); i++) |
| 98 | gpio_set_pull(sdcard_pd_pin[i], GPIO_PULL_ENABLE, GPIO_PULL_DOWN); |
| 99 | |
| 100 | /* set sdcard cmd/dat/clk pins driving to 8mA */ |
| 101 | SET32_BITFIELDS(gpio_base, MSDC1_DRV, MSDC1_DRV_VALUE); |
| 102 | |
| 103 | /* set sdcard dat2/dat0/dat3/cmd/clk pins to msdc1 mode */ |
| 104 | SET32_BITFIELDS(gpio_mode0_base, |
| 105 | MSDC1_GPIO_MODE0_0, MSDC1_GPIO_MODE0_VALUE, |
| 106 | MSDC1_GPIO_MODE0_1, MSDC1_GPIO_MODE0_VALUE); |
| 107 | |
| 108 | /* set sdcard dat1 pin to msdc1 mode */ |
| 109 | SET32_BITFIELDS(gpio_mode1_base, |
| 110 | MSDC1_GPIO_MODE1_0, MSDC1_GPIO_MODE1_VALUE, |
| 111 | MSDC1_GPIO_MODE1_1, MSDC1_GPIO_MODE1_VALUE, |
| 112 | MSDC1_GPIO_MODE1_2, MSDC1_GPIO_MODE1_VALUE, |
| 113 | MSDC1_GPIO_MODE1_3, MSDC1_GPIO_MODE1_VALUE); |
| 114 | |
| 115 | mtk_i2c_bus_init(7); |
| 116 | mt6360_init(7); |
| 117 | mt6360_ldo_enable(MT6360_LDO3, 1); |
| 118 | mt6360_ldo_enable(MT6360_LDO5, 1); |
| 119 | } |
| 120 | |
| 121 | static void mainboard_init(struct device *dev) |
| 122 | { |
| 123 | configure_emmc(); |
| 124 | configure_sdcard(); |
Yuchen Huang | 144237f | 2021-03-01 14:39:33 +0800 | [diff] [blame] | 125 | setup_usb_host(); |
Yidi Lin | 7c06dd9 | 2021-04-08 09:55:11 +0800 | [diff] [blame^] | 126 | |
| 127 | register_reset_to_bl31(); |
Wenbin Mei | 24c6355 | 2021-02-24 15:17:41 +0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static void mainboard_enable(struct device *dev) |
| 131 | { |
| 132 | dev->ops->init = &mainboard_init; |
| 133 | } |
| 134 | |
| 135 | struct chip_operations mainboard_ops = { |
| 136 | .name = CONFIG_MAINBOARD_PART_NUMBER, |
| 137 | .enable_dev = mainboard_enable, |
| 138 | }; |