blob: 4b744da2529af728733b90da39028ff8d046cda1 [file] [log] [blame]
Masahiro Yamada323d1f92015-09-22 00:27:39 +09001/*
2 * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Masahiro Yamadaa55d9fe2016-02-16 17:08:39 +09008#include <mmc.h>
Masahiro Yamada323d1f92015-09-22 00:27:39 +09009#include <spl.h>
Masahiro Yamada569e4be2016-02-16 17:08:40 +090010#include <linux/err.h>
Masahiro Yamada107b3fb2016-01-09 01:51:13 +090011
12#include "../sbc/sbc-regs.h"
13#include "../soc-info.h"
14#include "boot-device.h"
Masahiro Yamada323d1f92015-09-22 00:27:39 +090015
Masahiro Yamadafec48162016-02-02 21:11:31 +090016u32 spl_boot_device_raw(void)
Masahiro Yamada323d1f92015-09-22 00:27:39 +090017{
18 if (boot_is_swapped())
19 return BOOT_DEVICE_NOR;
20
21 switch (uniphier_get_soc_type()) {
Masahiro Yamadaea65c982016-03-18 16:41:43 +090022#if defined(CONFIG_ARCH_UNIPHIER_SLD3)
23 case SOC_UNIPHIER_SLD3:
Masahiro Yamada5b660062016-03-30 20:17:02 +090024 return uniphier_sld3_boot_device();
Masahiro Yamada323d1f92015-09-22 00:27:39 +090025#endif
Masahiro Yamadaea65c982016-03-18 16:41:43 +090026#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:
Masahiro Yamada5b660062016-03-30 20:17:02 +090031 return uniphier_ld4_boot_device();
Masahiro Yamada323d1f92015-09-22 00:27:39 +090032#endif
Masahiro Yamadaea65c982016-03-18 16:41:43 +090033#if defined(CONFIG_ARCH_UNIPHIER_PRO5)
34 case SOC_UNIPHIER_PRO5:
Masahiro Yamada5b660062016-03-30 20:17:02 +090035 return uniphier_pro5_boot_device();
Masahiro Yamada28f40d42015-09-22 00:27:40 +090036#endif
Masahiro Yamadaea65c982016-03-18 16:41:43 +090037#if defined(CONFIG_ARCH_UNIPHIER_PXS2) || defined(CONFIG_ARCH_UNIPHIER_LD6B)
38 case SOC_UNIPHIER_PXS2:
39 case SOC_UNIPHIER_LD6B:
Masahiro Yamada5b660062016-03-30 20:17:02 +090040 return uniphier_pxs2_boot_device();
Masahiro Yamada019df872015-09-22 00:27:41 +090041#endif
Masahiro Yamada667dbcd2016-05-24 21:14:01 +090042#if defined(CONFIG_ARCH_UNIPHIER_LD11) || defined(CONFIG_ARCH_UNIPHIER_LD20)
43 case SOC_UNIPHIER_LD11:
Masahiro Yamada9d0c2ce2016-04-21 14:43:18 +090044 case SOC_UNIPHIER_LD20:
45 return uniphier_ld20_boot_device();
46#endif
Masahiro Yamada323d1f92015-09-22 00:27:39 +090047 default:
48 return BOOT_DEVICE_NONE;
49 }
50}
Masahiro Yamadafec48162016-02-02 21:11:31 +090051
52u32 spl_boot_device(void)
53{
54 u32 ret;
55
56 ret = spl_boot_device_raw();
57
58 return ret == BOOT_DEVICE_USB ? BOOT_DEVICE_NOR : ret;
59}
Masahiro Yamadaa55d9fe2016-02-16 17:08:39 +090060
61u32 spl_boot_mode(void)
62{
63 struct mmc *mmc;
64
65 /*
66 * work around a bug in the Boot ROM of PH1-sLD3, LD4, Pro4, and sLD8:
67 *
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.
74 *
75 * Fixup mmc->part_config here because it is used to determine the
76 * partition which the U-Boot image is read from.
77 */
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;
81
82 return MMCSD_MODE_EMMCBOOT;
83}
Masahiro Yamada569e4be2016-02-16 17:08:40 +090084
85#if defined(CONFIG_DM_MMC) && !defined(CONFIG_SPL_BUILD)
86static int find_first_mmc_device(void)
87{
88 struct mmc *mmc;
89 int i;
90
91 for (i = 0; (mmc = find_mmc_device(i)); i++) {
92 if (!mmc_init(mmc) && IS_MMC(mmc))
93 return i;
94 }
95
96 return -ENODEV;
97}
98
Masahiro Yamadaaa8a9342016-02-16 17:08:42 +090099int mmc_get_env_dev(void)
100{
101 return find_first_mmc_device();
102}
103
Masahiro Yamada569e4be2016-02-16 17:08:40 +0900104static int do_mmcsetn(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
105{
106 int dev;
107
108 dev = find_first_mmc_device();
109 if (dev < 0)
110 return CMD_RET_FAILURE;
111
112 setenv_ulong("mmc_first_dev", dev);
113 return CMD_RET_SUCCESS;
114}
115
116U_BOOT_CMD(
117 mmcsetn, 1, 1, do_mmcsetn,
Robert P. J. Day1cc0a9f2016-05-04 04:47:31 -0400118 "Set the first MMC (not SD) dev number to \"mmc_first_dev\" environment",
Masahiro Yamada569e4be2016-02-16 17:08:40 +0900119 ""
120);
121#endif