1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2014 Panasonic Corporation
4 * Copyright (C) 2015-2016 Socionext Inc.
5 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
10 #include <linux/libfdt.h>
14 #include <linux/printk.h>
15 #include <../drivers/mtd/nand/denali.h>
19 static void nand_denali_wp_disable(void)
21 #ifdef CONFIG_NAND_DENALI
23 * Since the boot rom enables the write protection for NAND boot mode,
24 * it must be disabled somewhere for "nand write", "nand erase", etc.
25 * The workaround is here to not disturb the Denali NAND controller
26 * driver just for a really SoC-specific thing.
28 void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
30 writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
34 static int uniphier_set_fdt_file(void)
36 DECLARE_GLOBAL_DATA_PTR;
39 int buf_len = sizeof(dtb_name);
41 if (env_get("fdtfile"))
42 return 0; /* do nothing if it is already set */
44 compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
48 /* rip off the vendor prefix "socionext," */
49 compat = strchr(compat, ',');
54 strncpy(dtb_name, compat, buf_len);
55 buf_len -= strlen(compat);
57 strncat(dtb_name, ".dtb", buf_len);
59 return env_set("fdtfile", dtb_name);
62 int board_late_init(void)
66 switch (uniphier_boot_device_raw()) {
67 case BOOT_DEVICE_MMC1:
69 env_set("bootcmd", "run bootcmd_mmc0; run distro_bootcmd");
71 case BOOT_DEVICE_NAND:
73 env_set("bootcmd", "run bootcmd_ubifs0; run distro_bootcmd");
74 nand_denali_wp_disable();
78 env_set("bootcmd", "run tftpboot; run distro_bootcmd");
82 env_set("bootcmd", "run bootcmd_usb0; run distro_bootcmd");
89 if (uniphier_have_internal_stm())
91 uniphier_boot_from_backend() ? "OFF" : "ON");
95 if (uniphier_set_fdt_file())
96 pr_warn("fdt_file environment was not set correctly\n");