1 /* 2 * (C) Copyright 2015 Google, Inc 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <clk.h> 9 #include <dm.h> 10 #include <ram.h> 11 #include <asm/io.h> 12 #include <asm/arch/clock.h> 13 #include <asm/arch/periph.h> 14 #include <asm/gpio.h> 15 #include <dm/pinctrl.h> 16 17 DECLARE_GLOBAL_DATA_PTR; 18 19 int board_init(void) 20 { 21 #ifdef CONFIG_ROCKCHIP_SPL_BACK_TO_BROM 22 struct udevice *pinctrl; 23 int ret; 24 25 /* 26 * We need to implement sdcard iomux here for the further 27 * initlization, otherwise, it'll hit sdcard command sending 28 * timeout exception. 29 */ 30 ret = uclass_get_device(UCLASS_PINCTRL, 0, &pinctrl); 31 if (ret) { 32 debug("%s: Cannot find pinctrl device\n", __func__); 33 goto err; 34 } 35 ret = pinctrl_request_noflags(pinctrl, PERIPH_ID_SDCARD); 36 if (ret) { 37 debug("%s: Failed to set up SD card\n", __func__); 38 goto err; 39 } 40 41 return 0; 42 err: 43 printf("board_init: Error %d\n", ret); 44 45 /* No way to report error here */ 46 hang(); 47 48 return -1; 49 #else 50 return 0; 51 #endif 52 } 53 54 int dram_init(void) 55 { 56 struct ram_info ram; 57 struct udevice *dev; 58 int ret; 59 60 ret = uclass_get_device(UCLASS_RAM, 0, &dev); 61 if (ret) { 62 debug("DRAM init failed: %d\n", ret); 63 return ret; 64 } 65 ret = ram_get_info(dev, &ram); 66 if (ret) { 67 debug("Cannot get DRAM size: %d\n", ret); 68 return ret; 69 } 70 debug("SDRAM base=%lx, size=%x\n", ram.base, ram.size); 71 gd->ram_size = ram.size; 72 73 return 0; 74 } 75 76 #ifndef CONFIG_SYS_DCACHE_OFF 77 void enable_caches(void) 78 { 79 /* Enable D-cache. I-cache is already enabled in start.S */ 80 dcache_enable(); 81 } 82 #endif 83 84 void lowlevel_init(void) 85 { 86 } 87 88 static int do_clock(cmd_tbl_t *cmdtp, int flag, int argc, 89 char * const argv[]) 90 { 91 static const struct { 92 char *name; 93 int id; 94 } clks[] = { 95 { "osc", CLK_OSC }, 96 { "apll", CLK_ARM }, 97 { "dpll", CLK_DDR }, 98 { "cpll", CLK_CODEC }, 99 { "gpll", CLK_GENERAL }, 100 #ifdef CONFIG_ROCKCHIP_RK3036 101 { "mpll", CLK_NEW }, 102 #else 103 { "npll", CLK_NEW }, 104 #endif 105 }; 106 int ret, i; 107 struct udevice *dev; 108 109 ret = uclass_get_device(UCLASS_CLK, 0, &dev); 110 if (ret) { 111 printf("clk-uclass not found\n"); 112 return 0; 113 } 114 115 for (i = 0; i < ARRAY_SIZE(clks); i++) { 116 struct clk clk; 117 ulong rate; 118 119 clk.id = clks[i].id; 120 ret = clk_request(dev, &clk); 121 if (ret < 0) 122 continue; 123 124 rate = clk_get_rate(&clk); 125 printf("%s: %lu\n", clks[i].name, rate); 126 127 clk_free(&clk); 128 } 129 130 return 0; 131 } 132 133 U_BOOT_CMD( 134 clock, 2, 1, do_clock, 135 "display information about clocks", 136 "" 137 ); 138