]>
Commit | Line | Data |
---|---|---|
5894ca00 | 1 | /* |
40749d5a MY |
2 | * Copyright (C) 2014 Panasonic Corporation |
3 | * Copyright (C) 2015-2016 Socionext Inc. | |
4 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> | |
5894ca00 MY |
5 | * |
6 | * SPDX-License-Identifier: GPL-2.0+ | |
7 | */ | |
8 | ||
9 | #include <common.h> | |
10 | #include <spl.h> | |
8ea4f49a | 11 | #include <libfdt.h> |
5894ca00 | 12 | #include <nand.h> |
f6e7f07c | 13 | #include <linux/io.h> |
5894ca00 MY |
14 | #include <../drivers/mtd/nand/denali.h> |
15 | ||
784548ef | 16 | #include "init.h" |
fec48163 | 17 | |
5894ca00 MY |
18 | static void nand_denali_wp_disable(void) |
19 | { | |
20 | #ifdef CONFIG_NAND_DENALI | |
21 | /* | |
22 | * Since the boot rom enables the write protection for NAND boot mode, | |
23 | * it must be disabled somewhere for "nand write", "nand erase", etc. | |
24 | * The workaround is here to not disturb the Denali NAND controller | |
25 | * driver just for a really SoC-specific thing. | |
26 | */ | |
27 | void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE; | |
28 | ||
29 | writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT); | |
30 | #endif | |
31 | } | |
32 | ||
881aa5a7 | 33 | static int uniphier_set_fdt_file(void) |
8ea4f49a MY |
34 | { |
35 | DECLARE_GLOBAL_DATA_PTR; | |
881aa5a7 MY |
36 | const char *compat; |
37 | char dtb_name[256]; | |
40749d5a | 38 | int buf_len = sizeof(dtb_name); |
881aa5a7 | 39 | |
4565a74d MY |
40 | if (getenv("fdt_file")) |
41 | return 0; /* do nothing if it is already set */ | |
42 | ||
b02e4044 SG |
43 | compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL); |
44 | if (!compat) | |
881aa5a7 MY |
45 | return -EINVAL; |
46 | ||
40749d5a MY |
47 | /* rip off the vendor prefix "socionext," */ |
48 | compat = strchr(compat, ','); | |
49 | if (!compat) | |
881aa5a7 | 50 | return -EINVAL; |
40749d5a | 51 | compat++; |
881aa5a7 | 52 | |
40749d5a | 53 | strncpy(dtb_name, compat, buf_len); |
881aa5a7 MY |
54 | buf_len -= strlen(compat); |
55 | ||
56 | strncat(dtb_name, ".dtb", buf_len); | |
57 | ||
382bee57 | 58 | return env_set("fdt_file", dtb_name); |
8ea4f49a MY |
59 | } |
60 | ||
5894ca00 MY |
61 | int board_late_init(void) |
62 | { | |
63 | puts("MODE: "); | |
64 | ||
784548ef | 65 | switch (uniphier_boot_device_raw()) { |
5894ca00 | 66 | case BOOT_DEVICE_MMC1: |
63754842 | 67 | printf("eMMC Boot"); |
382bee57 | 68 | env_set("bootmode", "emmcboot"); |
5894ca00 MY |
69 | break; |
70 | case BOOT_DEVICE_NAND: | |
63754842 | 71 | printf("NAND Boot"); |
382bee57 | 72 | env_set("bootmode", "nandboot"); |
5894ca00 MY |
73 | nand_denali_wp_disable(); |
74 | break; | |
75 | case BOOT_DEVICE_NOR: | |
63754842 | 76 | printf("NOR Boot"); |
382bee57 | 77 | env_set("bootmode", "norboot"); |
5894ca00 | 78 | break; |
fec48163 | 79 | case BOOT_DEVICE_USB: |
63754842 | 80 | printf("USB Boot"); |
382bee57 | 81 | env_set("bootmode", "usbboot"); |
fec48163 | 82 | break; |
5894ca00 | 83 | default: |
63754842 | 84 | printf("Unknown"); |
d90b9745 | 85 | break; |
5894ca00 MY |
86 | } |
87 | ||
63754842 MY |
88 | if (uniphier_have_internal_stm()) |
89 | printf(" (STM: %s)", | |
90 | uniphier_boot_from_backend() ? "OFF" : "ON"); | |
91 | ||
92 | printf("\n"); | |
93 | ||
881aa5a7 MY |
94 | if (uniphier_set_fdt_file()) |
95 | printf("fdt_file environment was not set correctly\n"); | |
8ea4f49a | 96 | |
5894ca00 MY |
97 | return 0; |
98 | } |