blob: 845f047b027da675425f70f1d7bf548b28e2e549 [file] [log] [blame]
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09001/*
Masahiro Yamada663a23f2015-05-29 17:30:00 +09002 * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <spl.h>
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +09009#include <libfdt.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090010#include <nand.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +090011#include <linux/io.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090012#include <../drivers/mtd/nand/denali.h>
13
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090014#include "boot-mode/boot-device.h"
15
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090016static void nand_denali_wp_disable(void)
17{
18#ifdef CONFIG_NAND_DENALI
19 /*
20 * Since the boot rom enables the write protection for NAND boot mode,
21 * it must be disabled somewhere for "nand write", "nand erase", etc.
22 * The workaround is here to not disturb the Denali NAND controller
23 * driver just for a really SoC-specific thing.
24 */
25 void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
26
27 writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
28#endif
29}
30
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090031#define VENDOR_PREFIX "socionext,"
32#define DTB_FILE_PREFIX "uniphier-"
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090033
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090034static int uniphier_set_fdt_file(void)
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090035{
36 DECLARE_GLOBAL_DATA_PTR;
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090037 const char *compat;
38 char dtb_name[256];
39 int buf_len = 256;
40 int ret;
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090041
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090042 ret = fdt_get_string(gd->fdt_blob, 0, "compatible", &compat);
43 if (ret)
44 return -EINVAL;
45
46 if (strncmp(compat, VENDOR_PREFIX, strlen(VENDOR_PREFIX)))
47 return -EINVAL;
48
49 compat += strlen(VENDOR_PREFIX);
50
51 strncat(dtb_name, DTB_FILE_PREFIX, buf_len);
52 buf_len -= strlen(DTB_FILE_PREFIX);
53
54 strncat(dtb_name, compat, buf_len);
55 buf_len -= strlen(compat);
56
57 strncat(dtb_name, ".dtb", buf_len);
58
59 setenv("fdt_file", dtb_name);
60
61 return 0;
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090062}
63
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090064int board_late_init(void)
65{
66 puts("MODE: ");
67
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090068 switch (spl_boot_device_raw()) {
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090069 case BOOT_DEVICE_MMC1:
70 printf("eMMC Boot\n");
71 setenv("bootmode", "emmcboot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090072 break;
73 case BOOT_DEVICE_NAND:
74 printf("NAND Boot\n");
75 setenv("bootmode", "nandboot");
76 nand_denali_wp_disable();
77 break;
78 case BOOT_DEVICE_NOR:
79 printf("NOR Boot\n");
80 setenv("bootmode", "norboot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090081 break;
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090082 case BOOT_DEVICE_USB:
83 printf("USB Boot\n");
84 setenv("bootmode", "usbboot");
85 break;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090086 default:
Masahiro Yamada5572b0a2016-04-21 14:43:16 +090087 printf("Unknown\n");
88 break;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090089 }
90
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090091 if (uniphier_set_fdt_file())
92 printf("fdt_file environment was not set correctly\n");
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090093
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090094 return 0;
95}