Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 1 | /* Copyright 2013 Freescale Semiconductor, Inc. |
| 2 | * |
| 3 | * SPDX-License-Identifier: GPL-2.0+ |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 7 | #include <console.h> |
Simon Glass | 203e94f | 2017-08-03 12:21:56 -0600 | [diff] [blame] | 8 | #include <environment.h> |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 9 | #include <malloc.h> |
| 10 | #include <ns16550.h> |
| 11 | #include <nand.h> |
| 12 | #include <i2c.h> |
| 13 | #include <mmc.h> |
| 14 | #include <fsl_esdhc.h> |
| 15 | #include <spi_flash.h> |
Tang Yuantian | 0023352 | 2014-11-21 11:17:16 +0800 | [diff] [blame] | 16 | #include "../common/sleep.h" |
Simon Glass | ea022a3 | 2016-09-24 18:20:10 -0600 | [diff] [blame] | 17 | #include "../common/spl.h" |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | phys_size_t get_effective_memsize(void) |
| 22 | { |
| 23 | return CONFIG_SYS_L3_SIZE; |
| 24 | } |
| 25 | |
| 26 | unsigned long get_board_sys_clk(void) |
| 27 | { |
| 28 | return CONFIG_SYS_CLK_FREQ; |
| 29 | } |
| 30 | |
| 31 | unsigned long get_board_ddr_clk(void) |
| 32 | { |
| 33 | return CONFIG_DDR_CLK_FREQ; |
| 34 | } |
| 35 | |
| 36 | #define FSL_CORENET_CCSR_PORSR1_RCW_MASK 0xFF800000 |
| 37 | void board_init_f(ulong bootflag) |
| 38 | { |
| 39 | u32 plat_ratio, sys_clk, uart_clk; |
Prabhakar Kushwaha | 9f074e6 | 2014-10-29 22:33:09 +0530 | [diff] [blame] | 40 | #if defined(CONFIG_SPL_NAND_BOOT) && defined(CONFIG_A008044_WORKAROUND) |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 41 | u32 porsr1, pinctl; |
Prabhakar Kushwaha | 31530e0 | 2014-10-29 22:33:55 +0530 | [diff] [blame] | 42 | u32 svr = get_svr(); |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 43 | #endif |
| 44 | ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR; |
| 45 | |
Prabhakar Kushwaha | 9f074e6 | 2014-10-29 22:33:09 +0530 | [diff] [blame] | 46 | #if defined(CONFIG_SPL_NAND_BOOT) && defined(CONFIG_A008044_WORKAROUND) |
Prabhakar Kushwaha | 31530e0 | 2014-10-29 22:33:55 +0530 | [diff] [blame] | 47 | if (IS_SVR_REV(svr, 1, 0)) { |
| 48 | /* |
| 49 | * There is T1040 SoC issue where NOR, FPGA are inaccessible |
| 50 | * during NAND boot because IFC signals > IFC_AD7 are not |
| 51 | * enabled. This workaround changes RCW source to make all |
| 52 | * signals enabled. |
| 53 | */ |
| 54 | porsr1 = in_be32(&gur->porsr1); |
| 55 | pinctl = ((porsr1 & ~(FSL_CORENET_CCSR_PORSR1_RCW_MASK)) |
| 56 | | 0x24800000); |
| 57 | out_be32((unsigned int *)(CONFIG_SYS_DCSRBAR + 0x20000), |
| 58 | pinctl); |
| 59 | } |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | /* Memcpy existing GD at CONFIG_SPL_GD_ADDR */ |
| 63 | memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t)); |
| 64 | |
| 65 | /* Update GD pointer */ |
| 66 | gd = (gd_t *)(CONFIG_SPL_GD_ADDR); |
| 67 | |
Tang Yuantian | ce249d9 | 2014-07-23 17:27:53 +0800 | [diff] [blame] | 68 | #ifdef CONFIG_DEEP_SLEEP |
| 69 | /* disable the console if boot from deep sleep */ |
Tang Yuantian | 0023352 | 2014-11-21 11:17:16 +0800 | [diff] [blame] | 70 | if (is_warm_boot()) |
| 71 | fsl_dp_disable_console(); |
Tang Yuantian | ce249d9 | 2014-07-23 17:27:53 +0800 | [diff] [blame] | 72 | #endif |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 73 | /* compiler optimization barrier needed for GCC >= 3.4 */ |
| 74 | __asm__ __volatile__("" : : : "memory"); |
| 75 | |
| 76 | console_init_f(); |
| 77 | |
| 78 | /* initialize selected port with appropriate baud rate */ |
| 79 | sys_clk = get_board_sys_clk(); |
| 80 | plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; |
| 81 | uart_clk = sys_clk * plat_ratio / 2; |
| 82 | |
| 83 | NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, |
| 84 | uart_clk / 16 / CONFIG_BAUDRATE); |
| 85 | |
| 86 | relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0); |
| 87 | } |
| 88 | |
| 89 | void board_init_r(gd_t *gd, ulong dest_addr) |
| 90 | { |
| 91 | bd_t *bd; |
| 92 | |
| 93 | bd = (bd_t *)(gd + sizeof(gd_t)); |
| 94 | memset(bd, 0, sizeof(bd_t)); |
| 95 | gd->bd = bd; |
| 96 | bd->bi_memstart = CONFIG_SYS_INIT_L3_ADDR; |
| 97 | bd->bi_memsize = CONFIG_SYS_L3_SIZE; |
| 98 | |
Simon Glass | cbcbf71 | 2017-01-23 13:31:22 -0700 | [diff] [blame] | 99 | arch_cpu_init(); |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 100 | get_clocks(); |
| 101 | mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR, |
| 102 | CONFIG_SPL_RELOC_MALLOC_SIZE); |
Sumit Garg | ed4708a | 2016-05-25 12:41:48 -0400 | [diff] [blame] | 103 | gd->flags |= GD_FLG_FULL_MALLOC_INIT; |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 104 | |
| 105 | #ifdef CONFIG_SPL_MMC_BOOT |
| 106 | mmc_initialize(bd); |
| 107 | #endif |
| 108 | |
| 109 | /* relocate environment function pointers etc. */ |
| 110 | #ifdef CONFIG_SPL_NAND_BOOT |
| 111 | nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
| 112 | (uchar *)CONFIG_ENV_ADDR); |
| 113 | #endif |
| 114 | #ifdef CONFIG_SPL_MMC_BOOT |
| 115 | mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
| 116 | (uchar *)CONFIG_ENV_ADDR); |
| 117 | #endif |
| 118 | #ifdef CONFIG_SPL_SPI_BOOT |
Simon Glass | ea022a3 | 2016-09-24 18:20:10 -0600 | [diff] [blame] | 119 | fsl_spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
| 120 | (uchar *)CONFIG_ENV_ADDR); |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 121 | #endif |
| 122 | gd->env_addr = (ulong)(CONFIG_ENV_ADDR); |
Simon Glass | 203e94f | 2017-08-03 12:21:56 -0600 | [diff] [blame] | 123 | gd->env_valid = ENV_VALID; |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 124 | |
| 125 | i2c_init_all(); |
| 126 | |
| 127 | puts("\n\n"); |
| 128 | |
Simon Glass | f1683aa | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 129 | dram_init(); |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 130 | |
| 131 | #ifdef CONFIG_SPL_MMC_BOOT |
| 132 | mmc_boot(); |
| 133 | #elif defined(CONFIG_SPL_SPI_BOOT) |
Simon Glass | ea022a3 | 2016-09-24 18:20:10 -0600 | [diff] [blame] | 134 | fsl_spi_boot(); |
Prabhakar Kushwaha | 18c0144 | 2014-04-08 19:13:56 +0530 | [diff] [blame] | 135 | #elif defined(CONFIG_SPL_NAND_BOOT) |
| 136 | nand_boot(); |
| 137 | #endif |
| 138 | } |