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/raw/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 void uniphier_set_env_fdt_file(void)
36 DECLARE_GLOBAL_DATA_PTR;
39 int buf_len = sizeof(dtb_name);
42 if (env_get("fdtfile"))
43 return; /* 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 ret = env_set("fdtfile", dtb_name);
66 pr_warn("\"fdt_file\" environment variable was not set correctly\n");
69 static void uniphier_set_env_addr(const char *env, const char *offset_env)
71 unsigned long offset = 0;
77 return; /* do nothing if it is already set */
80 str = env_get(offset_env);
84 offset = simple_strtoul(str, &end, 16);
89 ret = env_set_hex(env, gd->ram_base + offset);
96 pr_warn("\"%s\" environment variable was not set correctly\n", env);
99 int board_late_init(void)
103 switch (uniphier_boot_device_raw()) {
104 case BOOT_DEVICE_MMC1:
106 env_set("bootdev", "emmc");
108 case BOOT_DEVICE_MMC2:
110 env_set("bootdev", "sd");
112 case BOOT_DEVICE_NAND:
114 env_set("bootdev", "nand");
115 nand_denali_wp_disable();
117 case BOOT_DEVICE_NOR:
119 env_set("bootdev", "nor");
121 case BOOT_DEVICE_USB:
123 env_set("bootdev", "usb");
130 if (uniphier_have_internal_stm())
132 uniphier_boot_from_backend() ? "OFF" : "ON");
136 uniphier_set_env_fdt_file();
138 uniphier_set_env_addr("dram_base", NULL);
140 uniphier_set_env_addr("loadaddr", "loadaddr_offset");
142 uniphier_set_env_addr("kernel_addr_r", "kernel_addr_r_offset");
143 uniphier_set_env_addr("ramdisk_addr_r", "ramdisk_addr_r_offset");
144 uniphier_set_env_addr("fdt_addr_r", "fdt_addr_r_offset");