Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Google, Inc |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <debug_uart.h> |
| 8 | #include <dm.h> |
| 9 | #include <fdtdec.h> |
Wadim Egorov | 6ee2d01 | 2017-06-19 12:36:40 +0200 | [diff] [blame] | 10 | #include <i2c.h> |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 11 | #include <led.h> |
| 12 | #include <malloc.h> |
| 13 | #include <ram.h> |
| 14 | #include <spl.h> |
| 15 | #include <asm/gpio.h> |
| 16 | #include <asm/io.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 17 | #include <asm/arch-rockchip/bootrom.h> |
| 18 | #include <asm/arch-rockchip/clock.h> |
| 19 | #include <asm/arch-rockchip/hardware.h> |
| 20 | #include <asm/arch-rockchip/periph.h> |
| 21 | #include <asm/arch-rockchip/pmu_rk3288.h> |
| 22 | #include <asm/arch-rockchip/sdram.h> |
| 23 | #include <asm/arch-rockchip/sdram_common.h> |
| 24 | #include <asm/arch-rockchip/sys_proto.h> |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 25 | #include <dm/root.h> |
| 26 | #include <dm/test.h> |
| 27 | #include <dm/util.h> |
| 28 | #include <power/regulator.h> |
Wadim Egorov | 6ee2d01 | 2017-06-19 12:36:40 +0200 | [diff] [blame] | 29 | #include <power/rk8xx_pmic.h> |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
Kever Yang | bd8532e | 2019-07-22 19:59:15 +0800 | [diff] [blame^] | 33 | void board_return_to_bootrom(void) |
| 34 | { |
| 35 | back_to_bootrom(BROM_BOOT_NEXTSTAGE); |
| 36 | } |
| 37 | |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 38 | u32 spl_boot_device(void) |
| 39 | { |
Simon Glass | 26158ef | 2016-07-04 11:58:32 -0600 | [diff] [blame] | 40 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 41 | const void *blob = gd->fdt_blob; |
| 42 | struct udevice *dev; |
| 43 | const char *bootdev; |
| 44 | int node; |
| 45 | int ret; |
| 46 | |
| 47 | bootdev = fdtdec_get_config_string(blob, "u-boot,boot0"); |
| 48 | debug("Boot device %s\n", bootdev); |
| 49 | if (!bootdev) |
| 50 | goto fallback; |
| 51 | |
| 52 | node = fdt_path_offset(blob, bootdev); |
| 53 | if (node < 0) { |
| 54 | debug("node=%d\n", node); |
| 55 | goto fallback; |
| 56 | } |
Jean-Jacques Hiblot | a7b0d6a | 2018-08-09 16:17:44 +0200 | [diff] [blame] | 57 | ret = device_get_global_by_ofnode(offset_to_ofnode(node), &dev); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 58 | if (ret) { |
| 59 | debug("device at node %s/%d not found: %d\n", bootdev, node, |
| 60 | ret); |
| 61 | goto fallback; |
| 62 | } |
| 63 | debug("Found device %s\n", dev->name); |
| 64 | switch (device_get_uclass_id(dev)) { |
| 65 | case UCLASS_SPI_FLASH: |
| 66 | return BOOT_DEVICE_SPI; |
| 67 | case UCLASS_MMC: |
| 68 | return BOOT_DEVICE_MMC1; |
| 69 | default: |
| 70 | debug("Booting from device uclass '%s' not supported\n", |
| 71 | dev_get_uclass_name(dev)); |
| 72 | } |
| 73 | |
| 74 | fallback: |
Simon Glass | bf8d7bf | 2016-11-13 14:22:16 -0700 | [diff] [blame] | 75 | #elif defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \ |
Simon Glass | e51b2e7 | 2016-11-13 14:24:54 -0700 | [diff] [blame] | 76 | defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \ |
Marty E. Plummer | 2708698 | 2019-01-05 20:12:08 -0600 | [diff] [blame] | 77 | defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \ |
| 78 | defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY) |
Simon Glass | 6f9087c | 2016-11-13 14:21:57 -0700 | [diff] [blame] | 79 | return BOOT_DEVICE_SPI; |
Simon Glass | 26158ef | 2016-07-04 11:58:32 -0600 | [diff] [blame] | 80 | #endif |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 81 | return BOOT_DEVICE_MMC1; |
| 82 | } |
| 83 | |
Wadim Egorov | 6ee2d01 | 2017-06-19 12:36:40 +0200 | [diff] [blame] | 84 | #if !defined(CONFIG_SPL_OF_PLATDATA) |
| 85 | static int phycore_init(void) |
| 86 | { |
| 87 | struct udevice *pmic; |
| 88 | int ret; |
| 89 | |
| 90 | ret = uclass_first_device_err(UCLASS_PMIC, &pmic); |
| 91 | if (ret) |
| 92 | return ret; |
| 93 | |
| 94 | #if defined(CONFIG_SPL_POWER_SUPPORT) |
| 95 | /* Increase USB input current to 2A */ |
| 96 | ret = rk818_spl_configure_usb_input_current(pmic, 2000); |
| 97 | if (ret) |
| 98 | return ret; |
| 99 | |
| 100 | /* Close charger when USB lower then 3.26V */ |
| 101 | ret = rk818_spl_configure_usb_chrg_shutdown(pmic, 3260000); |
| 102 | if (ret) |
| 103 | return ret; |
| 104 | #endif |
| 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | #endif |
| 109 | |
Kever Yang | a3eff93 | 2019-07-09 21:58:43 +0800 | [diff] [blame] | 110 | __weak int arch_cpu_init(void) |
| 111 | { |
| 112 | return 0; |
| 113 | } |
| 114 | |
Kever Yang | 243fca7 | 2019-07-09 22:00:26 +0800 | [diff] [blame] | 115 | #define TIMER_LOAD_COUNT_L 0x00 |
| 116 | #define TIMER_LOAD_COUNT_H 0x04 |
| 117 | #define TIMER_CONTROL_REG 0x10 |
| 118 | #define TIMER_EN 0x1 |
| 119 | #define TIMER_FMODE BIT(0) |
| 120 | #define TIMER_RMODE BIT(1) |
| 121 | |
| 122 | void rockchip_stimer_init(void) |
| 123 | { |
| 124 | /* If Timer already enabled, don't re-init it */ |
| 125 | u32 reg = readl(CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 126 | |
| 127 | if (reg & TIMER_EN) |
| 128 | return; |
| 129 | |
| 130 | asm volatile("mcr p15, 0, %0, c14, c0, 0" |
| 131 | : : "r"(COUNTER_FREQUENCY)); |
| 132 | |
| 133 | writel(0, CONFIG_ROCKCHIP_STIMER_BASE + TIMER_CONTROL_REG); |
| 134 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE); |
| 135 | writel(0xffffffff, CONFIG_ROCKCHIP_STIMER_BASE + 4); |
| 136 | writel(TIMER_EN | TIMER_FMODE, CONFIG_ROCKCHIP_STIMER_BASE + |
| 137 | TIMER_CONTROL_REG); |
| 138 | } |
| 139 | |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 140 | void board_init_f(ulong dummy) |
| 141 | { |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 142 | struct udevice *dev; |
| 143 | int ret; |
| 144 | |
Kever Yang | abfed9b | 2019-03-29 09:09:04 +0800 | [diff] [blame] | 145 | #ifdef CONFIG_DEBUG_UART |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 146 | /* |
| 147 | * Debug UART can be used from here if required: |
| 148 | * |
| 149 | * debug_uart_init(); |
| 150 | * printch('a'); |
| 151 | * printhex8(0x1234); |
| 152 | * printascii("string"); |
| 153 | */ |
| 154 | debug_uart_init(); |
Eddie Cai | 9d62e82 | 2017-04-18 19:17:27 +0800 | [diff] [blame] | 155 | debug("\nspl:debug uart enabled in %s\n", __func__); |
Kever Yang | abfed9b | 2019-03-29 09:09:04 +0800 | [diff] [blame] | 156 | #endif |
Eddie Cai | 3e2b61c | 2017-03-15 08:43:29 -0600 | [diff] [blame] | 157 | ret = spl_early_init(); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 158 | if (ret) { |
Eddie Cai | 3e2b61c | 2017-03-15 08:43:29 -0600 | [diff] [blame] | 159 | debug("spl_early_init() failed: %d\n", ret); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 160 | hang(); |
| 161 | } |
| 162 | |
Kever Yang | 243fca7 | 2019-07-09 22:00:26 +0800 | [diff] [blame] | 163 | /* Init secure timer */ |
| 164 | rockchip_stimer_init(); |
| 165 | /* Init ARM arch timer in arch/arm/cpu/armv7/arch_timer.c */ |
| 166 | timer_init(); |
| 167 | |
Kever Yang | a3eff93 | 2019-07-09 21:58:43 +0800 | [diff] [blame] | 168 | arch_cpu_init(); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 169 | |
Simon Glass | ae8fe41 | 2016-07-17 15:23:17 -0600 | [diff] [blame] | 170 | ret = rockchip_get_clk(&dev); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 171 | if (ret) { |
| 172 | debug("CLK init failed: %d\n", ret); |
| 173 | return; |
| 174 | } |
| 175 | |
Wadim Egorov | 6ee2d01 | 2017-06-19 12:36:40 +0200 | [diff] [blame] | 176 | #if !defined(CONFIG_SPL_OF_PLATDATA) |
| 177 | if (of_machine_is_compatible("phytec,rk3288-phycore-som")) { |
| 178 | ret = phycore_init(); |
| 179 | if (ret) { |
| 180 | debug("Failed to set up phycore power settings: %d\n", |
| 181 | ret); |
| 182 | return; |
| 183 | } |
| 184 | } |
| 185 | #endif |
| 186 | |
Jagan Teki | 387fd4b | 2017-09-27 23:03:12 +0530 | [diff] [blame] | 187 | #if !defined(CONFIG_SUPPORT_TPL) |
Eddie Cai | 9d62e82 | 2017-04-18 19:17:27 +0800 | [diff] [blame] | 188 | debug("\nspl:init dram\n"); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 189 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 190 | if (ret) { |
| 191 | debug("DRAM init failed: %d\n", ret); |
| 192 | return; |
| 193 | } |
Jagan Teki | 387fd4b | 2017-09-27 23:03:12 +0530 | [diff] [blame] | 194 | #endif |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static int setup_led(void) |
| 198 | { |
| 199 | #ifdef CONFIG_SPL_LED |
| 200 | struct udevice *dev; |
| 201 | char *led_name; |
| 202 | int ret; |
| 203 | |
| 204 | led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led"); |
| 205 | if (!led_name) |
| 206 | return 0; |
| 207 | ret = led_get_by_label(led_name, &dev); |
| 208 | if (ret) { |
| 209 | debug("%s: get=%d\n", __func__, ret); |
| 210 | return ret; |
| 211 | } |
| 212 | ret = led_set_on(dev, 1); |
| 213 | if (ret) |
| 214 | return ret; |
| 215 | #endif |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | void spl_board_init(void) |
| 221 | { |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 222 | int ret; |
| 223 | |
| 224 | ret = setup_led(); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 225 | if (ret) { |
| 226 | debug("LED ret=%d\n", ret); |
| 227 | hang(); |
| 228 | } |
| 229 | |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 230 | preloader_console_init(); |
Kever Yang | bd8532e | 2019-07-22 19:59:15 +0800 | [diff] [blame^] | 231 | |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 232 | return; |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 233 | } |
Jagan Teki | 536e4d3 | 2017-09-27 23:03:14 +0530 | [diff] [blame] | 234 | |
| 235 | #ifdef CONFIG_SPL_OS_BOOT |
| 236 | |
| 237 | #define PMU_BASE 0xff730000 |
| 238 | int dram_init_banksize(void) |
| 239 | { |
| 240 | struct rk3288_pmu *const pmu = (void *)PMU_BASE; |
| 241 | size_t size = rockchip_sdram_size((phys_addr_t)&pmu->sys_reg[2]); |
| 242 | |
| 243 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 244 | gd->bd->bi_dram[0].size = size; |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | #endif |