Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 1 | /* |
| 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 Yamada | a55d9fe | 2016-02-16 17:08:39 +0900 | [diff] [blame] | 8 | #include <mmc.h> |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 9 | #include <spl.h> |
Masahiro Yamada | 569e4be | 2016-02-16 17:08:40 +0900 | [diff] [blame] | 10 | #include <linux/err.h> |
Masahiro Yamada | 107b3fb | 2016-01-09 01:51:13 +0900 | [diff] [blame] | 11 | |
| 12 | #include "../sbc/sbc-regs.h" |
| 13 | #include "../soc-info.h" |
| 14 | #include "boot-device.h" |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 15 | |
Masahiro Yamada | fec4816 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 16 | u32 spl_boot_device_raw(void) |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 17 | { |
| 18 | if (boot_is_swapped()) |
| 19 | return BOOT_DEVICE_NOR; |
| 20 | |
| 21 | switch (uniphier_get_soc_type()) { |
| 22 | #if defined(CONFIG_ARCH_UNIPHIER_PH1_SLD3) |
| 23 | case SOC_UNIPHIER_PH1_SLD3: |
| 24 | return ph1_sld3_boot_device(); |
| 25 | #endif |
| 26 | #if defined(CONFIG_ARCH_UNIPHIER_PH1_LD4) || \ |
| 27 | defined(CONFIG_ARCH_UNIPHIER_PH1_PRO4) || \ |
| 28 | defined(CONFIG_ARCH_UNIPHIER_PH1_SLD8) |
| 29 | case SOC_UNIPHIER_PH1_LD4: |
| 30 | case SOC_UNIPHIER_PH1_PRO4: |
| 31 | case SOC_UNIPHIER_PH1_SLD8: |
| 32 | return ph1_ld4_boot_device(); |
| 33 | #endif |
Masahiro Yamada | 28f40d4 | 2015-09-22 00:27:40 +0900 | [diff] [blame] | 34 | #if defined(CONFIG_ARCH_UNIPHIER_PH1_PRO5) |
| 35 | case SOC_UNIPHIER_PH1_PRO5: |
| 36 | return ph1_pro5_boot_device(); |
| 37 | #endif |
Masahiro Yamada | 019df87 | 2015-09-22 00:27:41 +0900 | [diff] [blame] | 38 | #if defined(CONFIG_ARCH_UNIPHIER_PROXSTREAM2) || \ |
| 39 | defined(CONFIG_ARCH_UNIPHIER_PH1_LD6B) |
| 40 | case SOC_UNIPHIER_PROXSTREAM2: |
| 41 | case SOC_UNIPHIER_PH1_LD6B: |
| 42 | return proxstream2_boot_device(); |
| 43 | #endif |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 44 | default: |
| 45 | return BOOT_DEVICE_NONE; |
| 46 | } |
| 47 | } |
Masahiro Yamada | fec4816 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 48 | |
| 49 | u32 spl_boot_device(void) |
| 50 | { |
| 51 | u32 ret; |
| 52 | |
| 53 | ret = spl_boot_device_raw(); |
| 54 | |
| 55 | return ret == BOOT_DEVICE_USB ? BOOT_DEVICE_NOR : ret; |
| 56 | } |
Masahiro Yamada | a55d9fe | 2016-02-16 17:08:39 +0900 | [diff] [blame] | 57 | |
| 58 | u32 spl_boot_mode(void) |
| 59 | { |
| 60 | struct mmc *mmc; |
| 61 | |
| 62 | /* |
| 63 | * work around a bug in the Boot ROM of PH1-sLD3, LD4, Pro4, and sLD8: |
| 64 | * |
| 65 | * The boot ROM in these SoCs breaks the PARTITION_CONFIG [179] of |
| 66 | * Extended CSD register; when switching to the Boot Partition 1, the |
| 67 | * Boot ROM should issue the SWITCH command (CMD6) with Set Bits for |
| 68 | * the Access Bits, but in fact it uses Write Byte for the Access Bits. |
| 69 | * As a result, the BOOT_PARTITION_ENABLE field of the PARTITION_CONFIG |
| 70 | * is lost. This bug was fixed for PH1-Pro5 and later SoCs. |
| 71 | * |
| 72 | * Fixup mmc->part_config here because it is used to determine the |
| 73 | * partition which the U-Boot image is read from. |
| 74 | */ |
| 75 | mmc = find_mmc_device(0); |
| 76 | mmc->part_config &= ~EXT_CSD_BOOT_PART_NUM(PART_ACCESS_MASK); |
| 77 | mmc->part_config |= EXT_CSD_BOOT_PARTITION_ENABLE; |
| 78 | |
| 79 | return MMCSD_MODE_EMMCBOOT; |
| 80 | } |
Masahiro Yamada | 569e4be | 2016-02-16 17:08:40 +0900 | [diff] [blame] | 81 | |
| 82 | #if defined(CONFIG_DM_MMC) && !defined(CONFIG_SPL_BUILD) |
| 83 | static int find_first_mmc_device(void) |
| 84 | { |
| 85 | struct mmc *mmc; |
| 86 | int i; |
| 87 | |
| 88 | for (i = 0; (mmc = find_mmc_device(i)); i++) { |
| 89 | if (!mmc_init(mmc) && IS_MMC(mmc)) |
| 90 | return i; |
| 91 | } |
| 92 | |
| 93 | return -ENODEV; |
| 94 | } |
| 95 | |
Masahiro Yamada | aa8a934 | 2016-02-16 17:08:42 +0900 | [diff] [blame^] | 96 | int mmc_get_env_dev(void) |
| 97 | { |
| 98 | return find_first_mmc_device(); |
| 99 | } |
| 100 | |
Masahiro Yamada | 569e4be | 2016-02-16 17:08:40 +0900 | [diff] [blame] | 101 | static int do_mmcsetn(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 102 | { |
| 103 | int dev; |
| 104 | |
| 105 | dev = find_first_mmc_device(); |
| 106 | if (dev < 0) |
| 107 | return CMD_RET_FAILURE; |
| 108 | |
| 109 | setenv_ulong("mmc_first_dev", dev); |
| 110 | return CMD_RET_SUCCESS; |
| 111 | } |
| 112 | |
| 113 | U_BOOT_CMD( |
| 114 | mmcsetn, 1, 1, do_mmcsetn, |
| 115 | "Set the first MMC (not SD) dev number to \"mmc_first_dev\" enviroment", |
| 116 | "" |
| 117 | ); |
| 118 | #endif |