Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | f6e7f07 | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 2 | * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <spl.h> |
Masahiro Yamada | 8ea4f49 | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 9 | #include <libfdt.h> |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 10 | #include <nand.h> |
Masahiro Yamada | f6e7f07 | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 11 | #include <linux/io.h> |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 12 | #include <../drivers/mtd/nand/denali.h> |
| 13 | |
Masahiro Yamada | fec4816 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 14 | #include "boot-mode/boot-device.h" |
| 15 | |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 16 | static void nand_denali_wp_disable(void) |
| 17 | { |
| 18 | #ifdef CONFIG_NAND_DENALI |
| 19 | /* |
| 20 | * Since the boot rom enables the write protection for NAND boot mode, |
| 21 | * it must be disabled somewhere for "nand write", "nand erase", etc. |
| 22 | * The workaround is here to not disturb the Denali NAND controller |
| 23 | * driver just for a really SoC-specific thing. |
| 24 | */ |
| 25 | void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE; |
| 26 | |
| 27 | writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT); |
| 28 | #endif |
| 29 | } |
| 30 | |
Masahiro Yamada | 881aa5a | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 31 | #define VENDOR_PREFIX "socionext," |
| 32 | #define DTB_FILE_PREFIX "uniphier-" |
Masahiro Yamada | 8ea4f49 | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 33 | |
Masahiro Yamada | 881aa5a | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 34 | static int uniphier_set_fdt_file(void) |
Masahiro Yamada | 8ea4f49 | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 35 | { |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
Masahiro Yamada | 881aa5a | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 37 | const char *compat; |
| 38 | char dtb_name[256]; |
| 39 | int buf_len = 256; |
| 40 | int ret; |
Masahiro Yamada | 8ea4f49 | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 41 | |
Masahiro Yamada | 4565a74 | 2016-06-07 21:03:44 +0900 | [diff] [blame] | 42 | if (getenv("fdt_file")) |
| 43 | return 0; /* do nothing if it is already set */ |
| 44 | |
Masahiro Yamada | 881aa5a | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 45 | ret = fdt_get_string(gd->fdt_blob, 0, "compatible", &compat); |
| 46 | if (ret) |
| 47 | return -EINVAL; |
| 48 | |
| 49 | if (strncmp(compat, VENDOR_PREFIX, strlen(VENDOR_PREFIX))) |
| 50 | return -EINVAL; |
| 51 | |
| 52 | compat += strlen(VENDOR_PREFIX); |
| 53 | |
| 54 | strncat(dtb_name, DTB_FILE_PREFIX, buf_len); |
| 55 | buf_len -= strlen(DTB_FILE_PREFIX); |
| 56 | |
| 57 | strncat(dtb_name, compat, buf_len); |
| 58 | buf_len -= strlen(compat); |
| 59 | |
| 60 | strncat(dtb_name, ".dtb", buf_len); |
| 61 | |
Masahiro Yamada | 80630da | 2016-06-07 21:03:43 +0900 | [diff] [blame] | 62 | return setenv("fdt_file", dtb_name); |
Masahiro Yamada | 8ea4f49 | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 63 | } |
| 64 | |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 65 | int board_late_init(void) |
| 66 | { |
| 67 | puts("MODE: "); |
| 68 | |
Masahiro Yamada | fec4816 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 69 | switch (spl_boot_device_raw()) { |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 70 | case BOOT_DEVICE_MMC1: |
| 71 | printf("eMMC Boot\n"); |
| 72 | setenv("bootmode", "emmcboot"); |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 73 | break; |
| 74 | case BOOT_DEVICE_NAND: |
| 75 | printf("NAND Boot\n"); |
| 76 | setenv("bootmode", "nandboot"); |
| 77 | nand_denali_wp_disable(); |
| 78 | break; |
| 79 | case BOOT_DEVICE_NOR: |
| 80 | printf("NOR Boot\n"); |
| 81 | setenv("bootmode", "norboot"); |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 82 | break; |
Masahiro Yamada | fec4816 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 83 | case BOOT_DEVICE_USB: |
| 84 | printf("USB Boot\n"); |
| 85 | setenv("bootmode", "usbboot"); |
| 86 | break; |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 87 | default: |
Masahiro Yamada | d90b974 | 2016-04-21 14:43:16 +0900 | [diff] [blame] | 88 | printf("Unknown\n"); |
| 89 | break; |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 90 | } |
| 91 | |
Masahiro Yamada | 881aa5a | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 92 | if (uniphier_set_fdt_file()) |
| 93 | printf("fdt_file environment was not set correctly\n"); |
Masahiro Yamada | 8ea4f49 | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 94 | |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 95 | return 0; |
| 96 | } |