Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 Michal Simek <monstr@monstr.eu> |
Michal Simek | 3e1b61d | 2018-01-17 07:37:47 +0100 | [diff] [blame] | 4 | * (C) Copyright 2013 - 2018 Xilinx, Inc. |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 8 | #include <init.h> |
Michal Simek | 62b9626 | 2020-07-28 12:45:47 +0200 | [diff] [blame] | 9 | #include <log.h> |
Michal Simek | e6cc3b2 | 2018-02-21 17:04:28 +0100 | [diff] [blame] | 10 | #include <dm/uclass.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 11 | #include <env.h> |
Ashok Reddy Soma | cd08513 | 2021-02-23 08:07:45 -0700 | [diff] [blame] | 12 | #include <env_internal.h> |
Michal Simek | 9e0e37a | 2014-02-24 11:16:32 +0100 | [diff] [blame] | 13 | #include <fdtdec.h> |
Michal Simek | 5b73caf | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 14 | #include <fpga.h> |
Siva Durga Prasad Paladugu | 3c7b4c3 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 15 | #include <malloc.h> |
Michal Simek | 5b73caf | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 16 | #include <mmc.h> |
Michal Simek | 0ecd14e | 2018-06-08 13:45:14 +0200 | [diff] [blame] | 17 | #include <watchdog.h> |
Michal Simek | e6cc3b2 | 2018-02-21 17:04:28 +0100 | [diff] [blame] | 18 | #include <wdt.h> |
Michal Simek | d5dae85 | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 19 | #include <zynqpl.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Michal Simek | 7193653 | 2013-04-12 16:33:08 +0200 | [diff] [blame] | 21 | #include <asm/arch/hardware.h> |
| 22 | #include <asm/arch/sys_proto.h> |
Michal Simek | 80fdef1 | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 23 | #include "../common/board.h" |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | int board_init(void) |
| 28 | { |
Michal Simek | 98757d8 | 2021-02-02 16:34:48 +0100 | [diff] [blame] | 29 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
| 30 | printf("Silicon version:\t%d\n", zynq_get_silicon_version()); |
| 31 | |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 32 | return 0; |
| 33 | } |
| 34 | |
Jagannadha Sutradharudu Teki | b3de924 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 35 | int board_late_init(void) |
| 36 | { |
Siva Durga Prasad Paladugu | 3c7b4c3 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 37 | int env_targets_len = 0; |
| 38 | const char *mode; |
| 39 | char *new_targets; |
| 40 | char *env_targets; |
| 41 | |
Michal Simek | 62b9626 | 2020-07-28 12:45:47 +0200 | [diff] [blame] | 42 | if (!(gd->flags & GD_FLG_ENV_DEFAULT)) { |
| 43 | debug("Saved variables - Skipping\n"); |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | if (!CONFIG_IS_ENABLED(ENV_VARS_UBOOT_RUNTIME_CONFIG)) |
| 48 | return 0; |
| 49 | |
Jagannadha Sutradharudu Teki | b3de924 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 50 | switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) { |
Michal Simek | 085b2b8 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 51 | case ZYNQ_BM_QSPI: |
Siva Durga Prasad Paladugu | 3c7b4c3 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 52 | mode = "qspi"; |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 53 | env_set("modeboot", "qspiboot"); |
Michal Simek | 085b2b8 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 54 | break; |
| 55 | case ZYNQ_BM_NAND: |
Siva Durga Prasad Paladugu | 3c7b4c3 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 56 | mode = "nand"; |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 57 | env_set("modeboot", "nandboot"); |
Michal Simek | 085b2b8 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 58 | break; |
Jagannadha Sutradharudu Teki | b3de924 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 59 | case ZYNQ_BM_NOR: |
Siva Durga Prasad Paladugu | 3c7b4c3 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 60 | mode = "nor"; |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 61 | env_set("modeboot", "norboot"); |
Jagannadha Sutradharudu Teki | b3de924 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 62 | break; |
| 63 | case ZYNQ_BM_SD: |
Michal Simek | 7712fb1 | 2019-09-11 12:51:49 +0200 | [diff] [blame] | 64 | mode = "mmc0"; |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 65 | env_set("modeboot", "sdboot"); |
Jagannadha Sutradharudu Teki | b3de924 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 66 | break; |
| 67 | case ZYNQ_BM_JTAG: |
T Karthik Reddy | c352f1e | 2019-11-13 21:13:44 -0700 | [diff] [blame] | 68 | mode = "jtag pxe dhcp"; |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 69 | env_set("modeboot", "jtagboot"); |
Jagannadha Sutradharudu Teki | b3de924 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 70 | break; |
| 71 | default: |
Siva Durga Prasad Paladugu | 3c7b4c3 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 72 | mode = ""; |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 73 | env_set("modeboot", ""); |
Jagannadha Sutradharudu Teki | b3de924 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 74 | break; |
| 75 | } |
| 76 | |
Siva Durga Prasad Paladugu | 3c7b4c3 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 77 | /* |
| 78 | * One terminating char + one byte for space between mode |
| 79 | * and default boot_targets |
| 80 | */ |
| 81 | env_targets = env_get("boot_targets"); |
| 82 | if (env_targets) |
| 83 | env_targets_len = strlen(env_targets); |
| 84 | |
| 85 | new_targets = calloc(1, strlen(mode) + env_targets_len + 2); |
| 86 | if (!new_targets) |
| 87 | return -ENOMEM; |
| 88 | |
| 89 | sprintf(new_targets, "%s %s", mode, |
| 90 | env_targets ? env_targets : ""); |
| 91 | |
| 92 | env_set("boot_targets", new_targets); |
| 93 | |
Michal Simek | 80fdef1 | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 94 | return board_late_init_xilinx(); |
Jagannadha Sutradharudu Teki | b3de924 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 95 | } |
Michal Simek | f22651c | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 96 | |
Michal Simek | 758f29d | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 97 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
Simon Glass | 76b00ac | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 98 | int dram_init_banksize(void) |
Tom Rini | 361a879 | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 99 | { |
Michal Simek | da3f003 | 2017-11-03 15:25:51 +0100 | [diff] [blame] | 100 | return fdtdec_setup_memory_banksize(); |
Michal Simek | 758f29d | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 101 | } |
| 102 | |
Michal Simek | 8a5db0a | 2016-12-06 16:31:53 +0100 | [diff] [blame] | 103 | int dram_init(void) |
| 104 | { |
Siva Durga Prasad Paladugu | 12308b1 | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 105 | if (fdtdec_setup_mem_size_base() != 0) |
Nathan Rossi | de9bf1b | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 106 | return -EINVAL; |
Michal Simek | 8a5db0a | 2016-12-06 16:31:53 +0100 | [diff] [blame] | 107 | |
| 108 | zynq_ddrc_init(); |
| 109 | |
| 110 | return 0; |
| 111 | } |
Michal Simek | 758f29d | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 112 | #else |
| 113 | int dram_init(void) |
| 114 | { |
Michal Simek | 61dc92a | 2018-04-11 16:12:28 +0200 | [diff] [blame] | 115 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 116 | CONFIG_SYS_SDRAM_SIZE); |
Michal Simek | 758f29d | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 117 | |
| 118 | zynq_ddrc_init(); |
| 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | #endif |
Ashok Reddy Soma | cd08513 | 2021-02-23 08:07:45 -0700 | [diff] [blame] | 123 | |
| 124 | enum env_location env_get_location(enum env_operation op, int prio) |
| 125 | { |
| 126 | u32 bootmode = zynq_slcr_get_boot_mode() & ZYNQ_BM_MASK; |
| 127 | |
| 128 | if (prio) |
| 129 | return ENVL_UNKNOWN; |
| 130 | |
| 131 | switch (bootmode) { |
| 132 | case ZYNQ_BM_SD: |
| 133 | if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) |
| 134 | return ENVL_FAT; |
| 135 | if (IS_ENABLED(CONFIG_ENV_IS_IN_EXT4)) |
| 136 | return ENVL_EXT4; |
Mike Looijmans | 50918d0 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 137 | return ENVL_NOWHERE; |
Ashok Reddy Soma | cd08513 | 2021-02-23 08:07:45 -0700 | [diff] [blame] | 138 | case ZYNQ_BM_NAND: |
| 139 | if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND)) |
| 140 | return ENVL_NAND; |
| 141 | if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI)) |
| 142 | return ENVL_UBI; |
Mike Looijmans | 50918d0 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 143 | return ENVL_NOWHERE; |
Ashok Reddy Soma | cd08513 | 2021-02-23 08:07:45 -0700 | [diff] [blame] | 144 | case ZYNQ_BM_NOR: |
| 145 | case ZYNQ_BM_QSPI: |
| 146 | if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH)) |
| 147 | return ENVL_SPI_FLASH; |
Mike Looijmans | 50918d0 | 2021-07-02 10:28:36 +0200 | [diff] [blame] | 148 | return ENVL_NOWHERE; |
Ashok Reddy Soma | cd08513 | 2021-02-23 08:07:45 -0700 | [diff] [blame] | 149 | case ZYNQ_BM_JTAG: |
| 150 | default: |
| 151 | return ENVL_NOWHERE; |
| 152 | } |
| 153 | } |