blob: c2a32618acc7c607fa8ef60e4ff35a0987f4f8bf [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
14static void nand_denali_wp_disable(void)
15{
16#ifdef CONFIG_NAND_DENALI
17 /*
18 * Since the boot rom enables the write protection for NAND boot mode,
19 * it must be disabled somewhere for "nand write", "nand erase", etc.
20 * The workaround is here to not disturb the Denali NAND controller
21 * driver just for a really SoC-specific thing.
22 */
23 void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
24
25 writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
26#endif
27}
28
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090029struct uniphier_fdt_file {
30 const char *compatible;
31 const char *file_name;
32};
33
34static const struct uniphier_fdt_file uniphier_fdt_files[] = {
35 { "socionext,ph1-ld4-ref", "uniphier-ph1-ld4-ref.dtb", },
36 { "socionext,ph1-ld6b-ref", "uniphier-ph1-ld6b-ref.dtb", },
37 { "socionext,ph1-ld10-ref", "uniphier-ph1-ld10-ref.dtb", },
38 { "socionext,ph1-pro4-ref", "uniphier-ph1-pro4-ref.dtb", },
39 { "socionext,ph1-pro5-4kbox", "uniphier-ph1-pro5-4kbox.dtb", },
40 { "socionext,ph1-sld3-ref", "uniphier-ph1-sld3-ref.dtb", },
41 { "socionext,ph1-sld8-ref", "uniphier-ph1-sld8-ref.dtb", },
42 { "socionext,proxstream2-gentil", "uniphier-proxstream2-gentil.dtb", },
43 { "socionext,proxstream2-vodka", "uniphier-proxstream2-vodka.dtb", },
44};
45
46static void uniphier_set_fdt_file(void)
47{
48 DECLARE_GLOBAL_DATA_PTR;
49 int i;
50
51 /* lookup DTB file name based on the compatible string */
52 for (i = 0; i < ARRAY_SIZE(uniphier_fdt_files); i++) {
53 if (!fdt_node_check_compatible(gd->fdt_blob, 0,
54 uniphier_fdt_files[i].compatible)) {
55 setenv("fdt_file", uniphier_fdt_files[i].file_name);
56 return;
57 }
58 }
59}
60
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090061int board_late_init(void)
62{
63 puts("MODE: ");
64
65 switch (spl_boot_device()) {
66 case BOOT_DEVICE_MMC1:
67 printf("eMMC Boot\n");
68 setenv("bootmode", "emmcboot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090069 break;
70 case BOOT_DEVICE_NAND:
71 printf("NAND Boot\n");
72 setenv("bootmode", "nandboot");
73 nand_denali_wp_disable();
74 break;
75 case BOOT_DEVICE_NOR:
76 printf("NOR Boot\n");
77 setenv("bootmode", "norboot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090078 break;
79 default:
80 printf("Unsupported Boot Mode\n");
81 return -1;
82 }
83
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090084 uniphier_set_fdt_file();
85
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090086 return 0;
87}