Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 2 | /* |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 3 | * Copyright (C) 2014 Panasonic Corporation |
| 4 | * Copyright (C) 2015-2016 Socionext Inc. |
| 5 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 9 | #include <env.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame^] | 10 | #include <init.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 11 | #include <spl.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 12 | #include <linux/libfdt.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 13 | #include <nand.h> |
Masahiro Yamada | 609cd53 | 2017-10-13 19:21:55 +0900 | [diff] [blame] | 14 | #include <stdio.h> |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 15 | #include <linux/io.h> |
Masahiro Yamada | 609cd53 | 2017-10-13 19:21:55 +0900 | [diff] [blame] | 16 | #include <linux/printk.h> |
Miquel Raynal | 1f1ae15 | 2018-08-16 17:30:07 +0200 | [diff] [blame] | 17 | #include <../drivers/mtd/nand/raw/denali.h> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 18 | |
Masahiro Yamada | fb09203 | 2017-02-14 01:24:26 +0900 | [diff] [blame] | 19 | #include "init.h" |
Masahiro Yamada | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 20 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 21 | static void nand_denali_wp_disable(void) |
| 22 | { |
| 23 | #ifdef CONFIG_NAND_DENALI |
| 24 | /* |
| 25 | * Since the boot rom enables the write protection for NAND boot mode, |
| 26 | * it must be disabled somewhere for "nand write", "nand erase", etc. |
| 27 | * The workaround is here to not disturb the Denali NAND controller |
| 28 | * driver just for a really SoC-specific thing. |
| 29 | */ |
| 30 | void __iomem *denali_reg = (void __iomem *)CONFIG_SYS_NAND_REGS_BASE; |
| 31 | |
| 32 | writel(WRITE_PROTECT__FLAG, denali_reg + WRITE_PROTECT); |
| 33 | #endif |
| 34 | } |
| 35 | |
Masahiro Yamada | bdd7955 | 2019-07-10 20:07:47 +0900 | [diff] [blame] | 36 | static void uniphier_set_env_fdt_file(void) |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 37 | { |
| 38 | DECLARE_GLOBAL_DATA_PTR; |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 39 | const char *compat; |
| 40 | char dtb_name[256]; |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 41 | int buf_len = sizeof(dtb_name); |
Masahiro Yamada | bdd7955 | 2019-07-10 20:07:47 +0900 | [diff] [blame] | 42 | int ret; |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 43 | |
Masahiro Yamada | 018f2fb | 2018-05-17 19:55:20 +0900 | [diff] [blame] | 44 | if (env_get("fdtfile")) |
Masahiro Yamada | bdd7955 | 2019-07-10 20:07:47 +0900 | [diff] [blame] | 45 | return; /* do nothing if it is already set */ |
Masahiro Yamada | afbde6f | 2016-06-07 21:03:44 +0900 | [diff] [blame] | 46 | |
Simon Glass | b0ea740 | 2016-10-02 17:59:28 -0600 | [diff] [blame] | 47 | compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL); |
| 48 | if (!compat) |
Masahiro Yamada | bdd7955 | 2019-07-10 20:07:47 +0900 | [diff] [blame] | 49 | goto fail; |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 50 | |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 51 | /* rip off the vendor prefix "socionext," */ |
| 52 | compat = strchr(compat, ','); |
| 53 | if (!compat) |
Masahiro Yamada | bdd7955 | 2019-07-10 20:07:47 +0900 | [diff] [blame] | 54 | goto fail; |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 55 | compat++; |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 56 | |
Masahiro Yamada | adb349d | 2016-10-17 22:18:02 +0900 | [diff] [blame] | 57 | strncpy(dtb_name, compat, buf_len); |
Masahiro Yamada | 8e3e0fe | 2016-04-21 14:43:17 +0900 | [diff] [blame] | 58 | buf_len -= strlen(compat); |
| 59 | |
| 60 | strncat(dtb_name, ".dtb", buf_len); |
| 61 | |
Masahiro Yamada | bdd7955 | 2019-07-10 20:07:47 +0900 | [diff] [blame] | 62 | ret = env_set("fdtfile", dtb_name); |
| 63 | if (ret) |
| 64 | goto fail; |
| 65 | |
| 66 | return; |
| 67 | fail: |
| 68 | pr_warn("\"fdt_file\" environment variable was not set correctly\n"); |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 69 | } |
| 70 | |
Masahiro Yamada | 1fedafb | 2019-07-10 20:07:48 +0900 | [diff] [blame] | 71 | static void uniphier_set_env_addr(const char *env, const char *offset_env) |
| 72 | { |
| 73 | unsigned long offset = 0; |
| 74 | const char *str; |
| 75 | char *end; |
| 76 | int ret; |
| 77 | |
| 78 | if (env_get(env)) |
| 79 | return; /* do nothing if it is already set */ |
| 80 | |
| 81 | if (offset_env) { |
| 82 | str = env_get(offset_env); |
| 83 | if (!str) |
| 84 | goto fail; |
| 85 | |
| 86 | offset = simple_strtoul(str, &end, 16); |
| 87 | if (*end) |
| 88 | goto fail; |
| 89 | } |
| 90 | |
| 91 | ret = env_set_hex(env, gd->ram_base + offset); |
| 92 | if (ret) |
| 93 | goto fail; |
| 94 | |
| 95 | return; |
| 96 | |
| 97 | fail: |
| 98 | pr_warn("\"%s\" environment variable was not set correctly\n", env); |
| 99 | } |
| 100 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 101 | int board_late_init(void) |
| 102 | { |
| 103 | puts("MODE: "); |
| 104 | |
Masahiro Yamada | fb09203 | 2017-02-14 01:24:26 +0900 | [diff] [blame] | 105 | switch (uniphier_boot_device_raw()) { |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 106 | case BOOT_DEVICE_MMC1: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 107 | printf("eMMC Boot"); |
Masahiro Yamada | 93270eb | 2018-12-19 20:03:13 +0900 | [diff] [blame] | 108 | env_set("bootdev", "emmc"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 109 | break; |
Masahiro Yamada | c85f81b | 2019-07-10 20:07:39 +0900 | [diff] [blame] | 110 | case BOOT_DEVICE_MMC2: |
| 111 | printf("SD Boot"); |
| 112 | env_set("bootdev", "sd"); |
| 113 | break; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 114 | case BOOT_DEVICE_NAND: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 115 | printf("NAND Boot"); |
Masahiro Yamada | 93270eb | 2018-12-19 20:03:13 +0900 | [diff] [blame] | 116 | env_set("bootdev", "nand"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 117 | nand_denali_wp_disable(); |
| 118 | break; |
| 119 | case BOOT_DEVICE_NOR: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 120 | printf("NOR Boot"); |
Masahiro Yamada | 93270eb | 2018-12-19 20:03:13 +0900 | [diff] [blame] | 121 | env_set("bootdev", "nor"); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 122 | break; |
Masahiro Yamada | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 123 | case BOOT_DEVICE_USB: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 124 | printf("USB Boot"); |
Masahiro Yamada | 93270eb | 2018-12-19 20:03:13 +0900 | [diff] [blame] | 125 | env_set("bootdev", "usb"); |
Masahiro Yamada | 5fe0e33 | 2016-02-02 21:11:31 +0900 | [diff] [blame] | 126 | break; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 127 | default: |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 128 | printf("Unknown"); |
Masahiro Yamada | 5572b0a | 2016-04-21 14:43:16 +0900 | [diff] [blame] | 129 | break; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 130 | } |
| 131 | |
Masahiro Yamada | af19810 | 2017-04-20 16:54:43 +0900 | [diff] [blame] | 132 | if (uniphier_have_internal_stm()) |
| 133 | printf(" (STM: %s)", |
| 134 | uniphier_boot_from_backend() ? "OFF" : "ON"); |
| 135 | |
| 136 | printf("\n"); |
| 137 | |
Masahiro Yamada | bdd7955 | 2019-07-10 20:07:47 +0900 | [diff] [blame] | 138 | uniphier_set_env_fdt_file(); |
Masahiro Yamada | bf6e3fc | 2015-12-17 18:00:37 +0900 | [diff] [blame] | 139 | |
Masahiro Yamada | a74f0c3 | 2019-07-10 20:07:49 +0900 | [diff] [blame] | 140 | uniphier_set_env_addr("dram_base", NULL); |
| 141 | |
Masahiro Yamada | 1fedafb | 2019-07-10 20:07:48 +0900 | [diff] [blame] | 142 | uniphier_set_env_addr("loadaddr", "loadaddr_offset"); |
| 143 | |
Masahiro Yamada | a4677b1 | 2019-07-10 20:07:50 +0900 | [diff] [blame] | 144 | uniphier_set_env_addr("kernel_addr_r", "kernel_addr_r_offset"); |
| 145 | uniphier_set_env_addr("ramdisk_addr_r", "ramdisk_addr_r_offset"); |
| 146 | uniphier_set_env_addr("fdt_addr_r", "fdt_addr_r_offset"); |
| 147 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 148 | return 0; |
| 149 | } |