2 * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
4 * SPDX-License-Identifier: GPL-2.0+
12 #include <../drivers/mtd/nand/denali.h>
14 #include "boot-mode/boot-device.h"
16 static void nand_denali_wp_disable(void)
18 #ifdef CONFIG_NAND_DENALI
20 * Since the boot rom enables the write protection for NAND boot mode,
21 * it must be disabled somewhere for "nand write", "nand erase", etc.
22 * The workaround is here to not disturb the Denali NAND controller
23 * driver just for a really SoC-specific thing.
25 void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
27 writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
31 #define VENDOR_PREFIX "socionext,"
32 #define DTB_FILE_PREFIX "uniphier-"
34 static int uniphier_set_fdt_file(void)
36 DECLARE_GLOBAL_DATA_PTR;
42 if (getenv("fdt_file"))
43 return 0; /* do nothing if it is already set */
45 ret = fdt_get_string(gd->fdt_blob, 0, "compatible", &compat);
49 if (strncmp(compat, VENDOR_PREFIX, strlen(VENDOR_PREFIX)))
52 compat += strlen(VENDOR_PREFIX);
54 strncat(dtb_name, DTB_FILE_PREFIX, buf_len);
55 buf_len -= strlen(DTB_FILE_PREFIX);
57 strncat(dtb_name, compat, buf_len);
58 buf_len -= strlen(compat);
60 strncat(dtb_name, ".dtb", buf_len);
62 return setenv("fdt_file", dtb_name);
65 int board_late_init(void)
69 switch (spl_boot_device_raw()) {
70 case BOOT_DEVICE_MMC1:
71 printf("eMMC Boot\n");
72 setenv("bootmode", "emmcboot");
74 case BOOT_DEVICE_NAND:
75 printf("NAND Boot\n");
76 setenv("bootmode", "nandboot");
77 nand_denali_wp_disable();
81 setenv("bootmode", "norboot");
85 setenv("bootmode", "usbboot");
92 if (uniphier_set_fdt_file())
93 printf("fdt_file environment was not set correctly\n");