blob: 4bfa10b374ad8b2306f052d1ee75fb5f8e4dfe1a [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 Yamadafb092032017-02-14 01:24:26 +090016#include "init.h"
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090017
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 Yamadafb092032017-02-14 01:24:26 +090065 switch (uniphier_boot_device_raw()) {
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090066 case BOOT_DEVICE_MMC1:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090067 printf("eMMC Boot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090068 setenv("bootmode", "emmcboot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090069 break;
70 case BOOT_DEVICE_NAND:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090071 printf("NAND Boot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090072 setenv("bootmode", "nandboot");
73 nand_denali_wp_disable();
74 break;
75 case BOOT_DEVICE_NOR:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090076 printf("NOR Boot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090077 setenv("bootmode", "norboot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090078 break;
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090079 case BOOT_DEVICE_USB:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090080 printf("USB Boot");
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090081 setenv("bootmode", "usbboot");
82 break;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090083 default:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090084 printf("Unknown");
Masahiro Yamada5572b0a2016-04-21 14:43:16 +090085 break;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090086 }
87
Masahiro Yamadaaf198102017-04-20 16:54:43 +090088 if (uniphier_have_internal_stm())
89 printf(" (STM: %s)",
90 uniphier_boot_from_backend() ? "OFF" : "ON");
91
92 printf("\n");
93
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090094 if (uniphier_set_fdt_file())
95 printf("fdt_file environment was not set correctly\n");
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090096
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090097 return 0;
98}