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