blob: ece761fb948b0665f1eae5d16d5545b08eaad6cc [file] [log] [blame]
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09001/*
Masahiro Yamadaadb349d2016-10-17 22:18:02 +09002 * Copyright (C) 2014 Panasonic Corporation
3 * Copyright (C) 2015-2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09005 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
10#include <spl.h>
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090011#include <libfdt.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090012#include <nand.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +090013#include <linux/io.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090014#include <../drivers/mtd/nand/denali.h>
15
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090016#include "boot-mode/boot-device.h"
17
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090018static void nand_denali_wp_disable(void)
19{
20#ifdef CONFIG_NAND_DENALI
21 /*
22 * Since the boot rom enables the write protection for NAND boot mode,
23 * it must be disabled somewhere for "nand write", "nand erase", etc.
24 * The workaround is here to not disturb the Denali NAND controller
25 * driver just for a really SoC-specific thing.
26 */
27 void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
28
29 writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
30#endif
31}
32
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090033static int uniphier_set_fdt_file(void)
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090034{
35 DECLARE_GLOBAL_DATA_PTR;
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090036 const char *compat;
37 char dtb_name[256];
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090038 int buf_len = sizeof(dtb_name);
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090039
Masahiro Yamadaafbde6f2016-06-07 21:03:44 +090040 if (getenv("fdt_file"))
41 return 0; /* do nothing if it is already set */
42
Simon Glassb0ea7402016-10-02 17:59:28 -060043 compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
44 if (!compat)
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090045 return -EINVAL;
46
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090047 /* rip off the vendor prefix "socionext," */
48 compat = strchr(compat, ',');
49 if (!compat)
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090050 return -EINVAL;
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090051 compat++;
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090052
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090053 strncpy(dtb_name, compat, buf_len);
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090054 buf_len -= strlen(compat);
55
56 strncat(dtb_name, ".dtb", buf_len);
57
Masahiro Yamada7d109782016-06-07 21:03:43 +090058 return setenv("fdt_file", dtb_name);
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090059}
60
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090061int board_late_init(void)
62{
63 puts("MODE: ");
64
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090065 switch (spl_boot_device_raw()) {
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090066 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;
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090079 case BOOT_DEVICE_USB:
80 printf("USB Boot\n");
81 setenv("bootmode", "usbboot");
82 break;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090083 default:
Masahiro Yamada5572b0a2016-04-21 14:43:16 +090084 printf("Unknown\n");
85 break;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090086 }
87
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090088 if (uniphier_set_fdt_file())
89 printf("fdt_file environment was not set correctly\n");
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090090
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090091 return 0;
92}