|
| 1 | +/* |
| 2 | + * (C) Copyright 2016 Rockchip Electronics Co., Ltd |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: GPL-2.0+ |
| 5 | + */ |
| 6 | + |
| 7 | +#include <common.h> |
| 8 | +#include <debug_uart.h> |
| 9 | +#include <dm.h> |
| 10 | +#include <fdtdec.h> |
| 11 | +#include <led.h> |
| 12 | +#include <malloc.h> |
| 13 | +#include <mmc.h> |
| 14 | +#include <ram.h> |
| 15 | +#include <spl.h> |
| 16 | +#include <asm/gpio.h> |
| 17 | +#include <asm/io.h> |
| 18 | +#include <asm/arch/bootrom.h> |
| 19 | +#include <asm/arch/clock.h> |
| 20 | +#include <asm/arch/hardware.h> |
| 21 | +#include <asm/arch/periph.h> |
| 22 | +#include <asm/arch/sdram.h> |
| 23 | +#include <asm/arch/timer.h> |
| 24 | +#include <dm/pinctrl.h> |
| 25 | +#include <dm/root.h> |
| 26 | +#include <dm/test.h> |
| 27 | +#include <dm/util.h> |
| 28 | +#include <power/regulator.h> |
| 29 | +#include <asm/arch/grf_rk3328.h> |
| 30 | +#include <asm/arch/uart.h> |
| 31 | + |
| 32 | +#define CRU_BASE 0xFF440000 |
| 33 | +#define GRF_BASE 0xFF100000 |
| 34 | +#define UART2_BASE 0xFF130000 |
| 35 | +#define STIMER_BASE_ADDR 0xFF1d0000 |
| 36 | +#define CPU_TIMER_BASE (STIMER_BASE_ADDR + 0x20) |
| 37 | + |
| 38 | +void board_timer_init(void) |
| 39 | +{ |
| 40 | + /* Initialize CNTFRQ */ |
| 41 | + __asm__ volatile ("LDR x0,=24000000"); |
| 42 | + __asm__ volatile ("MSR CNTFRQ_EL0, x0"); |
| 43 | + |
| 44 | + /* Enable STimer1 for core */ |
| 45 | + writel(0x0, CPU_TIMER_BASE + 0x0010); |
| 46 | + writel(0xffffffff, CPU_TIMER_BASE + 0x0000); |
| 47 | + writel(0xffffffff, CPU_TIMER_BASE + 0x0004); |
| 48 | + writel(0x1, CPU_TIMER_BASE + 0x0010); |
| 49 | +} |
| 50 | + |
| 51 | +void board_debug_uart_init(void) |
| 52 | +{ |
| 53 | + struct rk3328_grf_regs * const grf = (void *)GRF_BASE; |
| 54 | + struct rk_uart * const uart = (void *)UART2_BASE; |
| 55 | + |
| 56 | + /* uart_sel_clk default select 24MHz */ |
| 57 | + writel((3 << (8 + 16)) | (2 << 8), CRU_BASE + 0x148); |
| 58 | + |
| 59 | + /* init uart baud rate 1500000 */ |
| 60 | + writel(0x83, &uart->lcr); |
| 61 | + writel(0x1, &uart->rbr); |
| 62 | + writel(0x3, &uart->lcr); |
| 63 | + |
| 64 | + /* Enable early UART2 */ |
| 65 | + rk_clrsetreg(&grf->com_iomux, |
| 66 | + IOMUX_SEL_UART2_MASK, |
| 67 | + IOMUX_SEL_UART2_M1 << IOMUX_SEL_UART2_SHIFT); |
| 68 | + rk_clrsetreg(&grf->gpio2a_iomux, |
| 69 | + GPIO2A0_SEL_MASK, |
| 70 | + GPIO2A0_UART2_TX_M1 << GPIO2A0_SEL_SHIFT); |
| 71 | + rk_clrsetreg(&grf->gpio2a_iomux, |
| 72 | + GPIO2A1_SEL_MASK, |
| 73 | + GPIO2A1_UART2_RX_M1 << GPIO2A1_SEL_SHIFT); |
| 74 | + |
| 75 | + /* enable FIFO */ |
| 76 | + writel(0x1, &uart->sfe); |
| 77 | +} |
| 78 | + |
| 79 | +void board_return_to_bootrom(void) |
| 80 | +{ |
| 81 | + back_to_bootrom(); |
| 82 | +} |
| 83 | + |
| 84 | +u32 spl_boot_device(void) |
| 85 | +{ |
| 86 | + return BOOT_DEVICE_BOOTROM; |
| 87 | +} |
| 88 | + |
| 89 | + |
| 90 | +void board_init_f(ulong dummy) |
| 91 | +{ |
| 92 | + struct udevice *dev; |
| 93 | + int ret; |
| 94 | + |
| 95 | +#define EARLY_UART |
| 96 | +#ifdef EARLY_UART |
| 97 | + debug_uart_init(); |
| 98 | + printascii("U-Boot TPL board init\n"); |
| 99 | +#endif |
| 100 | + |
| 101 | + board_timer_init(); |
| 102 | + |
| 103 | + ret = spl_early_init(); |
| 104 | + if (ret) { |
| 105 | + printf("spl_early_init() failed: %d\n", ret); |
| 106 | + hang(); |
| 107 | + } |
| 108 | + |
| 109 | + ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 110 | + if (ret) { |
| 111 | + printf("DRAM init failed: %d\n", ret); |
| 112 | + return; |
| 113 | + } |
| 114 | +} |
0 commit comments