1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2014 Panasonic Corporation
4 * Copyright (C) 2015-2016 Socionext Inc.
12 #include <linux/libfdt.h>
16 #include <linux/printk.h>
17 #include <../drivers/mtd/nand/raw/denali.h>
21 static void nand_denali_wp_disable(void)
23 #ifdef CONFIG_NAND_DENALI
25 * Since the boot rom enables the write protection for NAND boot mode,
26 * it must be disabled somewhere for "nand write", "nand erase", etc.
27 * The workaround is here to not disturb the Denali NAND controller
28 * driver just for a really SoC-specific thing.
30 void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
32 writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
36 static void uniphier_set_env_fdt_file(void)
38 DECLARE_GLOBAL_DATA_PTR;
41 int buf_len = sizeof(dtb_name);
44 if (env_get("fdtfile"))
45 return; /* do nothing if it is already set */
47 compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
51 /* rip off the vendor prefix "socionext," */
52 compat = strchr(compat, ',');
57 strncpy(dtb_name, compat, buf_len);
58 buf_len -= strlen(compat);
60 strncat(dtb_name, ".dtb", buf_len);
62 ret = env_set("fdtfile", dtb_name);
68 pr_warn("\"fdt_file\" environment variable was not set correctly\n");
71 static void uniphier_set_env_addr(const char *env, const char *offset_env)
73 unsigned long offset = 0;
79 return; /* do nothing if it is already set */
82 str = env_get(offset_env);
86 offset = simple_strtoul(str, &end, 16);
91 ret = env_set_hex(env, gd->ram_base + offset);
98 pr_warn("\"%s\" environment variable was not set correctly\n", env);
101 int board_late_init(void)
105 switch (uniphier_boot_device_raw()) {
106 case BOOT_DEVICE_MMC1:
108 env_set("bootdev", "emmc");
110 case BOOT_DEVICE_MMC2:
112 env_set("bootdev", "sd");
114 case BOOT_DEVICE_NAND:
116 env_set("bootdev", "nand");
117 nand_denali_wp_disable();
119 case BOOT_DEVICE_NOR:
121 env_set("bootdev", "nor");
123 case BOOT_DEVICE_USB:
125 env_set("bootdev", "usb");
132 if (uniphier_have_internal_stm())
134 uniphier_boot_from_backend() ? "OFF" : "ON");
138 uniphier_set_env_fdt_file();
140 uniphier_set_env_addr("dram_base", NULL);
142 uniphier_set_env_addr("loadaddr", "loadaddr_offset");
144 uniphier_set_env_addr("kernel_addr_r", "kernel_addr_r_offset");
145 uniphier_set_env_addr("ramdisk_addr_r", "ramdisk_addr_r_offset");
146 uniphier_set_env_addr("fdt_addr_r", "fdt_addr_r_offset");