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 | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 16 | #include "boot-mode/boot-device.h" |
| 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 | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 65 | switch (spl_boot_device_raw()) { |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 66 | case BOOT_DEVICE_MMC1: |
| 67 | printf("eMMC Boot\n"); |
| 68 | setenv("bootmode", "emmcboot"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 69 | break; |
| 70 | case BOOT_DEVICE_NAND: |
| 71 | printf("NAND Boot\n"); |
| 72 | setenv("bootmode", "nandboot"); |
| 73 | nand_denali_wp_disable(); |
| 74 | break; |
| 75 | case BOOT_DEVICE_NOR: |
| 76 | printf("NOR Boot\n"); |
| 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: |
| 80 | printf("USB Boot\n"); |
| 81 | setenv("bootmode", "usbboot"); |
| 82 | break; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 83 | default: |
Masahiro Yamada | 5572b0a | 2016-04-21 14:43:16 +0900 | [diff] [blame] | 84 | printf("Unknown\n"); |
| 85 | break; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 86 | } |
| 87 | |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 88 | if (uniphier_set_fdt_file()) |
| 89 | printf("fdt_file environment was not set correctly\n"); |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 90 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 91 | return 0; |
| 92 | } |