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