blob: adcc929a474cc63fa90a91e84e8d40e5190ab738 [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 Yamada75f82d02018-03-05 01:20:11 +090011#include <linux/libfdt.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090012#include <nand.h>
Masahiro Yamada609cd532017-10-13 19:21:55 +090013#include <stdio.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +090014#include <linux/io.h>
Masahiro Yamada609cd532017-10-13 19:21:55 +090015#include <linux/printk.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090016#include <../drivers/mtd/nand/denali.h>
17
Masahiro Yamadafb092032017-02-14 01:24:26 +090018#include "init.h"
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090019
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090020static void nand_denali_wp_disable(void)
21{
22#ifdef CONFIG_NAND_DENALI
23 /*
24 * Since the boot rom enables the write protection for NAND boot mode,
25 * it must be disabled somewhere for "nand write", "nand erase", etc.
26 * The workaround is here to not disturb the Denali NAND controller
27 * driver just for a really SoC-specific thing.
28 */
29 void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
30
31 writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
32#endif
33}
34
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090035static int uniphier_set_fdt_file(void)
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090036{
37 DECLARE_GLOBAL_DATA_PTR;
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090038 const char *compat;
39 char dtb_name[256];
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090040 int buf_len = sizeof(dtb_name);
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090041
Simon Glass64b723f2017-08-03 12:22:12 -060042 if (env_get("fdt_file"))
Masahiro Yamadaafbde6f2016-06-07 21:03:44 +090043 return 0; /* do nothing if it is already set */
44
Simon Glassb0ea7402016-10-02 17:59:28 -060045 compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
46 if (!compat)
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090047 return -EINVAL;
48
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090049 /* rip off the vendor prefix "socionext," */
50 compat = strchr(compat, ',');
51 if (!compat)
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090052 return -EINVAL;
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090053 compat++;
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090054
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090055 strncpy(dtb_name, compat, buf_len);
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090056 buf_len -= strlen(compat);
57
58 strncat(dtb_name, ".dtb", buf_len);
59
Simon Glass6a38e412017-08-03 12:22:09 -060060 return env_set("fdt_file", dtb_name);
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090061}
62
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090063int board_late_init(void)
64{
65 puts("MODE: ");
66
Masahiro Yamadafb092032017-02-14 01:24:26 +090067 switch (uniphier_boot_device_raw()) {
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090068 case BOOT_DEVICE_MMC1:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090069 printf("eMMC Boot");
Simon Glass6a38e412017-08-03 12:22:09 -060070 env_set("bootmode", "emmcboot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090071 break;
72 case BOOT_DEVICE_NAND:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090073 printf("NAND Boot");
Simon Glass6a38e412017-08-03 12:22:09 -060074 env_set("bootmode", "nandboot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090075 nand_denali_wp_disable();
76 break;
77 case BOOT_DEVICE_NOR:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090078 printf("NOR Boot");
Simon Glass6a38e412017-08-03 12:22:09 -060079 env_set("bootmode", "norboot");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090080 break;
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090081 case BOOT_DEVICE_USB:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090082 printf("USB Boot");
Simon Glass6a38e412017-08-03 12:22:09 -060083 env_set("bootmode", "usbboot");
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090084 break;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090085 default:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090086 printf("Unknown");
Masahiro Yamada5572b0a2016-04-21 14:43:16 +090087 break;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090088 }
89
Masahiro Yamadaaf198102017-04-20 16:54:43 +090090 if (uniphier_have_internal_stm())
91 printf(" (STM: %s)",
92 uniphier_boot_from_backend() ? "OFF" : "ON");
93
94 printf("\n");
95
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090096 if (uniphier_set_fdt_file())
Masahiro Yamada609cd532017-10-13 19:21:55 +090097 pr_warn("fdt_file environment was not set correctly\n");
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090098
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090099 return 0;
100}