|
| 1 | +/* |
| 2 | + * Copyright 2013 Freescale Semiconductor, Inc. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: GPL-2.0+ |
| 5 | + */ |
| 6 | + |
| 7 | +#include <common.h> |
| 8 | +#include <ns16550.h> |
| 9 | +#include <malloc.h> |
| 10 | +#include <mmc.h> |
| 11 | +#include <nand.h> |
| 12 | +#include <i2c.h> |
| 13 | +#include <fsl_esdhc.h> |
| 14 | +#include <spi_flash.h> |
| 15 | + |
| 16 | +DECLARE_GLOBAL_DATA_PTR; |
| 17 | + |
| 18 | +#define SYSCLK_MASK 0x00200000 |
| 19 | +#define BOARDREV_MASK 0x10100000 |
| 20 | + |
| 21 | +#define SYSCLK_66 66666666 |
| 22 | +#define SYSCLK_100 100000000 |
| 23 | + |
| 24 | +unsigned long get_board_sys_clk(ulong dummy) |
| 25 | +{ |
| 26 | + ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR); |
| 27 | + u32 val_gpdat, sysclk_gpio; |
| 28 | + |
| 29 | + val_gpdat = in_be32(&pgpio->gpdat); |
| 30 | + sysclk_gpio = val_gpdat & SYSCLK_MASK; |
| 31 | + |
| 32 | + if (sysclk_gpio == 0) |
| 33 | + return SYSCLK_66; |
| 34 | + else |
| 35 | + return SYSCLK_100; |
| 36 | + |
| 37 | + return 0; |
| 38 | +} |
| 39 | + |
| 40 | +phys_size_t get_effective_memsize(void) |
| 41 | +{ |
| 42 | + return CONFIG_SYS_L2_SIZE; |
| 43 | +} |
| 44 | + |
| 45 | +void board_init_f(ulong bootflag) |
| 46 | +{ |
| 47 | + u32 plat_ratio, bus_clk; |
| 48 | + ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR; |
| 49 | + |
| 50 | + console_init_f(); |
| 51 | + |
| 52 | + /* Set pmuxcr to allow both i2c1 and i2c2 */ |
| 53 | + setbits_be32(&gur->pmuxcr, in_be32(&gur->pmuxcr) | 0x1000); |
| 54 | + setbits_be32(&gur->pmuxcr, |
| 55 | + in_be32(&gur->pmuxcr) | MPC85xx_PMUXCR_SD_DATA); |
| 56 | + |
| 57 | + /* Read back the register to synchronize the write. */ |
| 58 | + in_be32(&gur->pmuxcr); |
| 59 | + |
| 60 | +#ifdef CONFIG_SPL_SPI_BOOT |
| 61 | + clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SD_DATA); |
| 62 | +#endif |
| 63 | + |
| 64 | + /* initialize selected port with appropriate baud rate */ |
| 65 | + plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO; |
| 66 | + plat_ratio >>= 1; |
| 67 | + bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; |
| 68 | + gd->bus_clk = bus_clk; |
| 69 | + |
| 70 | + NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, |
| 71 | + bus_clk / 16 / CONFIG_BAUDRATE); |
| 72 | +#ifdef CONFIG_SPL_MMC_BOOT |
| 73 | + puts("\nSD boot...\n"); |
| 74 | +#elif defined(CONFIG_SPL_SPI_BOOT) |
| 75 | + puts("\nSPI Flash boot...\n"); |
| 76 | +#endif |
| 77 | + |
| 78 | + /* copy code to RAM and jump to it - this should not return */ |
| 79 | + /* NOTE - code has to be copied out of NAND buffer before |
| 80 | + * other blocks can be read. |
| 81 | + */ |
| 82 | + relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE); |
| 83 | +} |
| 84 | + |
| 85 | +void board_init_r(gd_t *gd, ulong dest_addr) |
| 86 | +{ |
| 87 | + /* Pointer is writable since we allocated a register for it */ |
| 88 | + gd = (gd_t *)CONFIG_SPL_GD_ADDR; |
| 89 | + bd_t *bd; |
| 90 | + |
| 91 | + memset(gd, 0, sizeof(gd_t)); |
| 92 | + bd = (bd_t *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t)); |
| 93 | + memset(bd, 0, sizeof(bd_t)); |
| 94 | + gd->bd = bd; |
| 95 | + bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR; |
| 96 | + bd->bi_memsize = CONFIG_SYS_L2_SIZE; |
| 97 | + |
| 98 | + probecpu(); |
| 99 | + get_clocks(); |
| 100 | + mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR, |
| 101 | + CONFIG_SPL_RELOC_MALLOC_SIZE); |
| 102 | + |
| 103 | +#ifdef CONFIG_SPL_MMC_BOOT |
| 104 | + mmc_initialize(bd); |
| 105 | +#endif |
| 106 | + /* relocate environment function pointers etc. */ |
| 107 | +#ifdef CONFIG_SPL_NAND_BOOT |
| 108 | + nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
| 109 | + (uchar *)CONFIG_ENV_ADDR); |
| 110 | +#endif |
| 111 | +#ifdef CONFIG_SPL_NAND_BOOT |
| 112 | + nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
| 113 | + (uchar *)CONFIG_ENV_ADDR); |
| 114 | +#endif |
| 115 | +#ifdef CONFIG_SPL_MMC_BOOT |
| 116 | + mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
| 117 | + (uchar *)CONFIG_ENV_ADDR); |
| 118 | +#endif |
| 119 | +#ifdef CONFIG_SPL_SPI_BOOT |
| 120 | + spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
| 121 | + (uchar *)CONFIG_ENV_ADDR); |
| 122 | +#endif |
| 123 | + |
| 124 | + gd->env_addr = (ulong)(CONFIG_ENV_ADDR); |
| 125 | + gd->env_valid = 1; |
| 126 | + |
| 127 | + gd->ram_size = initdram(0); |
| 128 | +#ifdef CONFIG_SPL_NAND_BOOT |
| 129 | + puts("Tertiary program loader running in sram..."); |
| 130 | +#else |
| 131 | + puts("Second program loader running in sram...\n"); |
| 132 | +#endif |
| 133 | + |
| 134 | +#ifdef CONFIG_SPL_MMC_BOOT |
| 135 | + mmc_boot(); |
| 136 | +#elif defined(CONFIG_SPL_SPI_BOOT) |
| 137 | + spi_boot(); |
| 138 | +#elif defined(CONFIG_SPL_NAND_BOOT) |
| 139 | + nand_boot(); |
| 140 | +#endif |
| 141 | +} |
0 commit comments