Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2013 SAMSUNG Electronics |
| 4 | * Rajeshwari Shinde <rajeshwari.s@samsung.com> |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <cros_ec.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 9 | #include <env.h> |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 10 | #include <errno.h> |
| 11 | #include <fdtdec.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 12 | #include <hang.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 13 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 15 | #include <net.h> |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 16 | #include <spi.h> |
| 17 | #include <tmu.h> |
| 18 | #include <netdev.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 19 | #include <asm/global_data.h> |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 20 | #include <asm/io.h> |
Simon Glass | 37f1162 | 2014-10-20 19:48:37 -0600 | [diff] [blame] | 21 | #include <asm/gpio.h> |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 22 | #include <asm/arch/board.h> |
| 23 | #include <asm/arch/cpu.h> |
| 24 | #include <asm/arch/dwmmc.h> |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 25 | #include <asm/arch/mmc.h> |
| 26 | #include <asm/arch/pinmux.h> |
| 27 | #include <asm/arch/power.h> |
Ajay Kumar | 1176348 | 2014-09-05 16:53:30 +0530 | [diff] [blame] | 28 | #include <asm/arch/system.h> |
Przemyslaw Marczak | 110aa29 | 2015-04-20 20:07:50 +0200 | [diff] [blame] | 29 | #include <i2c.h> |
Marek Szyprowski | bc4a2e3 | 2020-01-17 14:02:44 +0100 | [diff] [blame] | 30 | #include <mmc.h> |
| 31 | #include <stdio_dev.h> |
Lukasz Majewski | 7573b96 | 2015-03-03 17:32:03 +0100 | [diff] [blame] | 32 | #include <usb.h> |
Joonyoung Shim | 95d3a1d | 2015-05-22 18:14:24 +0200 | [diff] [blame] | 33 | #include <dwc3-uboot.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 34 | #include <linux/delay.h> |
Joonyoung Shim | 95d3a1d | 2015-05-22 18:14:24 +0200 | [diff] [blame] | 35 | #include <samsung/misc.h> |
Thomas Abraham | 8d84faa | 2016-04-23 22:18:14 +0530 | [diff] [blame] | 36 | #include <dm/pinctrl.h> |
| 37 | #include <dm.h> |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 38 | |
| 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
Jeroen Hofstee | 5cd8294 | 2014-10-08 22:57:28 +0200 | [diff] [blame] | 41 | __weak int exynos_early_init_f(void) |
Piotr Wilczek | 942d0a9 | 2014-03-07 14:59:43 +0100 | [diff] [blame] | 42 | { |
| 43 | return 0; |
| 44 | } |
Piotr Wilczek | 942d0a9 | 2014-03-07 14:59:43 +0100 | [diff] [blame] | 45 | |
Jeroen Hofstee | 5cd8294 | 2014-10-08 22:57:28 +0200 | [diff] [blame] | 46 | __weak int exynos_power_init(void) |
Piotr Wilczek | 942d0a9 | 2014-03-07 14:59:43 +0100 | [diff] [blame] | 47 | { |
| 48 | return 0; |
| 49 | } |
Piotr Wilczek | 942d0a9 | 2014-03-07 14:59:43 +0100 | [diff] [blame] | 50 | |
Marek Szyprowski | bc4a2e3 | 2020-01-17 14:02:44 +0100 | [diff] [blame] | 51 | /** |
| 52 | * get_boot_mmc_dev() - read boot MMC device id from XOM[7:5] pins. |
| 53 | */ |
| 54 | static int get_boot_mmc_dev(void) |
| 55 | { |
| 56 | u32 mode = readl(EXYNOS4_OP_MODE) & 0x1C; |
| 57 | |
| 58 | if (mode == 0x04) |
| 59 | return 2; /* MMC2: SD */ |
| 60 | |
| 61 | /* MMC0: eMMC or unknown */ |
| 62 | return 0; |
| 63 | } |
| 64 | |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 65 | #if defined CONFIG_EXYNOS_TMU |
| 66 | /* Boot Time Thermal Analysis for SoC temperature threshold breach */ |
| 67 | static void boot_temp_check(void) |
| 68 | { |
| 69 | int temp; |
| 70 | |
| 71 | switch (tmu_monitor(&temp)) { |
| 72 | case TMU_STATUS_NORMAL: |
| 73 | break; |
| 74 | case TMU_STATUS_TRIPPED: |
| 75 | /* |
| 76 | * Status TRIPPED ans WARNING means corresponding threshold |
| 77 | * breach |
| 78 | */ |
| 79 | puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n"); |
| 80 | set_ps_hold_ctrl(); |
| 81 | hang(); |
| 82 | break; |
| 83 | case TMU_STATUS_WARNING: |
| 84 | puts("EXYNOS_TMU: WARNING! Temperature very high\n"); |
| 85 | break; |
| 86 | case TMU_STATUS_INIT: |
| 87 | /* |
| 88 | * TMU_STATUS_INIT means something is wrong with temperature |
| 89 | * sensing and TMU status was changed back from NORMAL to INIT. |
| 90 | */ |
| 91 | puts("EXYNOS_TMU: WARNING! Temperature sensing not done\n"); |
| 92 | break; |
| 93 | default: |
| 94 | debug("EXYNOS_TMU: Unknown TMU state\n"); |
| 95 | } |
| 96 | } |
| 97 | #endif |
| 98 | |
| 99 | int board_init(void) |
| 100 | { |
| 101 | gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL); |
| 102 | #if defined CONFIG_EXYNOS_TMU |
| 103 | if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) { |
| 104 | debug("%s: Failed to init TMU\n", __func__); |
| 105 | return -1; |
| 106 | } |
| 107 | boot_temp_check(); |
| 108 | #endif |
Tom Rini | 5c1e727 | 2022-04-06 10:33:32 -0400 | [diff] [blame] | 109 | #if CONFIG_VAL(SYS_MEM_TOP_HIDE) |
Przemyslaw Marczak | c32a04c | 2015-02-17 14:50:25 +0100 | [diff] [blame] | 110 | /* The last few MB of memory can be reserved for secure firmware */ |
Tom Rini | 5c1e727 | 2022-04-06 10:33:32 -0400 | [diff] [blame] | 111 | ulong size = CONFIG_SYS_MEM_TOP_HIDE; |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 112 | |
Przemyslaw Marczak | c32a04c | 2015-02-17 14:50:25 +0100 | [diff] [blame] | 113 | gd->ram_size -= size; |
| 114 | gd->bd->bi_dram[CONFIG_NR_DRAM_BANKS - 1].size -= size; |
| 115 | #endif |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 116 | return exynos_init(); |
| 117 | } |
| 118 | |
| 119 | int dram_init(void) |
| 120 | { |
Ćukasz Majewski | 33d7a19 | 2015-03-04 10:54:48 +0100 | [diff] [blame] | 121 | unsigned int i; |
Thomas Abraham | 8d84faa | 2016-04-23 22:18:14 +0530 | [diff] [blame] | 122 | unsigned long addr; |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 123 | |
| 124 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 125 | addr = CFG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE); |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 126 | gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE); |
| 127 | } |
| 128 | return 0; |
| 129 | } |
| 130 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 131 | int dram_init_banksize(void) |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 132 | { |
Ćukasz Majewski | 33d7a19 | 2015-03-04 10:54:48 +0100 | [diff] [blame] | 133 | unsigned int i; |
Thomas Abraham | 8d84faa | 2016-04-23 22:18:14 +0530 | [diff] [blame] | 134 | unsigned long addr, size; |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 135 | |
| 136 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 137 | addr = CFG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE); |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 138 | size = get_ram_size((long *)addr, SDRAM_BANK_SIZE); |
| 139 | |
| 140 | gd->bd->bi_dram[i].start = addr; |
| 141 | gd->bd->bi_dram[i].size = size; |
| 142 | } |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 143 | |
| 144 | return 0; |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static int board_uart_init(void) |
| 148 | { |
Thomas Abraham | 8d84faa | 2016-04-23 22:18:14 +0530 | [diff] [blame] | 149 | #ifndef CONFIG_PINCTRL_EXYNOS |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 150 | int err, uart_id, ret = 0; |
| 151 | |
| 152 | for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) { |
| 153 | err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE); |
| 154 | if (err) { |
| 155 | debug("UART%d not configured\n", |
| 156 | (uart_id - PERIPH_ID_UART0)); |
| 157 | ret |= err; |
| 158 | } |
| 159 | } |
| 160 | return ret; |
Thomas Abraham | 8d84faa | 2016-04-23 22:18:14 +0530 | [diff] [blame] | 161 | #else |
| 162 | return 0; |
| 163 | #endif |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 167 | int board_early_init_f(void) |
| 168 | { |
| 169 | int err; |
Przemyslaw Marczak | 4d2a92c | 2014-09-01 13:50:49 +0200 | [diff] [blame] | 170 | #ifdef CONFIG_BOARD_TYPES |
| 171 | set_board_type(); |
| 172 | #endif |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 173 | err = board_uart_init(); |
| 174 | if (err) { |
| 175 | debug("UART init failed\n"); |
| 176 | return err; |
| 177 | } |
| 178 | |
Piotr Wilczek | 942d0a9 | 2014-03-07 14:59:43 +0100 | [diff] [blame] | 179 | return exynos_early_init_f(); |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 180 | } |
| 181 | #endif |
| 182 | |
Simon Glass | 3133941 | 2021-08-08 12:20:27 -0600 | [diff] [blame] | 183 | #if CONFIG_IS_ENABLED(POWER_LEGACY) || CONFIG_IS_ENABLED(DM_PMIC) |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 184 | int power_init_board(void) |
| 185 | { |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 186 | set_ps_hold_ctrl(); |
| 187 | |
Piotr Wilczek | 942d0a9 | 2014-03-07 14:59:43 +0100 | [diff] [blame] | 188 | return exynos_power_init(); |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 189 | } |
| 190 | #endif |
| 191 | |
Krzysztof Kozlowski | c51bd0b | 2019-03-06 19:37:52 +0100 | [diff] [blame] | 192 | #if defined(CONFIG_DISPLAY_BOARDINFO) || defined(CONFIG_DISPLAY_BOARDINFO_LATE) |
Piotr Wilczek | 3df7aff | 2014-03-07 14:59:42 +0100 | [diff] [blame] | 193 | int checkboard(void) |
| 194 | { |
Simon Glass | 6ceeff4 | 2019-01-11 18:37:07 -0700 | [diff] [blame] | 195 | if (IS_ENABLED(CONFIG_BOARD_TYPES)) { |
Krzysztof Kozlowski | 36476ee | 2019-03-06 19:37:51 +0100 | [diff] [blame] | 196 | const char *board_info; |
| 197 | |
| 198 | if (IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) { |
| 199 | /* |
| 200 | * Printing type requires having revision, although |
| 201 | * this will succeed only if done late. |
| 202 | * Otherwise revision will be set in misc_init_r(). |
| 203 | */ |
| 204 | set_board_revision(); |
| 205 | } |
| 206 | |
| 207 | board_info = get_board_type(); |
Simon Glass | 6ceeff4 | 2019-01-11 18:37:07 -0700 | [diff] [blame] | 208 | |
| 209 | if (board_info) |
| 210 | printf("Type: %s\n", board_info); |
| 211 | } |
Piotr Wilczek | 3df7aff | 2014-03-07 14:59:42 +0100 | [diff] [blame] | 212 | |
Piotr Wilczek | 3df7aff | 2014-03-07 14:59:42 +0100 | [diff] [blame] | 213 | return 0; |
| 214 | } |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 215 | #endif |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 216 | |
| 217 | #ifdef CONFIG_BOARD_LATE_INIT |
| 218 | int board_late_init(void) |
| 219 | { |
Simon Glass | fe3f643 | 2018-11-06 15:21:26 -0700 | [diff] [blame] | 220 | struct udevice *dev; |
| 221 | int ret; |
Marek Szyprowski | bc4a2e3 | 2020-01-17 14:02:44 +0100 | [diff] [blame] | 222 | int mmcbootdev = get_boot_mmc_dev(); |
| 223 | char mmcbootdev_str[16]; |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 224 | |
Simon Glass | fe3f643 | 2018-11-06 15:21:26 -0700 | [diff] [blame] | 225 | ret = uclass_first_device_err(UCLASS_CROS_EC, &dev); |
| 226 | if (ret && ret != -ENODEV) { |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 227 | /* Force console on */ |
| 228 | gd->flags &= ~GD_FLG_SILENT; |
| 229 | |
Simon Glass | fe3f643 | 2018-11-06 15:21:26 -0700 | [diff] [blame] | 230 | printf("cros-ec communications failure %d\n", ret); |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 231 | puts("\nPlease reset with Power+Refresh\n\n"); |
| 232 | panic("Cannot init cros-ec device"); |
| 233 | return -1; |
| 234 | } |
Marek Szyprowski | bc4a2e3 | 2020-01-17 14:02:44 +0100 | [diff] [blame] | 235 | |
| 236 | printf("Boot device: MMC(%u)\n", mmcbootdev); |
| 237 | sprintf(mmcbootdev_str, "%u", mmcbootdev); |
| 238 | env_set("mmcbootdev", mmcbootdev_str); |
| 239 | |
Rajeshwari Birje | 987b0dd | 2013-12-26 09:44:17 +0530 | [diff] [blame] | 240 | return 0; |
| 241 | } |
| 242 | #endif |
| 243 | |
Piotr Wilczek | 2c3eed5 | 2014-03-07 14:59:45 +0100 | [diff] [blame] | 244 | #ifdef CONFIG_MISC_INIT_R |
| 245 | int misc_init_r(void) |
| 246 | { |
Krzysztof Kozlowski | 36476ee | 2019-03-06 19:37:51 +0100 | [diff] [blame] | 247 | if (IS_ENABLED(CONFIG_BOARD_TYPES) && |
| 248 | !IS_ENABLED(CONFIG_DISPLAY_BOARDINFO_LATE)) { |
| 249 | /* |
| 250 | * If revision was not set by late display boardinfo, |
| 251 | * set it here. At this point regulators should be already |
| 252 | * available. |
| 253 | */ |
| 254 | set_board_revision(); |
| 255 | } |
| 256 | |
Piotr Wilczek | 2c3eed5 | 2014-03-07 14:59:45 +0100 | [diff] [blame] | 257 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 258 | set_board_info(); |
| 259 | #endif |
Piotr Wilczek | 2c3eed5 | 2014-03-07 14:59:45 +0100 | [diff] [blame] | 260 | #ifdef CONFIG_CMD_BMP |
| 261 | if (panel_info.logo_on) |
| 262 | draw_logo(); |
| 263 | #endif |
| 264 | return 0; |
| 265 | } |
| 266 | #endif |
Joonyoung Shim | 7a3e806 | 2015-01-15 11:45:56 +0900 | [diff] [blame] | 267 | |
| 268 | void reset_misc(void) |
| 269 | { |
| 270 | struct gpio_desc gpio = {}; |
| 271 | int node; |
| 272 | |
| 273 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, |
| 274 | "samsung,emmc-reset"); |
| 275 | if (node < 0) |
| 276 | return; |
| 277 | |
Simon Glass | 1d9af1f | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 278 | gpio_request_by_name_nodev(offset_to_ofnode(node), "reset-gpio", 0, |
| 279 | &gpio, GPIOD_IS_OUT); |
Joonyoung Shim | 7a3e806 | 2015-01-15 11:45:56 +0900 | [diff] [blame] | 280 | |
| 281 | if (dm_gpio_is_valid(&gpio)) { |
| 282 | /* |
| 283 | * Reset eMMC |
| 284 | * |
| 285 | * FIXME: Need to optimize delay time. Minimum 1usec pulse is |
| 286 | * required by 'JEDEC Standard No.84-A441' (eMMC) |
| 287 | * document but real delay time is expected to greater |
| 288 | * than 1usec. |
| 289 | */ |
| 290 | dm_gpio_set_value(&gpio, 0); |
| 291 | mdelay(10); |
| 292 | dm_gpio_set_value(&gpio, 1); |
| 293 | } |
| 294 | } |
Lukasz Majewski | 7573b96 | 2015-03-03 17:32:03 +0100 | [diff] [blame] | 295 | |
| 296 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 297 | { |
Joonyoung Shim | 95d3a1d | 2015-05-22 18:14:24 +0200 | [diff] [blame] | 298 | #ifdef CONFIG_USB_DWC3 |
| 299 | dwc3_uboot_exit(index); |
| 300 | #endif |
Lukasz Majewski | 7573b96 | 2015-03-03 17:32:03 +0100 | [diff] [blame] | 301 | return 0; |
| 302 | } |
Marek Szyprowski | bc4a2e3 | 2020-01-17 14:02:44 +0100 | [diff] [blame] | 303 | |
| 304 | int mmc_get_env_dev(void) |
| 305 | { |
| 306 | return get_boot_mmc_dev(); |
| 307 | } |