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+
14 #include <../drivers/mtd/nand/denali.h>
18 static void nand_denali_wp_disable(void)
20 #ifdef CONFIG_NAND_DENALI
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.
27 void __iomem
*denali_reg
= (void __iomem
*)CONFIG_SYS_NAND_REGS_BASE
;
29 writel(WRITE_PROTECT__FLAG
, denali_reg
+ WRITE_PROTECT
);
33 static int uniphier_set_fdt_file(void)
35 DECLARE_GLOBAL_DATA_PTR
;
38 int buf_len
= sizeof(dtb_name
);
40 if (getenv("fdt_file"))
41 return 0; /* do nothing if it is already set */
43 compat
= fdt_stringlist_get(gd
->fdt_blob
, 0, "compatible", 0, NULL
);
47 /* rip off the vendor prefix "socionext," */
48 compat
= strchr(compat
, ',');
53 strncpy(dtb_name
, compat
, buf_len
);
54 buf_len
-= strlen(compat
);
56 strncat(dtb_name
, ".dtb", buf_len
);
58 return env_set("fdt_file", dtb_name
);
61 int board_late_init(void)
65 switch (uniphier_boot_device_raw()) {
66 case BOOT_DEVICE_MMC1
:
68 env_set("bootmode", "emmcboot");
70 case BOOT_DEVICE_NAND
:
72 env_set("bootmode", "nandboot");
73 nand_denali_wp_disable();
77 env_set("bootmode", "norboot");
81 env_set("bootmode", "usbboot");
88 if (uniphier_have_internal_stm())
90 uniphier_boot_from_backend() ? "OFF" : "ON");
94 if (uniphier_set_fdt_file())
95 printf("fdt_file environment was not set correctly\n");