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> |
| 25 | #include <asm/arch-rockchip/timer.h> |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 26 | #include <dm/root.h> |
| 27 | #include <dm/test.h> |
| 28 | #include <dm/util.h> |
| 29 | #include <power/regulator.h> |
Wadim Egorov | 6ee2d01 | 2017-06-19 12:36:40 +0200 | [diff] [blame] | 30 | #include <power/rk8xx_pmic.h> |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 31 | |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
| 34 | u32 spl_boot_device(void) |
| 35 | { |
Simon Glass | 26158ef | 2016-07-04 11:58:32 -0600 | [diff] [blame] | 36 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 37 | const void *blob = gd->fdt_blob; |
| 38 | struct udevice *dev; |
| 39 | const char *bootdev; |
| 40 | int node; |
| 41 | int ret; |
| 42 | |
| 43 | bootdev = fdtdec_get_config_string(blob, "u-boot,boot0"); |
| 44 | debug("Boot device %s\n", bootdev); |
| 45 | if (!bootdev) |
| 46 | goto fallback; |
| 47 | |
| 48 | node = fdt_path_offset(blob, bootdev); |
| 49 | if (node < 0) { |
| 50 | debug("node=%d\n", node); |
| 51 | goto fallback; |
| 52 | } |
Jean-Jacques Hiblot | a7b0d6a | 2018-08-09 16:17:44 +0200 | [diff] [blame] | 53 | ret = device_get_global_by_ofnode(offset_to_ofnode(node), &dev); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 54 | if (ret) { |
| 55 | debug("device at node %s/%d not found: %d\n", bootdev, node, |
| 56 | ret); |
| 57 | goto fallback; |
| 58 | } |
| 59 | debug("Found device %s\n", dev->name); |
| 60 | switch (device_get_uclass_id(dev)) { |
| 61 | case UCLASS_SPI_FLASH: |
| 62 | return BOOT_DEVICE_SPI; |
| 63 | case UCLASS_MMC: |
| 64 | return BOOT_DEVICE_MMC1; |
| 65 | default: |
| 66 | debug("Booting from device uclass '%s' not supported\n", |
| 67 | dev_get_uclass_name(dev)); |
| 68 | } |
| 69 | |
| 70 | fallback: |
Simon Glass | bf8d7bf | 2016-11-13 14:22:16 -0700 | [diff] [blame] | 71 | #elif defined(CONFIG_TARGET_CHROMEBOOK_JERRY) || \ |
Simon Glass | e51b2e7 | 2016-11-13 14:24:54 -0700 | [diff] [blame] | 72 | defined(CONFIG_TARGET_CHROMEBIT_MICKEY) || \ |
Marty E. Plummer | 2708698 | 2019-01-05 20:12:08 -0600 | [diff] [blame] | 73 | defined(CONFIG_TARGET_CHROMEBOOK_MINNIE) || \ |
| 74 | defined(CONFIG_TARGET_CHROMEBOOK_SPEEDY) |
Simon Glass | 6f9087c | 2016-11-13 14:21:57 -0700 | [diff] [blame] | 75 | return BOOT_DEVICE_SPI; |
Simon Glass | 26158ef | 2016-07-04 11:58:32 -0600 | [diff] [blame] | 76 | #endif |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 77 | return BOOT_DEVICE_MMC1; |
| 78 | } |
| 79 | |
Wadim Egorov | 6ee2d01 | 2017-06-19 12:36:40 +0200 | [diff] [blame] | 80 | #if !defined(CONFIG_SPL_OF_PLATDATA) |
| 81 | static int phycore_init(void) |
| 82 | { |
| 83 | struct udevice *pmic; |
| 84 | int ret; |
| 85 | |
| 86 | ret = uclass_first_device_err(UCLASS_PMIC, &pmic); |
| 87 | if (ret) |
| 88 | return ret; |
| 89 | |
| 90 | #if defined(CONFIG_SPL_POWER_SUPPORT) |
| 91 | /* Increase USB input current to 2A */ |
| 92 | ret = rk818_spl_configure_usb_input_current(pmic, 2000); |
| 93 | if (ret) |
| 94 | return ret; |
| 95 | |
| 96 | /* Close charger when USB lower then 3.26V */ |
| 97 | ret = rk818_spl_configure_usb_chrg_shutdown(pmic, 3260000); |
| 98 | if (ret) |
| 99 | return ret; |
| 100 | #endif |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | #endif |
| 105 | |
Kever Yang | a3eff93 | 2019-07-09 21:58:43 +0800 | [diff] [blame^] | 106 | __weak int arch_cpu_init(void) |
| 107 | { |
| 108 | return 0; |
| 109 | } |
| 110 | |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 111 | void board_init_f(ulong dummy) |
| 112 | { |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 113 | struct udevice *dev; |
| 114 | int ret; |
| 115 | |
Kever Yang | abfed9b | 2019-03-29 09:09:04 +0800 | [diff] [blame] | 116 | #ifdef CONFIG_DEBUG_UART |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 117 | /* |
| 118 | * Debug UART can be used from here if required: |
| 119 | * |
| 120 | * debug_uart_init(); |
| 121 | * printch('a'); |
| 122 | * printhex8(0x1234); |
| 123 | * printascii("string"); |
| 124 | */ |
| 125 | debug_uart_init(); |
Eddie Cai | 9d62e82 | 2017-04-18 19:17:27 +0800 | [diff] [blame] | 126 | debug("\nspl:debug uart enabled in %s\n", __func__); |
Kever Yang | abfed9b | 2019-03-29 09:09:04 +0800 | [diff] [blame] | 127 | #endif |
Eddie Cai | 3e2b61c | 2017-03-15 08:43:29 -0600 | [diff] [blame] | 128 | ret = spl_early_init(); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 129 | if (ret) { |
Eddie Cai | 3e2b61c | 2017-03-15 08:43:29 -0600 | [diff] [blame] | 130 | debug("spl_early_init() failed: %d\n", ret); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 131 | hang(); |
| 132 | } |
| 133 | |
huang lin | 8db3e24 | 2015-11-17 14:20:09 +0800 | [diff] [blame] | 134 | rockchip_timer_init(); |
Kever Yang | a3eff93 | 2019-07-09 21:58:43 +0800 | [diff] [blame^] | 135 | arch_cpu_init(); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 136 | |
Simon Glass | ae8fe41 | 2016-07-17 15:23:17 -0600 | [diff] [blame] | 137 | ret = rockchip_get_clk(&dev); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 138 | if (ret) { |
| 139 | debug("CLK init failed: %d\n", ret); |
| 140 | return; |
| 141 | } |
| 142 | |
Wadim Egorov | 6ee2d01 | 2017-06-19 12:36:40 +0200 | [diff] [blame] | 143 | #if !defined(CONFIG_SPL_OF_PLATDATA) |
| 144 | if (of_machine_is_compatible("phytec,rk3288-phycore-som")) { |
| 145 | ret = phycore_init(); |
| 146 | if (ret) { |
| 147 | debug("Failed to set up phycore power settings: %d\n", |
| 148 | ret); |
| 149 | return; |
| 150 | } |
| 151 | } |
| 152 | #endif |
| 153 | |
Jagan Teki | 387fd4b | 2017-09-27 23:03:12 +0530 | [diff] [blame] | 154 | #if !defined(CONFIG_SUPPORT_TPL) |
Eddie Cai | 9d62e82 | 2017-04-18 19:17:27 +0800 | [diff] [blame] | 155 | debug("\nspl:init dram\n"); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 156 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 157 | if (ret) { |
| 158 | debug("DRAM init failed: %d\n", ret); |
| 159 | return; |
| 160 | } |
Jagan Teki | 387fd4b | 2017-09-27 23:03:12 +0530 | [diff] [blame] | 161 | #endif |
| 162 | |
Philipp Tomsich | 798370f | 2017-06-29 11:21:15 +0200 | [diff] [blame] | 163 | #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) && !defined(CONFIG_SPL_BOARD_INIT) |
Philipp Tomsich | 7234c73 | 2017-10-10 16:21:16 +0200 | [diff] [blame] | 164 | back_to_bootrom(BROM_BOOT_NEXTSTAGE); |
Xu Ziyuan | 5401eb8 | 2016-07-12 19:09:49 +0800 | [diff] [blame] | 165 | #endif |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static int setup_led(void) |
| 169 | { |
| 170 | #ifdef CONFIG_SPL_LED |
| 171 | struct udevice *dev; |
| 172 | char *led_name; |
| 173 | int ret; |
| 174 | |
| 175 | led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led"); |
| 176 | if (!led_name) |
| 177 | return 0; |
| 178 | ret = led_get_by_label(led_name, &dev); |
| 179 | if (ret) { |
| 180 | debug("%s: get=%d\n", __func__, ret); |
| 181 | return ret; |
| 182 | } |
| 183 | ret = led_set_on(dev, 1); |
| 184 | if (ret) |
| 185 | return ret; |
| 186 | #endif |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | void spl_board_init(void) |
| 192 | { |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 193 | int ret; |
| 194 | |
| 195 | ret = setup_led(); |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 196 | if (ret) { |
| 197 | debug("LED ret=%d\n", ret); |
| 198 | hang(); |
| 199 | } |
| 200 | |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 201 | preloader_console_init(); |
Philipp Tomsich | 798370f | 2017-06-29 11:21:15 +0200 | [diff] [blame] | 202 | #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) |
Philipp Tomsich | 7234c73 | 2017-10-10 16:21:16 +0200 | [diff] [blame] | 203 | back_to_bootrom(BROM_BOOT_NEXTSTAGE); |
Sandy Patterson | a9e92ee | 2016-08-10 10:21:47 -0400 | [diff] [blame] | 204 | #endif |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 205 | return; |
Simon Glass | 2cffe66 | 2015-08-30 16:55:38 -0600 | [diff] [blame] | 206 | } |
Jagan Teki | 536e4d3 | 2017-09-27 23:03:14 +0530 | [diff] [blame] | 207 | |
| 208 | #ifdef CONFIG_SPL_OS_BOOT |
| 209 | |
| 210 | #define PMU_BASE 0xff730000 |
| 211 | int dram_init_banksize(void) |
| 212 | { |
| 213 | struct rk3288_pmu *const pmu = (void *)PMU_BASE; |
| 214 | size_t size = rockchip_sdram_size((phys_addr_t)&pmu->sys_reg[2]); |
| 215 | |
| 216 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
| 217 | gd->bd->bi_dram[0].size = size; |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | #endif |