Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 - 2015 Xilinx, Inc. |
| 4 | * Michal Simek <michal.simek@xilinx.com> |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 8 | #include <command.h> |
Simon Glass | 370382c | 2019-11-14 12:57:35 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Michal Simek | 09a7d7d | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 10 | #include <debug_uart.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 11 | #include <env.h> |
Michal Simek | 8d4a8d4 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 12 | #include <env_internal.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 13 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 15 | #include <net.h> |
Michal Simek | d54b1af | 2015-09-30 17:26:55 +0200 | [diff] [blame] | 16 | #include <sata.h> |
Michal Simek | b216cc1 | 2015-07-23 13:27:40 +0200 | [diff] [blame] | 17 | #include <ahci.h> |
| 18 | #include <scsi.h> |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 19 | #include <malloc.h> |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 20 | #include <wdt.h> |
Michal Simek | c23d3f8 | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 21 | #include <asm/arch/clk.h> |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 22 | #include <asm/arch/hardware.h> |
| 23 | #include <asm/arch/sys_proto.h> |
Michal Simek | f2f0864 | 2018-01-10 09:36:09 +0100 | [diff] [blame] | 24 | #include <asm/arch/psu_init_gpl.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 25 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 26 | #include <asm/global_data.h> |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 27 | #include <asm/io.h> |
Simon Glass | 6b9f010 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 28 | #include <asm/ptrace.h> |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 29 | #include <dm/device.h> |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 30 | #include <dm/uclass.h> |
Siva Durga Prasad Paladugu | ba1f68e | 2015-08-04 13:03:26 +0530 | [diff] [blame] | 31 | #include <usb.h> |
| 32 | #include <dwc3-uboot.h> |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 33 | #include <zynqmppl.h> |
Ibai Erkiaga | c8a3efa | 2019-09-27 11:37:01 +0100 | [diff] [blame] | 34 | #include <zynqmp_firmware.h> |
Michal Simek | 76d0a77 | 2016-09-01 11:16:40 +0200 | [diff] [blame] | 35 | #include <g_dnl.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 36 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 37 | #include <linux/delay.h> |
| 38 | #include <linux/sizes.h> |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 39 | #include "../common/board.h" |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 40 | |
Luca Ceresoli | 23e6500 | 2019-05-21 18:06:43 +0200 | [diff] [blame] | 41 | #include "pm_cfg_obj.h" |
| 42 | |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 43 | #define ZYNQMP_VERSION_SIZE 7 |
Michal Simek | c702a74 | 2020-10-21 12:23:17 +0200 | [diff] [blame] | 44 | #define EFUSE_VCU_DIS_MASK 0x100 |
| 45 | #define EFUSE_VCU_DIS_SHIFT 8 |
| 46 | #define EFUSE_GPU_DIS_MASK 0x20 |
| 47 | #define EFUSE_GPU_DIS_SHIFT 5 |
| 48 | #define IDCODE2_PL_INIT_MASK 0x200 |
| 49 | #define IDCODE2_PL_INIT_SHIFT 9 |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 50 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 51 | DECLARE_GLOBAL_DATA_PTR; |
| 52 | |
Michal Simek | 1aab114 | 2020-09-09 14:41:56 +0200 | [diff] [blame] | 53 | #if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 54 | static xilinx_desc zynqmppl = XILINX_ZYNQMP_DESC; |
| 55 | |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 56 | enum { |
| 57 | ZYNQMP_VARIANT_EG = BIT(0U), |
| 58 | ZYNQMP_VARIANT_EV = BIT(1U), |
| 59 | ZYNQMP_VARIANT_CG = BIT(2U), |
| 60 | ZYNQMP_VARIANT_DR = BIT(3U), |
| 61 | }; |
| 62 | |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 63 | static const struct { |
Michal Simek | 6908b86 | 2017-11-06 12:55:59 +0100 | [diff] [blame] | 64 | u32 id; |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 65 | u8 device; |
| 66 | u8 variants; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 67 | } zynqmp_devices[] = { |
| 68 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 69 | .id = 0x04711093, |
| 70 | .device = 2, |
| 71 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 72 | }, |
| 73 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 74 | .id = 0x04710093, |
| 75 | .device = 3, |
| 76 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 77 | }, |
| 78 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 79 | .id = 0x04721093, |
| 80 | .device = 4, |
| 81 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG | |
| 82 | ZYNQMP_VARIANT_EV, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 83 | }, |
| 84 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 85 | .id = 0x04720093, |
| 86 | .device = 5, |
| 87 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG | |
| 88 | ZYNQMP_VARIANT_EV, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 89 | }, |
| 90 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 91 | .id = 0x04739093, |
| 92 | .device = 6, |
| 93 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 94 | }, |
| 95 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 96 | .id = 0x04730093, |
| 97 | .device = 7, |
| 98 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG | |
| 99 | ZYNQMP_VARIANT_EV, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 100 | }, |
| 101 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 102 | .id = 0x04738093, |
| 103 | .device = 9, |
Michal Simek | 3626f2c | 2020-10-02 14:42:05 +0200 | [diff] [blame] | 104 | .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 105 | }, |
| 106 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 107 | .id = 0x04740093, |
| 108 | .device = 11, |
| 109 | .variants = ZYNQMP_VARIANT_EG, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 110 | }, |
| 111 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 112 | .id = 0x04750093, |
| 113 | .device = 15, |
| 114 | .variants = ZYNQMP_VARIANT_EG, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 115 | }, |
| 116 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 117 | .id = 0x04759093, |
| 118 | .device = 17, |
| 119 | .variants = ZYNQMP_VARIANT_EG, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 120 | }, |
| 121 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 122 | .id = 0x04758093, |
| 123 | .device = 19, |
| 124 | .variants = ZYNQMP_VARIANT_EG, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 125 | }, |
| 126 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 127 | .id = 0x047E1093, |
| 128 | .device = 21, |
| 129 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 130 | }, |
| 131 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 132 | .id = 0x047E3093, |
| 133 | .device = 23, |
| 134 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 135 | }, |
| 136 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 137 | .id = 0x047E5093, |
| 138 | .device = 25, |
| 139 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 140 | }, |
| 141 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 142 | .id = 0x047E4093, |
| 143 | .device = 27, |
| 144 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 145 | }, |
| 146 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 147 | .id = 0x047E0093, |
| 148 | .device = 28, |
| 149 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 150 | }, |
| 151 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 152 | .id = 0x047E2093, |
| 153 | .device = 29, |
| 154 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 155 | }, |
Michal Simek | b510e53 | 2017-06-02 08:08:59 +0200 | [diff] [blame] | 156 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 157 | .id = 0x047E6093, |
| 158 | .device = 39, |
| 159 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | b510e53 | 2017-06-02 08:08:59 +0200 | [diff] [blame] | 160 | }, |
| 161 | { |
Michal Simek | 3fd2ed3 | 2020-09-11 09:22:15 +0200 | [diff] [blame] | 162 | .id = 0x047FD093, |
| 163 | .device = 43, |
| 164 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | b510e53 | 2017-06-02 08:08:59 +0200 | [diff] [blame] | 165 | }, |
| 166 | { |
Michal Simek | 3fd2ed3 | 2020-09-11 09:22:15 +0200 | [diff] [blame] | 167 | .id = 0x047F8093, |
| 168 | .device = 46, |
| 169 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | b510e53 | 2017-06-02 08:08:59 +0200 | [diff] [blame] | 170 | }, |
| 171 | { |
Michal Simek | 3fd2ed3 | 2020-09-11 09:22:15 +0200 | [diff] [blame] | 172 | .id = 0x047FF093, |
| 173 | .device = 47, |
| 174 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | b510e53 | 2017-06-02 08:08:59 +0200 | [diff] [blame] | 175 | }, |
| 176 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 177 | .id = 0x047FB093, |
| 178 | .device = 48, |
| 179 | .variants = ZYNQMP_VARIANT_DR, |
Michal Simek | b510e53 | 2017-06-02 08:08:59 +0200 | [diff] [blame] | 180 | }, |
| 181 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 182 | .id = 0x047FE093, |
| 183 | .device = 49, |
| 184 | .variants = ZYNQMP_VARIANT_DR, |
Siva Durga Prasad Paladugu | 85f61a8 | 2019-07-23 11:56:17 +0530 | [diff] [blame] | 185 | }, |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 186 | }; |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 187 | |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 188 | static char *zynqmp_get_silicon_idcode_name(void) |
| 189 | { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 190 | u32 i; |
| 191 | u32 idcode, idcode2; |
Michal Simek | 051b8bc | 2020-08-05 12:41:35 +0200 | [diff] [blame] | 192 | char name[ZYNQMP_VERSION_SIZE]; |
Ibai Erkiaga | c318ecb | 2020-08-04 23:17:30 +0100 | [diff] [blame] | 193 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
Michal Simek | b5c3b0d | 2020-10-07 15:13:17 +0200 | [diff] [blame] | 194 | int ret; |
Ibai Erkiaga | c318ecb | 2020-08-04 23:17:30 +0100 | [diff] [blame] | 195 | |
Michal Simek | 23c0def | 2020-10-21 12:16:02 +0200 | [diff] [blame] | 196 | ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload); |
| 197 | if (ret) { |
| 198 | debug("%s: Getting chipid failed\n", __func__); |
| 199 | return "unknown"; |
| 200 | } |
Ibai Erkiaga | c318ecb | 2020-08-04 23:17:30 +0100 | [diff] [blame] | 201 | |
| 202 | /* |
| 203 | * Firmware returns: |
| 204 | * payload[0][31:0] = status of the operation |
| 205 | * payload[1]] = IDCODE |
| 206 | * payload[2][19:0] = Version |
| 207 | * payload[2][28:20] = EXTENDED_IDCODE |
| 208 | * payload[2][29] = PL_INIT |
| 209 | */ |
| 210 | |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 211 | idcode = ret_payload[1]; |
| 212 | idcode2 = ret_payload[2] >> ZYNQMP_CSU_VERSION_EMPTY_SHIFT; |
Michal Simek | c76c96f | 2020-10-21 12:16:50 +0200 | [diff] [blame] | 213 | debug("%s, IDCODE: 0x%0x, IDCODE2: 0x%0x\r\n", __func__, idcode, |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 214 | idcode2); |
Michal Simek | 50d8cef | 2017-08-22 14:58:53 +0200 | [diff] [blame] | 215 | |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 216 | for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) { |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 217 | if (zynqmp_devices[i].id == (idcode & 0x0FFFFFFF)) |
| 218 | break; |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 219 | } |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 220 | |
| 221 | if (i >= ARRAY_SIZE(zynqmp_devices)) |
| 222 | return "unknown"; |
| 223 | |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 224 | /* Add device prefix to the name */ |
Michal Simek | b5c3b0d | 2020-10-07 15:13:17 +0200 | [diff] [blame] | 225 | ret = snprintf(name, ZYNQMP_VERSION_SIZE, "zu%d", |
| 226 | zynqmp_devices[i].device); |
Michal Simek | d228167 | 2020-10-21 12:17:44 +0200 | [diff] [blame] | 227 | if (ret < 0) |
Michal Simek | b5c3b0d | 2020-10-07 15:13:17 +0200 | [diff] [blame] | 228 | return "unknown"; |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 229 | |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 230 | if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EV) { |
| 231 | /* Devices with EV variant might be EG/CG/EV family */ |
| 232 | if (idcode2 & IDCODE2_PL_INIT_MASK) { |
| 233 | u32 family = ((idcode2 & EFUSE_VCU_DIS_MASK) >> |
| 234 | EFUSE_VCU_DIS_SHIFT) << 1 | |
| 235 | ((idcode2 & EFUSE_GPU_DIS_MASK) >> |
| 236 | EFUSE_GPU_DIS_SHIFT); |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 237 | |
Ibai Erkiaga | 4f73618 | 2020-08-04 23:17:31 +0100 | [diff] [blame] | 238 | /* |
| 239 | * Get family name based on extended idcode values as |
| 240 | * determined on UG1087, EXTENDED_IDCODE register |
| 241 | * description |
| 242 | */ |
| 243 | switch (family) { |
| 244 | case 0x00: |
| 245 | strncat(name, "ev", 2); |
| 246 | break; |
| 247 | case 0x10: |
| 248 | strncat(name, "eg", 2); |
| 249 | break; |
| 250 | case 0x11: |
| 251 | strncat(name, "cg", 2); |
| 252 | break; |
| 253 | default: |
| 254 | /* Do not append family name*/ |
| 255 | break; |
| 256 | } |
| 257 | } else { |
| 258 | /* |
| 259 | * When PL powered down the VCU Disable efuse cannot be |
| 260 | * read. So, ignore the bit and just findout if it is CG |
| 261 | * or EG/EV variant. |
| 262 | */ |
| 263 | strncat(name, (idcode2 & EFUSE_GPU_DIS_MASK) ? "cg" : |
| 264 | "e", 2); |
| 265 | } |
| 266 | } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_CG) { |
| 267 | /* Devices with CG variant might be EG or CG family */ |
| 268 | strncat(name, (idcode2 & EFUSE_GPU_DIS_MASK) ? "cg" : "eg", 2); |
| 269 | } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_EG) { |
| 270 | strncat(name, "eg", 2); |
| 271 | } else if (zynqmp_devices[i].variants & ZYNQMP_VARIANT_DR) { |
| 272 | strncat(name, "dr", 2); |
| 273 | } else { |
| 274 | debug("Variant not identified\n"); |
Siva Durga Prasad Paladugu | ba2622d | 2018-03-02 16:20:10 +0530 | [diff] [blame] | 275 | } |
| 276 | |
Michal Simek | 051b8bc | 2020-08-05 12:41:35 +0200 | [diff] [blame] | 277 | return strdup(name); |
Michal Simek | 8111aff | 2016-02-01 15:05:58 +0100 | [diff] [blame] | 278 | } |
| 279 | #endif |
| 280 | |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 281 | int board_early_init_f(void) |
| 282 | { |
Michal Simek | 1a1ab5a | 2018-01-15 12:52:59 +0100 | [diff] [blame] | 283 | #if defined(CONFIG_ZYNQMP_PSU_INIT_ENABLED) |
Michal Simek | 09a7d7d | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 284 | int ret; |
| 285 | |
Michal Simek | c8785f2 | 2018-01-10 11:48:48 +0100 | [diff] [blame] | 286 | ret = psu_init(); |
Michal Simek | 09a7d7d | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 287 | if (ret) |
| 288 | return ret; |
Michal Simek | 1f55e57 | 2020-03-20 08:59:02 +0100 | [diff] [blame] | 289 | |
| 290 | /* Delay is required for clocks to be propagated */ |
| 291 | udelay(1000000); |
Michal Simek | e0f3610 | 2017-07-12 13:08:41 +0200 | [diff] [blame] | 292 | #endif |
| 293 | |
Michal Simek | 09a7d7d | 2020-01-07 09:02:52 +0100 | [diff] [blame] | 294 | #ifdef CONFIG_DEBUG_UART |
| 295 | /* Uart debug for sure */ |
| 296 | debug_uart_init(); |
| 297 | puts("Debug uart enabled\n"); /* or printch() */ |
| 298 | #endif |
| 299 | |
| 300 | return 0; |
Michal Simek | 8b35330 | 2017-02-07 14:32:26 +0100 | [diff] [blame] | 301 | } |
| 302 | |
Michal Simek | 4690046 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 303 | static int multi_boot(void) |
| 304 | { |
| 305 | u32 multiboot; |
| 306 | |
| 307 | multiboot = readl(&csu_base->multi_boot); |
| 308 | |
Michal Simek | c55f2d5 | 2020-05-27 12:50:33 +0200 | [diff] [blame] | 309 | printf("Multiboot:\t%d\n", multiboot); |
Michal Simek | 4690046 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
Mike Looijmans | 9863e2f | 2019-10-18 07:34:13 +0200 | [diff] [blame] | 314 | #define PS_SYSMON_ANALOG_BUS_VAL 0x3210 |
| 315 | #define PS_SYSMON_ANALOG_BUS_REG 0xFFA50914 |
| 316 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 317 | int board_init(void) |
| 318 | { |
Michal Simek | 826d7eca | 2020-03-04 08:48:16 +0100 | [diff] [blame] | 319 | #if defined(CONFIG_ZYNQMP_FIRMWARE) |
Ibai Erkiaga | 2d9b95b | 2019-09-27 11:37:04 +0100 | [diff] [blame] | 320 | struct udevice *dev; |
| 321 | |
| 322 | uclass_get_device_by_name(UCLASS_FIRMWARE, "zynqmp-power", &dev); |
| 323 | if (!dev) |
| 324 | panic("PMU Firmware device not found - Enable it"); |
Michal Simek | 826d7eca | 2020-03-04 08:48:16 +0100 | [diff] [blame] | 325 | #endif |
Ibai Erkiaga | 2d9b95b | 2019-09-27 11:37:04 +0100 | [diff] [blame] | 326 | |
Luca Ceresoli | 23e6500 | 2019-05-21 18:06:43 +0200 | [diff] [blame] | 327 | #if defined(CONFIG_SPL_BUILD) |
| 328 | /* Check *at build time* if the filename is an non-empty string */ |
| 329 | if (sizeof(CONFIG_ZYNQMP_SPL_PM_CFG_OBJ_FILE) > 1) |
| 330 | zynqmp_pmufw_load_config_object(zynqmp_pm_cfg_obj, |
| 331 | zynqmp_pm_cfg_obj_size); |
Michal Simek | ae9dc11 | 2021-02-02 16:34:48 +0100 | [diff] [blame] | 332 | printf("Silicon version:\t%d\n", zynqmp_get_silicon_version()); |
Michal Simek | 394ee24 | 2020-08-03 13:01:45 +0200 | [diff] [blame] | 333 | #else |
| 334 | if (CONFIG_IS_ENABLED(DM_I2C) && CONFIG_IS_ENABLED(I2C_EEPROM)) |
| 335 | xilinx_read_eeprom(); |
Luca Ceresoli | 23e6500 | 2019-05-21 18:06:43 +0200 | [diff] [blame] | 336 | #endif |
| 337 | |
Michal Simek | fb7242d | 2015-06-22 14:31:06 +0200 | [diff] [blame] | 338 | printf("EL Level:\tEL%d\n", current_el()); |
| 339 | |
Mike Looijmans | 9863e2f | 2019-10-18 07:34:13 +0200 | [diff] [blame] | 340 | /* Bug in ROM sets wrong value in this register */ |
| 341 | writel(PS_SYSMON_ANALOG_BUS_VAL, PS_SYSMON_ANALOG_BUS_REG); |
| 342 | |
Michal Simek | 1aab114 | 2020-09-09 14:41:56 +0200 | [diff] [blame] | 343 | #if CONFIG_IS_ENABLED(FPGA) && defined(CONFIG_FPGA_ZYNQMPPL) |
Ibai Erkiaga | e91ca7c | 2020-08-04 23:17:29 +0100 | [diff] [blame] | 344 | zynqmppl.name = zynqmp_get_silicon_idcode_name(); |
| 345 | printf("Chip ID:\t%s\n", zynqmppl.name); |
| 346 | fpga_init(); |
| 347 | fpga_add(fpga_xilinx, &zynqmppl); |
Michal Simek | bf0f9ca | 2018-04-19 15:43:38 +0200 | [diff] [blame] | 348 | #endif |
| 349 | |
Michal Simek | 4690046 | 2020-02-11 12:43:14 +0100 | [diff] [blame] | 350 | if (current_el() == 3) |
| 351 | multi_boot(); |
| 352 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | int board_early_init_r(void) |
| 357 | { |
| 358 | u32 val; |
| 359 | |
Siva Durga Prasad Paladugu | 64d9000 | 2017-12-07 15:05:30 +0530 | [diff] [blame] | 360 | if (current_el() != 3) |
| 361 | return 0; |
| 362 | |
Michal Simek | 245d528 | 2017-07-12 10:32:18 +0200 | [diff] [blame] | 363 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 364 | val &= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 365 | |
Siva Durga Prasad Paladugu | 64d9000 | 2017-12-07 15:05:30 +0530 | [diff] [blame] | 366 | if (!val) { |
Michal Simek | c23d3f8 | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 367 | val = readl(&crlapb_base->timestamp_ref_ctrl); |
| 368 | val |= ZYNQMP_CRL_APB_TIMESTAMP_REF_CTRL_CLKACT; |
| 369 | writel(val, &crlapb_base->timestamp_ref_ctrl); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 370 | |
Michal Simek | c23d3f8 | 2015-11-05 08:34:35 +0100 | [diff] [blame] | 371 | /* Program freq register in System counter */ |
| 372 | writel(zynqmp_get_system_timer_freq(), |
| 373 | &iou_scntr_secure->base_frequency_id_register); |
| 374 | /* And enable system counter */ |
| 375 | writel(ZYNQMP_IOU_SCNTR_COUNTER_CONTROL_REGISTER_EN, |
| 376 | &iou_scntr_secure->counter_control_register); |
| 377 | } |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 378 | return 0; |
| 379 | } |
| 380 | |
Nitin Jain | b2eb59b | 2018-02-16 12:56:17 +0530 | [diff] [blame] | 381 | unsigned long do_go_exec(ulong (*entry)(int, char * const []), int argc, |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 382 | char *const argv[]) |
Nitin Jain | b2eb59b | 2018-02-16 12:56:17 +0530 | [diff] [blame] | 383 | { |
| 384 | int ret = 0; |
| 385 | |
| 386 | if (current_el() > 1) { |
| 387 | smp_kick_all_cpus(); |
| 388 | dcache_disable(); |
| 389 | armv8_switch_to_el1(0x0, 0, 0, 0, (unsigned long)entry, |
| 390 | ES_TO_AARCH64); |
| 391 | } else { |
| 392 | printf("FAIL: current EL is not above EL1\n"); |
| 393 | ret = EINVAL; |
| 394 | } |
| 395 | return ret; |
| 396 | } |
| 397 | |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 398 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 399 | int dram_init_banksize(void) |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 400 | { |
Nitin Jain | 9bcc76f | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 401 | int ret; |
| 402 | |
| 403 | ret = fdtdec_setup_memory_banksize(); |
| 404 | if (ret) |
| 405 | return ret; |
| 406 | |
| 407 | mem_map_fill(); |
| 408 | |
| 409 | return 0; |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 410 | } |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 411 | |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 412 | int dram_init(void) |
| 413 | { |
Siva Durga Prasad Paladugu | b3d55ea | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 414 | if (fdtdec_setup_mem_size_base() != 0) |
Nathan Rossi | ac04bfa | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 415 | return -EINVAL; |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 416 | |
| 417 | return 0; |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 418 | } |
| 419 | #else |
Nitin Jain | 9bcc76f | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 420 | int dram_init_banksize(void) |
| 421 | { |
Nitin Jain | 9bcc76f | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 422 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 423 | gd->bd->bi_dram[0].size = get_effective_memsize(); |
Nitin Jain | 9bcc76f | 2018-04-20 12:30:40 +0530 | [diff] [blame] | 424 | |
| 425 | mem_map_fill(); |
| 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 430 | int dram_init(void) |
| 431 | { |
Michal Simek | 1b84621 | 2018-04-11 16:12:28 +0200 | [diff] [blame] | 432 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 433 | CONFIG_SYS_SDRAM_SIZE); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 434 | |
| 435 | return 0; |
| 436 | } |
Michal Simek | 8faa66a | 2016-02-08 09:34:53 +0100 | [diff] [blame] | 437 | #endif |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 438 | |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 439 | void reset_cpu(void) |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 440 | { |
| 441 | } |
| 442 | |
Michal Simek | 8ec3004 | 2020-08-20 10:54:45 +0200 | [diff] [blame] | 443 | static u8 __maybe_unused zynqmp_get_bootmode(void) |
| 444 | { |
| 445 | u8 bootmode; |
| 446 | u32 reg = 0; |
| 447 | int ret; |
| 448 | |
| 449 | ret = zynqmp_mmio_read((ulong)&crlapb_base->boot_mode, ®); |
| 450 | if (ret) |
| 451 | return -EINVAL; |
| 452 | |
| 453 | if (reg >> BOOT_MODE_ALT_SHIFT) |
| 454 | reg >>= BOOT_MODE_ALT_SHIFT; |
| 455 | |
| 456 | bootmode = reg & BOOT_MODES_MASK; |
| 457 | |
| 458 | return bootmode; |
| 459 | } |
| 460 | |
Michal Simek | 342edfe | 2018-12-20 09:33:38 +0100 | [diff] [blame] | 461 | #if defined(CONFIG_BOARD_LATE_INIT) |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 462 | static const struct { |
| 463 | u32 bit; |
| 464 | const char *name; |
| 465 | } reset_reasons[] = { |
| 466 | { RESET_REASON_DEBUG_SYS, "DEBUG" }, |
| 467 | { RESET_REASON_SOFT, "SOFT" }, |
| 468 | { RESET_REASON_SRST, "SRST" }, |
| 469 | { RESET_REASON_PSONLY, "PS-ONLY" }, |
| 470 | { RESET_REASON_PMU, "PMU" }, |
| 471 | { RESET_REASON_INTERNAL, "INTERNAL" }, |
| 472 | { RESET_REASON_EXTERNAL, "EXTERNAL" }, |
| 473 | {} |
| 474 | }; |
| 475 | |
T Karthik Reddy | 09b6def | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 476 | static int reset_reason(void) |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 477 | { |
T Karthik Reddy | 09b6def | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 478 | u32 reg; |
| 479 | int i, ret; |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 480 | const char *reason = NULL; |
| 481 | |
T Karthik Reddy | 09b6def | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 482 | ret = zynqmp_mmio_read((ulong)&crlapb_base->reset_reason, ®); |
| 483 | if (ret) |
| 484 | return -EINVAL; |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 485 | |
| 486 | puts("Reset reason:\t"); |
| 487 | |
| 488 | for (i = 0; i < ARRAY_SIZE(reset_reasons); i++) { |
T Karthik Reddy | 09b6def | 2019-03-13 20:24:18 +0530 | [diff] [blame] | 489 | if (reg & reset_reasons[i].bit) { |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 490 | reason = reset_reasons[i].name; |
| 491 | printf("%s ", reset_reasons[i].name); |
| 492 | break; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | puts("\n"); |
| 497 | |
| 498 | env_set("reset_reason", reason); |
| 499 | |
Michal Simek | 0954c8c | 2021-02-09 08:50:22 +0100 | [diff] [blame] | 500 | return 0; |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 501 | } |
| 502 | |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 503 | static int set_fdtfile(void) |
| 504 | { |
| 505 | char *compatible, *fdtfile; |
| 506 | const char *suffix = ".dtb"; |
| 507 | const char *vendor = "xilinx/"; |
Igor Lantsman | e167bac | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 508 | int fdt_compat_len; |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 509 | |
| 510 | if (env_get("fdtfile")) |
| 511 | return 0; |
| 512 | |
Igor Lantsman | e167bac | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 513 | compatible = (char *)fdt_getprop(gd->fdt_blob, 0, "compatible", |
| 514 | &fdt_compat_len); |
| 515 | if (compatible && fdt_compat_len) { |
| 516 | char *name; |
| 517 | |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 518 | debug("Compatible: %s\n", compatible); |
| 519 | |
Igor Lantsman | e167bac | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 520 | name = strchr(compatible, ','); |
| 521 | if (!name) |
| 522 | return -EINVAL; |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 523 | |
Igor Lantsman | e167bac | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 524 | name++; |
| 525 | |
| 526 | fdtfile = calloc(1, strlen(vendor) + strlen(name) + |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 527 | strlen(suffix) + 1); |
| 528 | if (!fdtfile) |
| 529 | return -ENOMEM; |
| 530 | |
Igor Lantsman | e167bac | 2020-06-24 14:33:46 +0200 | [diff] [blame] | 531 | sprintf(fdtfile, "%s%s%s", vendor, name, suffix); |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 532 | |
| 533 | env_set("fdtfile", fdtfile); |
| 534 | free(fdtfile); |
| 535 | } |
| 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | |
Michal Simek | 9c91e61 | 2020-04-08 11:04:41 +0200 | [diff] [blame] | 540 | int board_late_init(void) |
| 541 | { |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 542 | u8 bootmode; |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 543 | struct udevice *dev; |
| 544 | int bootseq = -1; |
| 545 | int bootseq_len = 0; |
Michal Simek | 7410b14 | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 546 | int env_targets_len = 0; |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 547 | const char *mode; |
| 548 | char *new_targets; |
Siva Durga Prasad Paladugu | 245c556 | 2017-12-20 16:35:06 +0530 | [diff] [blame] | 549 | char *env_targets; |
Siva Durga Prasad Paladugu | e6fd3bb | 2017-02-21 17:58:28 +0530 | [diff] [blame] | 550 | int ret; |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 551 | |
Michal Simek | 482f549 | 2018-10-05 08:55:16 +0200 | [diff] [blame] | 552 | #if defined(CONFIG_USB_ETHER) && !defined(CONFIG_USB_GADGET_DOWNLOAD) |
| 553 | usb_ether_init(); |
| 554 | #endif |
| 555 | |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 556 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 557 | debug("Saved variables - Skipping\n"); |
| 558 | return 0; |
| 559 | } |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 560 | |
Michal Simek | bab07b6 | 2020-07-28 12:45:47 +0200 | [diff] [blame] | 561 | if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG)) |
| 562 | return 0; |
| 563 | |
Michal Simek | 1ca66d7 | 2019-02-14 13:14:30 +0100 | [diff] [blame] | 564 | ret = set_fdtfile(); |
| 565 | if (ret) |
| 566 | return ret; |
| 567 | |
Michal Simek | 9c91e61 | 2020-04-08 11:04:41 +0200 | [diff] [blame] | 568 | bootmode = zynqmp_get_bootmode(); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 569 | |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 570 | puts("Bootmode: "); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 571 | switch (bootmode) { |
Michal Simek | 12398ea | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 572 | case USB_MODE: |
| 573 | puts("USB_MODE\n"); |
| 574 | mode = "usb"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 575 | env_set("modeboot", "usb_dfu_spl"); |
Michal Simek | 12398ea | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 576 | break; |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 577 | case JTAG_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 578 | puts("JTAG_MODE\n"); |
Siva Durga Prasad Paladugu | 9c44170 | 2019-06-25 17:41:09 +0530 | [diff] [blame] | 579 | mode = "jtag pxe dhcp"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 580 | env_set("modeboot", "jtagboot"); |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 581 | break; |
| 582 | case QSPI_MODE_24BIT: |
| 583 | case QSPI_MODE_32BIT: |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 584 | mode = "qspi0"; |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 585 | puts("QSPI_MODE\n"); |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 586 | env_set("modeboot", "qspiboot"); |
Siva Durga Prasad Paladugu | 30f0fc7 | 2015-03-13 11:10:26 +0530 | [diff] [blame] | 587 | break; |
Michal Simek | 02d66cd | 2015-04-15 15:02:28 +0200 | [diff] [blame] | 588 | case EMMC_MODE: |
Michal Simek | df7ff0a | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 589 | puts("EMMC_MODE\n"); |
T Karthik Reddy | 19735c3 | 2019-12-17 06:41:42 -0700 | [diff] [blame] | 590 | if (uclass_get_device_by_name(UCLASS_MMC, |
| 591 | "mmc@ff160000", &dev) && |
| 592 | uclass_get_device_by_name(UCLASS_MMC, |
| 593 | "sdhci@ff160000", &dev)) { |
| 594 | puts("Boot from EMMC but without SD0 enabled!\n"); |
| 595 | return -1; |
| 596 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 597 | debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev)); |
T Karthik Reddy | 19735c3 | 2019-12-17 06:41:42 -0700 | [diff] [blame] | 598 | |
| 599 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 600 | bootseq = dev_seq(dev); |
Michal Simek | df7ff0a | 2015-10-05 15:59:38 +0200 | [diff] [blame] | 601 | break; |
| 602 | case SD_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 603 | puts("SD_MODE\n"); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 604 | if (uclass_get_device_by_name(UCLASS_MMC, |
Siva Durga Prasad Paladugu | e91778d | 2019-01-03 15:44:24 +0530 | [diff] [blame] | 605 | "mmc@ff160000", &dev) && |
| 606 | uclass_get_device_by_name(UCLASS_MMC, |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 607 | "sdhci@ff160000", &dev)) { |
| 608 | puts("Boot from SD0 but without SD0 enabled!\n"); |
| 609 | return -1; |
| 610 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 611 | debug("mmc0 device found at %p, seq %d\n", dev, dev_seq(dev)); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 612 | |
| 613 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 614 | bootseq = dev_seq(dev); |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 615 | env_set("modeboot", "sdboot"); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 616 | break; |
Siva Durga Prasad Paladugu | 29a77d2 | 2016-09-21 11:45:05 +0530 | [diff] [blame] | 617 | case SD1_LSHFT_MODE: |
| 618 | puts("LVL_SHFT_"); |
| 619 | /* fall through */ |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 620 | case SD_MODE1: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 621 | puts("SD_MODE1\n"); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 622 | if (uclass_get_device_by_name(UCLASS_MMC, |
Siva Durga Prasad Paladugu | e91778d | 2019-01-03 15:44:24 +0530 | [diff] [blame] | 623 | "mmc@ff170000", &dev) && |
| 624 | uclass_get_device_by_name(UCLASS_MMC, |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 625 | "sdhci@ff170000", &dev)) { |
| 626 | puts("Boot from SD1 but without SD1 enabled!\n"); |
| 627 | return -1; |
| 628 | } |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 629 | debug("mmc1 device found at %p, seq %d\n", dev, dev_seq(dev)); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 630 | |
| 631 | mode = "mmc"; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 632 | bootseq = dev_seq(dev); |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 633 | env_set("modeboot", "sdboot"); |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 634 | break; |
| 635 | case NAND_MODE: |
Michal Simek | c5d9523 | 2015-09-20 17:20:42 +0200 | [diff] [blame] | 636 | puts("NAND_MODE\n"); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 637 | mode = "nand0"; |
Michal Simek | 4338035 | 2017-12-01 15:18:24 +0100 | [diff] [blame] | 638 | env_set("modeboot", "nandboot"); |
Michal Simek | 108e184 | 2015-10-05 10:51:12 +0200 | [diff] [blame] | 639 | break; |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 640 | default: |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 641 | mode = ""; |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 642 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
| 643 | break; |
| 644 | } |
| 645 | |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 646 | if (bootseq >= 0) { |
| 647 | bootseq_len = snprintf(NULL, 0, "%i", bootseq); |
| 648 | debug("Bootseq len: %x\n", bootseq_len); |
Michal Simek | 7a117c7 | 2021-01-11 13:46:58 +0100 | [diff] [blame] | 649 | env_set_hex("bootseq", bootseq); |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 650 | } |
| 651 | |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 652 | /* |
| 653 | * One terminating char + one byte for space between mode |
| 654 | * and default boot_targets |
| 655 | */ |
Siva Durga Prasad Paladugu | 245c556 | 2017-12-20 16:35:06 +0530 | [diff] [blame] | 656 | env_targets = env_get("boot_targets"); |
Michal Simek | 7410b14 | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 657 | if (env_targets) |
| 658 | env_targets_len = strlen(env_targets); |
| 659 | |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 660 | new_targets = calloc(1, strlen(mode) + env_targets_len + 2 + |
| 661 | bootseq_len); |
Michal Simek | 089b84d | 2018-06-13 09:42:41 +0200 | [diff] [blame] | 662 | if (!new_targets) |
| 663 | return -ENOMEM; |
Michal Simek | 7410b14 | 2018-04-25 11:10:34 +0200 | [diff] [blame] | 664 | |
Michal Simek | f183a98 | 2018-04-25 11:20:43 +0200 | [diff] [blame] | 665 | if (bootseq >= 0) |
| 666 | sprintf(new_targets, "%s%x %s", mode, bootseq, |
| 667 | env_targets ? env_targets : ""); |
| 668 | else |
| 669 | sprintf(new_targets, "%s %s", mode, |
| 670 | env_targets ? env_targets : ""); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 671 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 672 | env_set("boot_targets", new_targets); |
Michal Simek | ecfb6dc | 2016-04-22 14:28:54 +0200 | [diff] [blame] | 673 | |
Michal Simek | 29b9b71 | 2018-05-17 14:06:06 +0200 | [diff] [blame] | 674 | reset_reason(); |
| 675 | |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 676 | return board_late_init_xilinx(); |
Michal Simek | 04b7e62 | 2015-01-15 10:01:51 +0100 | [diff] [blame] | 677 | } |
Michal Simek | 342edfe | 2018-12-20 09:33:38 +0100 | [diff] [blame] | 678 | #endif |
Siva Durga Prasad Paladugu | 650e0a3 | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 679 | |
| 680 | int checkboard(void) |
| 681 | { |
Michal Simek | 47ce936 | 2016-01-25 11:04:21 +0100 | [diff] [blame] | 682 | puts("Board: Xilinx ZynqMP\n"); |
Siva Durga Prasad Paladugu | 650e0a3 | 2015-08-04 13:01:05 +0530 | [diff] [blame] | 683 | return 0; |
| 684 | } |
Michal Simek | 8d4a8d4 | 2020-07-30 13:37:49 +0200 | [diff] [blame] | 685 | |
| 686 | enum env_location env_get_location(enum env_operation op, int prio) |
| 687 | { |
| 688 | u32 bootmode = zynqmp_get_bootmode(); |
| 689 | |
| 690 | if (prio) |
| 691 | return ENVL_UNKNOWN; |
| 692 | |
| 693 | switch (bootmode) { |
| 694 | case EMMC_MODE: |
| 695 | case SD_MODE: |
| 696 | case SD1_LSHFT_MODE: |
| 697 | case SD_MODE1: |
| 698 | if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) |
| 699 | return ENVL_FAT; |
| 700 | if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4)) |
| 701 | return ENVL_EXT4; |
| 702 | return ENVL_UNKNOWN; |
| 703 | case NAND_MODE: |
| 704 | if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND)) |
| 705 | return ENVL_NAND; |
| 706 | if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI)) |
| 707 | return ENVL_UBI; |
| 708 | return ENVL_UNKNOWN; |
| 709 | case QSPI_MODE_24BIT: |
| 710 | case QSPI_MODE_32BIT: |
| 711 | if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH)) |
| 712 | return ENVL_SPI_FLASH; |
| 713 | return ENVL_UNKNOWN; |
| 714 | case JTAG_MODE: |
| 715 | default: |
| 716 | return ENVL_NOWHERE; |
| 717 | } |
| 718 | } |