ARM: uniphier: make mem_map run-time configurable
[oweals/u-boot.git] / arch / arm / mach-uniphier / board_late_init.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2014      Panasonic Corporation
4  * Copyright (C) 2015-2016 Socionext Inc.
5  *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
6  */
7
8 #include <common.h>
9 #include <spl.h>
10 #include <linux/libfdt.h>
11 #include <nand.h>
12 #include <stdio.h>
13 #include <linux/io.h>
14 #include <linux/printk.h>
15 #include <../drivers/mtd/nand/raw/denali.h>
16
17 #include "init.h"
18
19 static void nand_denali_wp_disable(void)
20 {
21 #ifdef CONFIG_NAND_DENALI
22         /*
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.
27          */
28         void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
29
30         writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
31 #endif
32 }
33
34 static int uniphier_set_fdt_file(void)
35 {
36         DECLARE_GLOBAL_DATA_PTR;
37         const char *compat;
38         char dtb_name[256];
39         int buf_len = sizeof(dtb_name);
40
41         if (env_get("fdtfile"))
42                 return 0;       /* do nothing if it is already set */
43
44         compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
45         if (!compat)
46                 return -EINVAL;
47
48         /* rip off the vendor prefix "socionext,"  */
49         compat = strchr(compat, ',');
50         if (!compat)
51                 return -EINVAL;
52         compat++;
53
54         strncpy(dtb_name, compat, buf_len);
55         buf_len -= strlen(compat);
56
57         strncat(dtb_name, ".dtb", buf_len);
58
59         return env_set("fdtfile", dtb_name);
60 }
61
62 int board_late_init(void)
63 {
64         puts("MODE:  ");
65
66         switch (uniphier_boot_device_raw()) {
67         case BOOT_DEVICE_MMC1:
68                 printf("eMMC Boot");
69                 env_set("bootdev", "emmc");
70                 break;
71         case BOOT_DEVICE_MMC2:
72                 printf("SD Boot");
73                 env_set("bootdev", "sd");
74                 break;
75         case BOOT_DEVICE_NAND:
76                 printf("NAND Boot");
77                 env_set("bootdev", "nand");
78                 nand_denali_wp_disable();
79                 break;
80         case BOOT_DEVICE_NOR:
81                 printf("NOR Boot");
82                 env_set("bootdev", "nor");
83                 break;
84         case BOOT_DEVICE_USB:
85                 printf("USB Boot");
86                 env_set("bootdev", "usb");
87                 break;
88         default:
89                 printf("Unknown");
90                 break;
91         }
92
93         if (uniphier_have_internal_stm())
94                 printf(" (STM: %s)",
95                        uniphier_boot_from_backend() ? "OFF" : "ON");
96
97         printf("\n");
98
99         if (uniphier_set_fdt_file())
100                 pr_warn("fdt_file environment was not set correctly\n");
101
102         return 0;
103 }