Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 Michal Simek <monstr@monstr.eu> |
Michal Simek | 98d0f1f | 2018-01-17 07:37:47 +0100 | [diff] [blame] | 4 | * (C) Copyright 2013 - 2018 Xilinx, Inc. |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 8 | #include <init.h> |
Michal Simek | 309ef80 | 2018-02-21 17:04:28 +0100 | [diff] [blame] | 9 | #include <dm/uclass.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 10 | #include <env.h> |
Michal Simek | 65ef52f | 2014-02-24 11:16:32 +0100 | [diff] [blame] | 11 | #include <fdtdec.h> |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 12 | #include <fpga.h> |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 13 | #include <malloc.h> |
Michal Simek | 0f79670 | 2014-04-25 13:51:17 +0200 | [diff] [blame] | 14 | #include <mmc.h> |
Michal Simek | c07b225 | 2018-06-08 13:45:14 +0200 | [diff] [blame] | 15 | #include <watchdog.h> |
Michal Simek | 309ef80 | 2018-02-21 17:04:28 +0100 | [diff] [blame] | 16 | #include <wdt.h> |
Michal Simek | 15d654c | 2013-04-22 15:43:02 +0200 | [diff] [blame] | 17 | #include <zynqpl.h> |
Michal Simek | 242192b | 2013-04-12 16:33:08 +0200 | [diff] [blame] | 18 | #include <asm/arch/hardware.h> |
| 19 | #include <asm/arch/sys_proto.h> |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 20 | #include "../common/board.h" |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
| 24 | int board_init(void) |
| 25 | { |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 26 | return 0; |
| 27 | } |
| 28 | |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 29 | int board_late_init(void) |
| 30 | { |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 31 | int env_targets_len = 0; |
| 32 | const char *mode; |
| 33 | char *new_targets; |
| 34 | char *env_targets; |
| 35 | |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 36 | switch ((zynq_slcr_get_boot_mode()) & ZYNQ_BM_MASK) { |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 37 | case ZYNQ_BM_QSPI: |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 38 | mode = "qspi"; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 39 | env_set("modeboot", "qspiboot"); |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 40 | break; |
| 41 | case ZYNQ_BM_NAND: |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 42 | mode = "nand"; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 43 | env_set("modeboot", "nandboot"); |
Michal Simek | 1935671 | 2016-12-16 13:16:14 +0100 | [diff] [blame] | 44 | break; |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 45 | case ZYNQ_BM_NOR: |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 46 | mode = "nor"; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 47 | env_set("modeboot", "norboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 48 | break; |
| 49 | case ZYNQ_BM_SD: |
Michal Simek | 9541d0b | 2019-09-11 12:51:49 +0200 | [diff] [blame] | 50 | mode = "mmc0"; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 51 | env_set("modeboot", "sdboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 52 | break; |
| 53 | case ZYNQ_BM_JTAG: |
T Karthik Reddy | 6c28c29 | 2019-11-13 21:13:44 -0700 | [diff] [blame] | 54 | mode = "jtag pxe dhcp"; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 55 | env_set("modeboot", "jtagboot"); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 56 | break; |
| 57 | default: |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 58 | mode = ""; |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 59 | env_set("modeboot", ""); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 60 | break; |
| 61 | } |
| 62 | |
Siva Durga Prasad Paladugu | bd75bc1 | 2019-01-25 17:06:06 +0530 | [diff] [blame] | 63 | /* |
| 64 | * One terminating char + one byte for space between mode |
| 65 | * and default boot_targets |
| 66 | */ |
| 67 | env_targets = env_get("boot_targets"); |
| 68 | if (env_targets) |
| 69 | env_targets_len = strlen(env_targets); |
| 70 | |
| 71 | new_targets = calloc(1, strlen(mode) + env_targets_len + 2); |
| 72 | if (!new_targets) |
| 73 | return -ENOMEM; |
| 74 | |
| 75 | sprintf(new_targets, "%s %s", mode, |
| 76 | env_targets ? env_targets : ""); |
| 77 | |
| 78 | env_set("boot_targets", new_targets); |
| 79 | |
Michal Simek | 705d44a | 2020-03-31 12:39:37 +0200 | [diff] [blame] | 80 | return board_late_init_xilinx(); |
Jagannadha Sutradharudu Teki | 11704c2 | 2014-01-09 01:48:21 +0530 | [diff] [blame] | 81 | } |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 82 | |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 83 | #if !defined(CONFIG_SYS_SDRAM_BASE) && !defined(CONFIG_SYS_SDRAM_SIZE) |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 84 | int dram_init_banksize(void) |
Nathan Rossi | c12892b | 2016-12-04 19:33:22 +1000 | [diff] [blame] | 85 | { |
Michal Simek | d5b7de6 | 2017-11-03 15:25:51 +0100 | [diff] [blame] | 86 | return fdtdec_setup_memory_banksize(); |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 87 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 88 | |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 89 | int dram_init(void) |
| 90 | { |
Siva Durga Prasad Paladugu | b3d55ea | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 91 | if (fdtdec_setup_mem_size_base() != 0) |
Nathan Rossi | 58ea0d8 | 2016-12-19 00:03:34 +1000 | [diff] [blame] | 92 | return -EINVAL; |
Tom Rini | edcfdbd | 2016-12-09 07:56:54 -0500 | [diff] [blame] | 93 | |
| 94 | zynq_ddrc_init(); |
| 95 | |
| 96 | return 0; |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 97 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 98 | #else |
| 99 | int dram_init(void) |
| 100 | { |
Michal Simek | 1b84621 | 2018-04-11 16:12:28 +0200 | [diff] [blame] | 101 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
| 102 | CONFIG_SYS_SDRAM_SIZE); |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 103 | |
Michal Simek | f5ff7bc | 2013-06-17 14:37:01 +0200 | [diff] [blame] | 104 | zynq_ddrc_init(); |
| 105 | |
Michal Simek | af482d5 | 2012-09-28 09:56:37 +0000 | [diff] [blame] | 106 | return 0; |
| 107 | } |
Michal Simek | f4780a7 | 2016-04-01 15:56:33 +0200 | [diff] [blame] | 108 | #endif |