Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 2 | * Copyright (C) 2014 Panasonic Corporation |
| 3 | * Copyright (C) 2015-2016 Socionext Inc. |
| 4 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <spl.h> |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 11 | #include <libfdt.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 12 | #include <nand.h> |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 13 | #include <linux/io.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 14 | #include <../drivers/mtd/nand/denali.h> |
| 15 | |
Masahiro Yamada | fb09203 | 2017-02-14 01:24:26 +0900 | [diff] [blame] | 16 | #include "init.h" |
Masahiro Yamada | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 17 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 18 | static 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 Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 33 | static int uniphier_set_fdt_file(void) |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 34 | { |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 36 | const char *compat; |
| 37 | char dtb_name[256]; |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 38 | int buf_len = sizeof(dtb_name); |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 39 | |
Masahiro Yamada | afbde6f | 2016-06-07 21:03:44 +0900 | [diff] [blame] | 40 | if (getenv("fdt_file")) |
| 41 | return 0; /* do nothing if it is already set */ |
| 42 | |
Simon Glass | b0ea740 | 2016-10-02 17:59:28 -0600 | [diff] [blame] | 43 | compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL); |
| 44 | if (!compat) |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 45 | return -EINVAL; |
| 46 | |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 47 | /* rip off the vendor prefix "socionext," */ |
| 48 | compat = strchr(compat, ','); |
| 49 | if (!compat) |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 50 | return -EINVAL; |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 51 | compat++; |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 52 | |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 53 | strncpy(dtb_name, compat, buf_len); |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 54 | buf_len -= strlen(compat); |
| 55 | |
| 56 | strncat(dtb_name, ".dtb", buf_len); |
| 57 | |
Masahiro Yamada | 7d10978 | 2016-06-07 21:03:43 +0900 | [diff] [blame] | 58 | return setenv("fdt_file", dtb_name); |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 59 | } |
| 60 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 61 | int board_late_init(void) |
| 62 | { |
| 63 | puts("MODE: "); |
| 64 | |
Masahiro Yamada | fb09203 | 2017-02-14 01:24:26 +0900 | [diff] [blame] | 65 | switch (uniphier_boot_device_raw()) { |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 66 | case BOOT_DEVICE_MMC1: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 67 | printf("eMMC Boot"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 68 | setenv("bootmode", "emmcboot"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 69 | break; |
| 70 | case BOOT_DEVICE_NAND: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 71 | printf("NAND Boot"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 72 | setenv("bootmode", "nandboot"); |
| 73 | nand_denali_wp_disable(); |
| 74 | break; |
| 75 | case BOOT_DEVICE_NOR: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 76 | printf("NOR Boot"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 77 | setenv("bootmode", "norboot"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 78 | break; |
Masahiro Yamada | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 79 | case BOOT_DEVICE_USB: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 80 | printf("USB Boot"); |
Masahiro Yamada | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 81 | setenv("bootmode", "usbboot"); |
| 82 | break; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 83 | default: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 84 | printf("Unknown"); |
Masahiro Yamada | 5572b0a | 2016-04-21 14:43:16 +0900 | [diff] [blame] | 85 | break; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 86 | } |
| 87 | |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 88 | if (uniphier_have_internal_stm()) |
| 89 | printf(" (STM: %s)", |
| 90 | uniphier_boot_from_backend() ? "OFF" : "ON"); |
| 91 | |
| 92 | printf("\n"); |
| 93 | |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 94 | if (uniphier_set_fdt_file()) |
| 95 | printf("fdt_file environment was not set correctly\n"); |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 96 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 97 | return 0; |
| 98 | } |