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>
11 #include <linux/libfdt.h>
15 #include <linux/printk.h>
16 #include <../drivers/mtd/nand/raw/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 void uniphier_set_env_fdt_file(void)
37 DECLARE_GLOBAL_DATA_PTR;
40 int buf_len = sizeof(dtb_name);
43 if (env_get("fdtfile"))
44 return; /* do nothing if it is already set */
46 compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
50 /* rip off the vendor prefix "socionext," */
51 compat = strchr(compat, ',');
56 strncpy(dtb_name, compat, buf_len);
57 buf_len -= strlen(compat);
59 strncat(dtb_name, ".dtb", buf_len);
61 ret = env_set("fdtfile", dtb_name);
67 pr_warn("\"fdt_file\" environment variable was not set correctly\n");
70 static void uniphier_set_env_addr(const char *env, const char *offset_env)
72 unsigned long offset = 0;
78 return; /* do nothing if it is already set */
81 str = env_get(offset_env);
85 offset = simple_strtoul(str, &end, 16);
90 ret = env_set_hex(env, gd->ram_base + offset);
97 pr_warn("\"%s\" environment variable was not set correctly\n", env);
100 int board_late_init(void)
104 switch (uniphier_boot_device_raw()) {
105 case BOOT_DEVICE_MMC1:
107 env_set("bootdev", "emmc");
109 case BOOT_DEVICE_MMC2:
111 env_set("bootdev", "sd");
113 case BOOT_DEVICE_NAND:
115 env_set("bootdev", "nand");
116 nand_denali_wp_disable();
118 case BOOT_DEVICE_NOR:
120 env_set("bootdev", "nor");
122 case BOOT_DEVICE_USB:
124 env_set("bootdev", "usb");
131 if (uniphier_have_internal_stm())
133 uniphier_boot_from_backend() ? "OFF" : "ON");
137 uniphier_set_env_fdt_file();
139 uniphier_set_env_addr("dram_base", NULL);
141 uniphier_set_env_addr("loadaddr", "loadaddr_offset");
143 uniphier_set_env_addr("kernel_addr_r", "kernel_addr_r_offset");
144 uniphier_set_env_addr("ramdisk_addr_r", "ramdisk_addr_r_offset");
145 uniphier_set_env_addr("fdt_addr_r", "fdt_addr_r_offset");