Kever Yang | 0a2a5e1 | 2019-03-29 09:09:01 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2019 Rockchip Electronics Co., Ltd |
| 4 | */ |
| 5 | #include <common.h> |
Kever Yang | 0f9e338 | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <syscon.h> |
Kever Yang | 0a2a5e1 | 2019-03-29 09:09:01 +0800 | [diff] [blame] | 8 | #include <asm/io.h> |
Kever Yang | 60b270e | 2019-07-22 19:59:17 +0800 | [diff] [blame] | 9 | #include <asm/arch-rockchip/bootrom.h> |
Kever Yang | 0f9e338 | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 10 | #include <asm/arch-rockchip/clock.h> |
Kever Yang | 0a2a5e1 | 2019-03-29 09:09:01 +0800 | [diff] [blame] | 11 | #include <asm/arch-rockchip/grf_rk3188.h> |
| 12 | #include <asm/arch-rockchip/hardware.h> |
| 13 | |
Kever Yang | 8fd6019 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 14 | #define GRF_BASE 0x20008000 |
| 15 | |
Kever Yang | 60b270e | 2019-07-22 19:59:17 +0800 | [diff] [blame] | 16 | const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
| 17 | [BROM_BOOTSOURCE_EMMC] = "dwmmc@1021c000", |
| 18 | [BROM_BOOTSOURCE_SD] = "dwmmc@10214000", |
| 19 | }; |
| 20 | |
Kever Yang | 0a2a5e1 | 2019-03-29 09:09:01 +0800 | [diff] [blame] | 21 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 22 | void board_debug_uart_init(void) |
| 23 | { |
| 24 | /* Enable early UART on the RK3188 */ |
Kever Yang | 0a2a5e1 | 2019-03-29 09:09:01 +0800 | [diff] [blame] | 25 | struct rk3188_grf * const grf = (void *)GRF_BASE; |
| 26 | enum { |
| 27 | GPIO1B1_SHIFT = 2, |
| 28 | GPIO1B1_MASK = 3, |
| 29 | GPIO1B1_GPIO = 0, |
| 30 | GPIO1B1_UART2_SOUT, |
| 31 | GPIO1B1_JTAG_TDO, |
| 32 | |
| 33 | GPIO1B0_SHIFT = 0, |
| 34 | GPIO1B0_MASK = 3, |
| 35 | GPIO1B0_GPIO = 0, |
| 36 | GPIO1B0_UART2_SIN, |
| 37 | GPIO1B0_JTAG_TDI, |
| 38 | }; |
| 39 | |
| 40 | rk_clrsetreg(&grf->gpio1b_iomux, |
| 41 | GPIO1B1_MASK << GPIO1B1_SHIFT | |
| 42 | GPIO1B0_MASK << GPIO1B0_SHIFT, |
| 43 | GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT | |
| 44 | GPIO1B0_UART2_SIN << GPIO1B0_SHIFT); |
| 45 | } |
| 46 | #endif |
Kever Yang | 8fd6019 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 47 | |
Kever Yang | 0f9e338 | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 48 | #ifdef CONFIG_SPL_BUILD |
Kever Yang | 8fd6019 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 49 | int arch_cpu_init(void) |
| 50 | { |
Kever Yang | 0f9e338 | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 51 | struct rk3188_grf *grf; |
Kever Yang | 8fd6019 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 52 | |
Kever Yang | 0f9e338 | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 53 | grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); |
| 54 | if (IS_ERR(grf)) { |
| 55 | pr_err("grf syscon returned %ld\n", PTR_ERR(grf)); |
| 56 | return 0; |
| 57 | } |
| 58 | #ifdef CONFIG_ROCKCHIP_USB_UART |
Kever Yang | 8fd6019 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 59 | rk_clrsetreg(&grf->uoc0_con[0], |
| 60 | SIDDQ_MASK | UOC_DISABLE_MASK | COMMON_ON_N_MASK, |
| 61 | 1 << SIDDQ_SHIFT | 1 << UOC_DISABLE_SHIFT | |
| 62 | 1 << COMMON_ON_N_SHIFT); |
| 63 | rk_clrsetreg(&grf->uoc0_con[2], |
| 64 | SOFT_CON_SEL_MASK, 1 << SOFT_CON_SEL_SHIFT); |
| 65 | rk_clrsetreg(&grf->uoc0_con[3], |
| 66 | OPMODE_MASK | XCVRSELECT_MASK | |
| 67 | TERMSEL_FULLSPEED_MASK | SUSPENDN_MASK, |
| 68 | OPMODE_NODRIVING << OPMODE_SHIFT | |
| 69 | XCVRSELECT_FSTRANSC << XCVRSELECT_SHIFT | |
| 70 | 1 << TERMSEL_FULLSPEED_SHIFT | |
| 71 | 1 << SUSPENDN_SHIFT); |
| 72 | rk_clrsetreg(&grf->uoc0_con[0], |
| 73 | BYPASSSEL_MASK | BYPASSDMEN_MASK, |
| 74 | 1 << BYPASSSEL_SHIFT | 1 << BYPASSDMEN_SHIFT); |
| 75 | #endif |
Kever Yang | 0f9e338 | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 76 | |
| 77 | /* enable noc remap to mimic legacy loaders */ |
| 78 | rk_clrsetreg(&grf->soc_con0, |
| 79 | NOC_REMAP_MASK << NOC_REMAP_SHIFT, |
| 80 | NOC_REMAP_MASK << NOC_REMAP_SHIFT); |
| 81 | |
Kever Yang | 8fd6019 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 82 | return 0; |
| 83 | } |
Kever Yang | 0f9e338 | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 84 | #endif |
Kever Yang | 96bf25a | 2019-07-22 19:59:16 +0800 | [diff] [blame] | 85 | |
| 86 | #ifdef CONFIG_SPL_BUILD |
| 87 | static int setup_led(void) |
| 88 | { |
| 89 | #ifdef CONFIG_SPL_LED |
| 90 | struct udevice *dev; |
| 91 | char *led_name; |
| 92 | int ret; |
| 93 | |
| 94 | led_name = fdtdec_get_config_string(gd->fdt_blob, "u-boot,boot-led"); |
| 95 | if (!led_name) |
| 96 | return 0; |
| 97 | ret = led_get_by_label(led_name, &dev); |
| 98 | if (ret) { |
| 99 | debug("%s: get=%d\n", __func__, ret); |
| 100 | return ret; |
| 101 | } |
| 102 | ret = led_set_on(dev, 1); |
| 103 | if (ret) |
| 104 | return ret; |
| 105 | #endif |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | void spl_board_init(void) |
| 111 | { |
| 112 | int ret; |
| 113 | |
| 114 | ret = setup_led(); |
| 115 | if (ret) { |
| 116 | debug("LED ret=%d\n", ret); |
| 117 | hang(); |
| 118 | } |
| 119 | } |
| 120 | #endif |