Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 2 | * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | bb2ff9d | 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 | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 9 | #include <libfdt.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 10 | #include <nand.h> |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 11 | #include <linux/io.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 12 | #include <../drivers/mtd/nand/denali.h> |
| 13 | |
Masahiro Yamada | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 14 | #include "boot-mode/boot-device.h" |
| 15 | |
Masahiro Yamada | bb2ff9d | 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 | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 31 | struct uniphier_fdt_file { |
| 32 | const char *compatible; |
| 33 | const char *file_name; |
| 34 | }; |
| 35 | |
| 36 | static const struct uniphier_fdt_file uniphier_fdt_files[] = { |
| 37 | { "socionext,ph1-ld4-ref", "uniphier-ph1-ld4-ref.dtb", }, |
| 38 | { "socionext,ph1-ld6b-ref", "uniphier-ph1-ld6b-ref.dtb", }, |
| 39 | { "socionext,ph1-ld10-ref", "uniphier-ph1-ld10-ref.dtb", }, |
Masahiro Yamada | 40efc4f | 2016-02-12 20:27:02 +0900 | [diff] [blame] | 40 | { "socionext,ph1-pro4-ace", "uniphier-ph1-pro4-ace.dtb", }, |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 41 | { "socionext,ph1-pro4-ref", "uniphier-ph1-pro4-ref.dtb", }, |
Masahiro Yamada | 40efc4f | 2016-02-12 20:27:02 +0900 | [diff] [blame] | 42 | { "socionext,ph1-pro4-sanji", "uniphier-ph1-pro4-sanji.dtb", }, |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 43 | { "socionext,ph1-pro5-4kbox", "uniphier-ph1-pro5-4kbox.dtb", }, |
| 44 | { "socionext,ph1-sld3-ref", "uniphier-ph1-sld3-ref.dtb", }, |
| 45 | { "socionext,ph1-sld8-ref", "uniphier-ph1-sld8-ref.dtb", }, |
| 46 | { "socionext,proxstream2-gentil", "uniphier-proxstream2-gentil.dtb", }, |
| 47 | { "socionext,proxstream2-vodka", "uniphier-proxstream2-vodka.dtb", }, |
| 48 | }; |
| 49 | |
| 50 | static void uniphier_set_fdt_file(void) |
| 51 | { |
| 52 | DECLARE_GLOBAL_DATA_PTR; |
| 53 | int i; |
| 54 | |
| 55 | /* lookup DTB file name based on the compatible string */ |
| 56 | for (i = 0; i < ARRAY_SIZE(uniphier_fdt_files); i++) { |
| 57 | if (!fdt_node_check_compatible(gd->fdt_blob, 0, |
| 58 | uniphier_fdt_files[i].compatible)) { |
| 59 | setenv("fdt_file", uniphier_fdt_files[i].file_name); |
| 60 | return; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 65 | int board_late_init(void) |
| 66 | { |
| 67 | puts("MODE: "); |
| 68 | |
Masahiro Yamada | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 69 | switch (spl_boot_device_raw()) { |
Masahiro Yamada | bb2ff9d | 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 | bb2ff9d | 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 | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 82 | break; |
Masahiro Yamada | 5fe0e33 | 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 | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 87 | default: |
| 88 | printf("Unsupported Boot Mode\n"); |
| 89 | return -1; |
| 90 | } |
| 91 | |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 92 | uniphier_set_fdt_file(); |
| 93 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 94 | return 0; |
| 95 | } |