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