1*81c847bfSMasahiro Yamada /*
2*81c847bfSMasahiro Yamada  * Copyright (C) 2016 Socionext Inc.
3*81c847bfSMasahiro Yamada  *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
4*81c847bfSMasahiro Yamada  *
5*81c847bfSMasahiro Yamada  * SPDX-License-Identifier:	GPL-2.0+
6*81c847bfSMasahiro Yamada  */
7*81c847bfSMasahiro Yamada 
8*81c847bfSMasahiro Yamada #include <common.h>
9*81c847bfSMasahiro Yamada #include <mmc.h>
10*81c847bfSMasahiro Yamada #include <spl.h>
11*81c847bfSMasahiro Yamada 
12*81c847bfSMasahiro Yamada u32 spl_boot_mode(const u32 boot_device)
13*81c847bfSMasahiro Yamada {
14*81c847bfSMasahiro Yamada 	struct mmc *mmc;
15*81c847bfSMasahiro Yamada 
16*81c847bfSMasahiro Yamada 	/*
17*81c847bfSMasahiro Yamada 	 * work around a bug in the Boot ROM of PH1-sLD3, LD4, Pro4, and sLD8:
18*81c847bfSMasahiro Yamada 	 *
19*81c847bfSMasahiro Yamada 	 * The boot ROM in these SoCs breaks the PARTITION_CONFIG [179] of
20*81c847bfSMasahiro Yamada 	 * Extended CSD register; when switching to the Boot Partition 1, the
21*81c847bfSMasahiro Yamada 	 * Boot ROM should issue the SWITCH command (CMD6) with Set Bits for
22*81c847bfSMasahiro Yamada 	 * the Access Bits, but in fact it uses Write Byte for the Access Bits.
23*81c847bfSMasahiro Yamada 	 * As a result, the BOOT_PARTITION_ENABLE field of the PARTITION_CONFIG
24*81c847bfSMasahiro Yamada 	 * is lost.  This bug was fixed for PH1-Pro5 and later SoCs.
25*81c847bfSMasahiro Yamada 	 *
26*81c847bfSMasahiro Yamada 	 * Fixup mmc->part_config here because it is used to determine the
27*81c847bfSMasahiro Yamada 	 * partition which the U-Boot image is read from.
28*81c847bfSMasahiro Yamada 	 */
29*81c847bfSMasahiro Yamada 	mmc = find_mmc_device(0);
30*81c847bfSMasahiro Yamada 	mmc->part_config &= ~EXT_CSD_BOOT_PART_NUM(PART_ACCESS_MASK);
31*81c847bfSMasahiro Yamada 	mmc->part_config |= EXT_CSD_BOOT_PARTITION_ENABLE;
32*81c847bfSMasahiro Yamada 
33*81c847bfSMasahiro Yamada 	return MMCSD_MODE_EMMCBOOT;
34*81c847bfSMasahiro Yamada }
35