blob: 972dbe8ae55380e8c270904334873f838669a8f4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09002/*
Masahiro Yamadaadb349d2016-10-17 22:18:02 +09003 * Copyright (C) 2014 Panasonic Corporation
4 * Copyright (C) 2015-2016 Socionext Inc.
5 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09006 */
7
8#include <common.h>
9#include <spl.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090010#include <linux/libfdt.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090011#include <nand.h>
Masahiro Yamada609cd532017-10-13 19:21:55 +090012#include <stdio.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +090013#include <linux/io.h>
Masahiro Yamada609cd532017-10-13 19:21:55 +090014#include <linux/printk.h>
Miquel Raynal1f1ae152018-08-16 17:30:07 +020015#include <../drivers/mtd/nand/raw/denali.h>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090016
Masahiro Yamadafb092032017-02-14 01:24:26 +090017#include "init.h"
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090018
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090019static void nand_denali_wp_disable(void)
20{
21#ifdef CONFIG_NAND_DENALI
22 /*
23 * Since the boot rom enables the write protection for NAND boot mode,
24 * it must be disabled somewhere for "nand write", "nand erase", etc.
25 * The workaround is here to not disturb the Denali NAND controller
26 * driver just for a really SoC-specific thing.
27 */
28 void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE;
29
30 writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT);
31#endif
32}
33
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];
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090039 int buf_len = sizeof(dtb_name);
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090040
Masahiro Yamada018f2fb2018-05-17 19:55:20 +090041 if (env_get("fdtfile"))
Masahiro Yamadaafbde6f2016-06-07 21:03:44 +090042 return 0; /* do nothing if it is already set */
43
Simon Glassb0ea7402016-10-02 17:59:28 -060044 compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
45 if (!compat)
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090046 return -EINVAL;
47
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090048 /* rip off the vendor prefix "socionext," */
49 compat = strchr(compat, ',');
50 if (!compat)
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090051 return -EINVAL;
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090052 compat++;
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090053
Masahiro Yamadaadb349d2016-10-17 22:18:02 +090054 strncpy(dtb_name, compat, buf_len);
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090055 buf_len -= strlen(compat);
56
57 strncat(dtb_name, ".dtb", buf_len);
58
Masahiro Yamada018f2fb2018-05-17 19:55:20 +090059 return env_set("fdtfile", dtb_name);
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090060}
61
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090062int board_late_init(void)
63{
64 puts("MODE: ");
65
Masahiro Yamadafb092032017-02-14 01:24:26 +090066 switch (uniphier_boot_device_raw()) {
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090067 case BOOT_DEVICE_MMC1:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090068 printf("eMMC Boot");
Masahiro Yamada93270eb2018-12-19 20:03:13 +090069 env_set("bootdev", "emmc");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090070 break;
71 case BOOT_DEVICE_NAND:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090072 printf("NAND Boot");
Masahiro Yamada93270eb2018-12-19 20:03:13 +090073 env_set("bootdev", "nand");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090074 nand_denali_wp_disable();
75 break;
76 case BOOT_DEVICE_NOR:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090077 printf("NOR Boot");
Masahiro Yamada93270eb2018-12-19 20:03:13 +090078 env_set("bootdev", "nor");
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090079 break;
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090080 case BOOT_DEVICE_USB:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090081 printf("USB Boot");
Masahiro Yamada93270eb2018-12-19 20:03:13 +090082 env_set("bootdev", "usb");
Masahiro Yamada5fe0e332016-02-02 21:11:31 +090083 break;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090084 default:
Masahiro Yamadaaf198102017-04-20 16:54:43 +090085 printf("Unknown");
Masahiro Yamada5572b0a2016-04-21 14:43:16 +090086 break;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090087 }
88
Masahiro Yamadaaf198102017-04-20 16:54:43 +090089 if (uniphier_have_internal_stm())
90 printf(" (STM: %s)",
91 uniphier_boot_from_backend() ? "OFF" : "ON");
92
93 printf("\n");
94
Masahiro Yamada8e3e0fe2016-04-21 14:43:17 +090095 if (uniphier_set_fdt_file())
Masahiro Yamada609cd532017-10-13 19:21:55 +090096 pr_warn("fdt_file environment was not set correctly\n");
Masahiro Yamadabf6e3fc2015-12-17 18:00:37 +090097
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090098 return 0;
99}