2 * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <linux/err.h>
12 #include "../sbc/sbc-regs.h"
13 #include "../soc-info.h"
14 #include "boot-device.h"
16 u32 spl_boot_device_raw(void)
18 if (boot_is_swapped())
19 return BOOT_DEVICE_NOR;
21 switch (uniphier_get_soc_type()) {
22 #if defined(CONFIG_ARCH_UNIPHIER_SLD3)
23 case SOC_UNIPHIER_SLD3:
24 return uniphier_sld3_boot_device();
26 #if defined(CONFIG_ARCH_UNIPHIER_LD4) || defined(CONFIG_ARCH_UNIPHIER_PRO4) || \
27 defined(CONFIG_ARCH_UNIPHIER_SLD8)
28 case SOC_UNIPHIER_LD4:
29 case SOC_UNIPHIER_PRO4:
30 case SOC_UNIPHIER_SLD8:
31 return uniphier_ld4_boot_device();
33 #if defined(CONFIG_ARCH_UNIPHIER_PRO5)
34 case SOC_UNIPHIER_PRO5:
35 return uniphier_pro5_boot_device();
37 #if defined(CONFIG_ARCH_UNIPHIER_PXS2) || defined(CONFIG_ARCH_UNIPHIER_LD6B)
38 case SOC_UNIPHIER_PXS2:
39 case SOC_UNIPHIER_LD6B:
40 return uniphier_pxs2_boot_device();
42 #if defined(CONFIG_ARCH_UNIPHIER_LD11) || defined(CONFIG_ARCH_UNIPHIER_LD20)
43 case SOC_UNIPHIER_LD11:
44 case SOC_UNIPHIER_LD20:
45 return uniphier_ld20_boot_device();
48 return BOOT_DEVICE_NONE;
52 u32 spl_boot_device(void)
56 ret = spl_boot_device_raw();
58 return ret == BOOT_DEVICE_USB ? BOOT_DEVICE_NOR : ret;
61 u32 spl_boot_mode(void)
66 * work around a bug in the Boot ROM of PH1-sLD3, LD4, Pro4, and sLD8:
68 * The boot ROM in these SoCs breaks the PARTITION_CONFIG [179] of
69 * Extended CSD register; when switching to the Boot Partition 1, the
70 * Boot ROM should issue the SWITCH command (CMD6) with Set Bits for
71 * the Access Bits, but in fact it uses Write Byte for the Access Bits.
72 * As a result, the BOOT_PARTITION_ENABLE field of the PARTITION_CONFIG
73 * is lost. This bug was fixed for PH1-Pro5 and later SoCs.
75 * Fixup mmc->part_config here because it is used to determine the
76 * partition which the U-Boot image is read from.
78 mmc = find_mmc_device(0);
79 mmc->part_config &= ~EXT_CSD_BOOT_PART_NUM(PART_ACCESS_MASK);
80 mmc->part_config |= EXT_CSD_BOOT_PARTITION_ENABLE;
82 return MMCSD_MODE_EMMCBOOT;
85 #if defined(CONFIG_DM_MMC) && !defined(CONFIG_SPL_BUILD)
86 static int find_first_mmc_device(void)
91 for (i = 0; (mmc = find_mmc_device(i)); i++) {
92 if (!mmc_init(mmc) && IS_MMC(mmc))
99 int mmc_get_env_dev(void)
101 return find_first_mmc_device();
104 static int do_mmcsetn(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
108 dev = find_first_mmc_device();
110 return CMD_RET_FAILURE;
112 setenv_ulong("mmc_first_dev", dev);
113 return CMD_RET_SUCCESS;
117 mmcsetn, 1, 1, do_mmcsetn,
118 "Set the first MMC (not SD) dev number to \"mmc_first_dev\" environment",