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 | 0f4ec05 | 2017-01-21 18:05:24 +0900 | [diff] [blame] | 10 | #include <linux/errno.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 | |
Masahiro Yamada | e27d6c7 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 21 | switch (uniphier_get_soc_id()) { |
Masahiro Yamada | ea65c98 | 2016-03-18 16:41:43 +0900 | [diff] [blame] | 22 | #if defined(CONFIG_ARCH_UNIPHIER_SLD3) |
Masahiro Yamada | e27d6c7 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 23 | case UNIPHIER_SLD3_ID: |
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) |
Masahiro Yamada | e27d6c7 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 28 | case UNIPHIER_LD4_ID: |
| 29 | case UNIPHIER_PRO4_ID: |
| 30 | case UNIPHIER_SLD8_ID: |
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) |
Masahiro Yamada | e27d6c7 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 34 | case UNIPHIER_PRO5_ID: |
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) |
Masahiro Yamada | e27d6c7 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 38 | case UNIPHIER_PXS2_ID: |
| 39 | case UNIPHIER_LD6B_ID: |
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 | 667dbcd | 2016-05-24 21:14:01 +0900 | [diff] [blame] | 42 | #if defined(CONFIG_ARCH_UNIPHIER_LD11) || defined(CONFIG_ARCH_UNIPHIER_LD20) |
Masahiro Yamada | e27d6c7 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 43 | case UNIPHIER_LD11_ID: |
| 44 | case UNIPHIER_LD20_ID: |
Masahiro Yamada | 9d0c2ce | 2016-04-21 14:43:18 +0900 | [diff] [blame] | 45 | return uniphier_ld20_boot_device(); |
| 46 | #endif |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 47 | default: |
| 48 | return BOOT_DEVICE_NONE; |
| 49 | } |
| 50 | } |
Masahiro Yamada | fec4816 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 51 | |
| 52 | u32 spl_boot_device(void) |
| 53 | { |
Masahiro Yamada | adb3928 | 2016-06-04 22:39:08 +0900 | [diff] [blame] | 54 | u32 mode; |
Masahiro Yamada | fec4816 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 55 | |
Masahiro Yamada | adb3928 | 2016-06-04 22:39:08 +0900 | [diff] [blame] | 56 | mode = spl_boot_device_raw(); |
Masahiro Yamada | fec4816 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 57 | |
Masahiro Yamada | e27d6c7 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 58 | switch (uniphier_get_soc_id()) { |
Masahiro Yamada | adb3928 | 2016-06-04 22:39:08 +0900 | [diff] [blame] | 59 | #if defined(CONFIG_ARCH_UNIPHIER_PXS2) || defined(CONFIG_ARCH_UNIPHIER_LD6B) |
Masahiro Yamada | e27d6c7 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 60 | case UNIPHIER_PXS2_ID: |
| 61 | case UNIPHIER_LD6B_ID: |
Masahiro Yamada | adb3928 | 2016-06-04 22:39:08 +0900 | [diff] [blame] | 62 | if (mode == BOOT_DEVICE_USB) |
| 63 | mode = BOOT_DEVICE_NOR; |
| 64 | break; |
| 65 | #endif |
| 66 | #if defined(CONFIG_ARCH_UNIPHIER_LD11) || defined(CONFIG_ARCH_UNIPHIER_LD20) |
Masahiro Yamada | e27d6c7 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 67 | case UNIPHIER_LD11_ID: |
| 68 | case UNIPHIER_LD20_ID: |
Masahiro Yamada | adb3928 | 2016-06-04 22:39:08 +0900 | [diff] [blame] | 69 | if (mode == BOOT_DEVICE_MMC1 || mode == BOOT_DEVICE_USB) |
| 70 | mode = BOOT_DEVICE_BOARD; |
| 71 | break; |
| 72 | #endif |
| 73 | default: |
| 74 | break; |
| 75 | } |
| 76 | |
| 77 | return mode; |
Masahiro Yamada | fec4816 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 78 | } |
Masahiro Yamada | a55d9fe | 2016-02-16 17:08:39 +0900 | [diff] [blame] | 79 | |
Marek Vasut | 2b1cdaf | 2016-05-14 23:42:07 +0200 | [diff] [blame] | 80 | u32 spl_boot_mode(const u32 boot_device) |
Masahiro Yamada | a55d9fe | 2016-02-16 17:08:39 +0900 | [diff] [blame] | 81 | { |
| 82 | struct mmc *mmc; |
| 83 | |
| 84 | /* |
| 85 | * work around a bug in the Boot ROM of PH1-sLD3, LD4, Pro4, and sLD8: |
| 86 | * |
| 87 | * The boot ROM in these SoCs breaks the PARTITION_CONFIG [179] of |
| 88 | * Extended CSD register; when switching to the Boot Partition 1, the |
| 89 | * Boot ROM should issue the SWITCH command (CMD6) with Set Bits for |
| 90 | * the Access Bits, but in fact it uses Write Byte for the Access Bits. |
| 91 | * As a result, the BOOT_PARTITION_ENABLE field of the PARTITION_CONFIG |
| 92 | * is lost. This bug was fixed for PH1-Pro5 and later SoCs. |
| 93 | * |
| 94 | * Fixup mmc->part_config here because it is used to determine the |
| 95 | * partition which the U-Boot image is read from. |
| 96 | */ |
| 97 | mmc = find_mmc_device(0); |
| 98 | mmc->part_config &= ~EXT_CSD_BOOT_PART_NUM(PART_ACCESS_MASK); |
| 99 | mmc->part_config |= EXT_CSD_BOOT_PARTITION_ENABLE; |
| 100 | |
| 101 | return MMCSD_MODE_EMMCBOOT; |
| 102 | } |