2 * Copyright (C) 2014 Panasonic Corporation
3 * Copyright (C) 2015-2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <linux/libfdt.h>
15 #include <linux/printk.h>
16 #include <../drivers/mtd/nand/denali.h>
20 static void nand_denali_wp_disable(void)
22 #ifdef CONFIG_NAND_DENALI
24 * Since the boot rom enables the write protection for NAND boot mode,
25 * it must be disabled somewhere for "nand write", "nand erase", etc.
26 * The workaround is here to not disturb the Denali NAND controller
27 * driver just for a really SoC-specific thing.
29 void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
31 writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
35 static int uniphier_set_fdt_file(void)
37 DECLARE_GLOBAL_DATA_PTR;
40 int buf_len = sizeof(dtb_name);
42 if (env_get("fdt_file"))
43 return 0; /* do nothing if it is already set */
45 compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
49 /* rip off the vendor prefix "socionext," */
50 compat = strchr(compat, ',');
55 strncpy(dtb_name, compat, buf_len);
56 buf_len -= strlen(compat);
58 strncat(dtb_name, ".dtb", buf_len);
60 return env_set("fdt_file", dtb_name);
63 int board_late_init(void)
67 switch (uniphier_boot_device_raw()) {
68 case BOOT_DEVICE_MMC1:
70 env_set("bootmode", "emmcboot");
72 case BOOT_DEVICE_NAND:
74 env_set("bootmode", "nandboot");
75 nand_denali_wp_disable();
79 env_set("bootmode", "norboot");
83 env_set("bootmode", "usbboot");
90 if (uniphier_have_internal_stm())
92 uniphier_boot_from_backend() ? "OFF" : "ON");
96 if (uniphier_set_fdt_file())
97 pr_warn("fdt_file environment was not set correctly\n");