Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Google, Inc |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
Heiko Stübner | ba188bb | 2017-03-20 12:40:33 +0100 | [diff] [blame] | 6 | #include <clk.h> |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 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 <ram.h> |
| 14 | #include <spl.h> |
Simon Glass | f473eba | 2019-01-21 14:53:31 -0700 | [diff] [blame] | 15 | #include <syscon.h> |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 16 | #include <asm/gpio.h> |
| 17 | #include <asm/io.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 18 | #include <asm/arch-rockchip/bootrom.h> |
| 19 | #include <asm/arch-rockchip/clock.h> |
| 20 | #include <asm/arch-rockchip/grf_rk3188.h> |
| 21 | #include <asm/arch-rockchip/hardware.h> |
| 22 | #include <asm/arch-rockchip/periph.h> |
| 23 | #include <asm/arch-rockchip/pmu_rk3188.h> |
| 24 | #include <asm/arch-rockchip/sdram.h> |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 25 | #include <dm/root.h> |
| 26 | #include <dm/test.h> |
| 27 | #include <dm/util.h> |
| 28 | #include <power/regulator.h> |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 29 | |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
| 32 | u32 spl_boot_device(void) |
| 33 | { |
| 34 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
| 35 | const void *blob = gd->fdt_blob; |
| 36 | struct udevice *dev; |
| 37 | const char *bootdev; |
| 38 | int node; |
| 39 | int ret; |
| 40 | |
| 41 | bootdev = fdtdec_get_config_string(blob, "u-boot,boot0"); |
| 42 | debug("Boot device %s\n", bootdev); |
| 43 | if (!bootdev) |
| 44 | goto fallback; |
| 45 | |
| 46 | node = fdt_path_offset(blob, bootdev); |
| 47 | if (node < 0) { |
| 48 | debug("node=%d\n", node); |
| 49 | goto fallback; |
| 50 | } |
Jean-Jacques Hiblot | a7b0d6a | 2018-08-09 16:17:44 +0200 | [diff] [blame] | 51 | ret = device_get_global_by_ofnode(offset_to_ofnode(node), &dev); |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 52 | if (ret) { |
| 53 | debug("device at node %s/%d not found: %d\n", bootdev, node, |
| 54 | ret); |
| 55 | goto fallback; |
| 56 | } |
| 57 | debug("Found device %s\n", dev->name); |
| 58 | switch (device_get_uclass_id(dev)) { |
| 59 | case UCLASS_SPI_FLASH: |
| 60 | return BOOT_DEVICE_SPI; |
| 61 | case UCLASS_MMC: |
| 62 | return BOOT_DEVICE_MMC1; |
| 63 | default: |
| 64 | debug("Booting from device uclass '%s' not supported\n", |
| 65 | dev_get_uclass_name(dev)); |
| 66 | } |
| 67 | |
| 68 | fallback: |
| 69 | #endif |
| 70 | return BOOT_DEVICE_MMC1; |
| 71 | } |
| 72 | |
Heiko Stübner | ba188bb | 2017-03-20 12:40:33 +0100 | [diff] [blame] | 73 | static int setup_arm_clock(void) |
| 74 | { |
| 75 | struct udevice *dev; |
| 76 | struct clk clk; |
| 77 | int ret; |
| 78 | |
| 79 | ret = rockchip_get_clk(&dev); |
| 80 | if (ret) |
| 81 | return ret; |
| 82 | |
| 83 | clk.id = CLK_ARM; |
| 84 | ret = clk_request(dev, &clk); |
| 85 | if (ret < 0) |
| 86 | return ret; |
| 87 | |
| 88 | ret = clk_set_rate(&clk, 600000000); |
| 89 | |
| 90 | clk_free(&clk); |
| 91 | return ret; |
| 92 | } |
| 93 | |
Kever Yang | d2af98b | 2018-11-29 10:07:38 +0800 | [diff] [blame] | 94 | void board_init_f(ulong dummy) |
| 95 | { |
David Wu | cee4c82 | 2019-01-02 20:50:58 +0800 | [diff] [blame] | 96 | struct udevice *dev; |
Kever Yang | d2af98b | 2018-11-29 10:07:38 +0800 | [diff] [blame] | 97 | int ret; |
| 98 | |
Kever Yang | 0a2a5e1 | 2019-03-29 09:09:01 +0800 | [diff] [blame] | 99 | #ifdef CONFIG_DEBUG_UART |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 100 | /* |
| 101 | * Debug UART can be used from here if required: |
| 102 | * |
| 103 | * debug_uart_init(); |
| 104 | * printch('a'); |
| 105 | * printhex8(0x1234); |
| 106 | * printascii("string"); |
| 107 | */ |
| 108 | debug_uart_init(); |
David Wu | cee4c82 | 2019-01-02 20:50:58 +0800 | [diff] [blame] | 109 | printascii("U-Boot SPL board init"); |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 110 | #endif |
| 111 | |
Heiko Stuebner | 9cc8feb | 2018-10-08 13:01:56 +0200 | [diff] [blame] | 112 | #ifdef CONFIG_ROCKCHIP_USB_UART |
| 113 | rk_clrsetreg(&grf->uoc0_con[0], |
| 114 | SIDDQ_MASK | UOC_DISABLE_MASK | COMMON_ON_N_MASK, |
| 115 | 1 << SIDDQ_SHIFT | 1 << UOC_DISABLE_SHIFT | |
| 116 | 1 << COMMON_ON_N_SHIFT); |
| 117 | rk_clrsetreg(&grf->uoc0_con[2], |
| 118 | SOFT_CON_SEL_MASK, 1 << SOFT_CON_SEL_SHIFT); |
| 119 | rk_clrsetreg(&grf->uoc0_con[3], |
| 120 | OPMODE_MASK | XCVRSELECT_MASK | |
| 121 | TERMSEL_FULLSPEED_MASK | SUSPENDN_MASK, |
| 122 | OPMODE_NODRIVING << OPMODE_SHIFT | |
| 123 | XCVRSELECT_FSTRANSC << XCVRSELECT_SHIFT | |
| 124 | 1 << TERMSEL_FULLSPEED_SHIFT | |
| 125 | 1 << SUSPENDN_SHIFT); |
| 126 | rk_clrsetreg(&grf->uoc0_con[0], |
| 127 | BYPASSSEL_MASK | BYPASSDMEN_MASK, |
| 128 | 1 << BYPASSSEL_SHIFT | 1 << BYPASSDMEN_SHIFT); |
| 129 | #endif |
| 130 | |
Kever Yang | e603a3d | 2017-03-20 14:47:16 +0800 | [diff] [blame] | 131 | ret = spl_early_init(); |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 132 | if (ret) { |
Kever Yang | e603a3d | 2017-03-20 14:47:16 +0800 | [diff] [blame] | 133 | debug("spl_early_init() failed: %d\n", ret); |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 134 | hang(); |
| 135 | } |
| 136 | |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 137 | ret = rockchip_get_clk(&dev); |
| 138 | if (ret) { |
| 139 | debug("CLK init failed: %d\n", ret); |
| 140 | return; |
| 141 | } |
| 142 | |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 143 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 144 | if (ret) { |
| 145 | debug("DRAM init failed: %d\n", ret); |
| 146 | return; |
| 147 | } |
| 148 | |
Heiko Stübner | ba188bb | 2017-03-20 12:40:33 +0100 | [diff] [blame] | 149 | setup_arm_clock(); |
Philipp Tomsich | 798370f | 2017-06-29 11:21:15 +0200 | [diff] [blame] | 150 | #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] | 151 | back_to_bootrom(BROM_BOOT_NEXTSTAGE); |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 152 | #endif |
| 153 | } |
| 154 | |
| 155 | static int setup_led(void) |
| 156 | { |
| 157 | #ifdef CONFIG_SPL_LED |
| 158 | struct udevice *dev; |
| 159 | char *led_name; |
| 160 | int ret; |
| 161 | |
| 162 | led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led"); |
| 163 | if (!led_name) |
| 164 | return 0; |
| 165 | ret = led_get_by_label(led_name, &dev); |
| 166 | if (ret) { |
| 167 | debug("%s: get=%d\n", __func__, ret); |
| 168 | return ret; |
| 169 | } |
| 170 | ret = led_set_on(dev, 1); |
| 171 | if (ret) |
| 172 | return ret; |
| 173 | #endif |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | void spl_board_init(void) |
| 179 | { |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 180 | int ret; |
| 181 | |
| 182 | ret = setup_led(); |
| 183 | if (ret) { |
| 184 | debug("LED ret=%d\n", ret); |
| 185 | hang(); |
| 186 | } |
| 187 | |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 188 | preloader_console_init(); |
Philipp Tomsich | 798370f | 2017-06-29 11:21:15 +0200 | [diff] [blame] | 189 | #if CONFIG_IS_ENABLED(ROCKCHIP_BACK_TO_BROM) |
Philipp Tomsich | 7234c73 | 2017-10-10 16:21:16 +0200 | [diff] [blame] | 190 | back_to_bootrom(BROM_BOOT_NEXTSTAGE); |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 191 | #endif |
| 192 | return; |
Heiko Stübner | 0b3c26a | 2017-02-18 19:46:38 +0100 | [diff] [blame] | 193 | } |