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 | 609cd53 | 2017-10-13 19:21:55 +0900 | [diff] [blame] | 13 | #include <stdio.h> |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 14 | #include <linux/io.h> |
Masahiro Yamada | 609cd53 | 2017-10-13 19:21:55 +0900 | [diff] [blame] | 15 | #include <linux/printk.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 16 | #include <../drivers/mtd/nand/denali.h> |
| 17 | |
Masahiro Yamada | fb09203 | 2017-02-14 01:24:26 +0900 | [diff] [blame] | 18 | #include "init.h" |
Masahiro Yamada | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 19 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 20 | static void nand_denali_wp_disable(void) |
| 21 | { |
| 22 | #ifdef CONFIG_NAND_DENALI |
| 23 | /* |
| 24 | * Since the boot rom enables the write protection for NAND boot mode, |
| 25 | * it must be disabled somewhere for "nand write", "nand erase", etc. |
| 26 | * The workaround is here to not disturb the Denali NAND controller |
| 27 | * driver just for a really SoC-specific thing. |
| 28 | */ |
| 29 | void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE; |
| 30 | |
| 31 | writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT); |
| 32 | #endif |
| 33 | } |
| 34 | |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 35 | static int uniphier_set_fdt_file(void) |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 36 | { |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 38 | const char *compat; |
| 39 | char dtb_name[256]; |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 40 | int buf_len = sizeof(dtb_name); |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 41 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 42 | if (env_get("fdt_file")) |
Masahiro Yamada | afbde6f | 2016-06-07 21:03:44 +0900 | [diff] [blame] | 43 | return 0; /* do nothing if it is already set */ |
| 44 | |
Simon Glass | b0ea740 | 2016-10-02 17:59:28 -0600 | [diff] [blame] | 45 | compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL); |
| 46 | if (!compat) |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 47 | return -EINVAL; |
| 48 | |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 49 | /* rip off the vendor prefix "socionext," */ |
| 50 | compat = strchr(compat, ','); |
| 51 | if (!compat) |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 52 | return -EINVAL; |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 53 | compat++; |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 54 | |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 55 | strncpy(dtb_name, compat, buf_len); |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 56 | buf_len -= strlen(compat); |
| 57 | |
| 58 | strncat(dtb_name, ".dtb", buf_len); |
| 59 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 60 | return env_set("fdt_file", dtb_name); |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 61 | } |
| 62 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 63 | int board_late_init(void) |
| 64 | { |
| 65 | puts("MODE: "); |
| 66 | |
Masahiro Yamada | fb09203 | 2017-02-14 01:24:26 +0900 | [diff] [blame] | 67 | switch (uniphier_boot_device_raw()) { |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 68 | case BOOT_DEVICE_MMC1: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 69 | printf("eMMC Boot"); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 70 | env_set("bootmode", "emmcboot"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 71 | break; |
| 72 | case BOOT_DEVICE_NAND: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 73 | printf("NAND Boot"); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 74 | env_set("bootmode", "nandboot"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 75 | nand_denali_wp_disable(); |
| 76 | break; |
| 77 | case BOOT_DEVICE_NOR: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 78 | printf("NOR Boot"); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 79 | env_set("bootmode", "norboot"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 80 | break; |
Masahiro Yamada | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 81 | case BOOT_DEVICE_USB: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 82 | printf("USB Boot"); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 83 | env_set("bootmode", "usbboot"); |
Masahiro Yamada | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 84 | break; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 85 | default: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 86 | printf("Unknown"); |
Masahiro Yamada | 5572b0a | 2016-04-21 14:43:16 +0900 | [diff] [blame] | 87 | break; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 88 | } |
| 89 | |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 90 | if (uniphier_have_internal_stm()) |
| 91 | printf(" (STM: %s)", |
| 92 | uniphier_boot_from_backend() ? "OFF" : "ON"); |
| 93 | |
| 94 | printf("\n"); |
| 95 | |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 96 | if (uniphier_set_fdt_file()) |
Masahiro Yamada | 609cd53 | 2017-10-13 19:21:55 +0900 | [diff] [blame] | 97 | pr_warn("fdt_file environment was not set correctly\n"); |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 98 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 99 | return 0; |
| 100 | } |