Kever Yang | 86d0eca | 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 | c14fe2a | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 6 | #include <dm.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 7 | #include <hang.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Kever Yang | e2f8ba8 | 2020-08-20 17:31:16 +0800 | [diff] [blame] | 9 | #include <led.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Kever Yang | c14fe2a | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 11 | #include <syscon.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Kever Yang | 86d0eca | 2019-03-29 09:09:01 +0800 | [diff] [blame] | 13 | #include <asm/io.h> |
Kever Yang | 3b3c623 | 2019-07-22 19:59:17 +0800 | [diff] [blame] | 14 | #include <asm/arch-rockchip/bootrom.h> |
Kever Yang | c14fe2a | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 15 | #include <asm/arch-rockchip/clock.h> |
Kever Yang | 86d0eca | 2019-03-29 09:09:01 +0800 | [diff] [blame] | 16 | #include <asm/arch-rockchip/grf_rk3188.h> |
| 17 | #include <asm/arch-rockchip/hardware.h> |
Simon Glass | 7de8bd0 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 18 | #include <dm/ofnode.h> |
Simon Glass | 61b29b8 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 19 | #include <linux/err.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame^] | 20 | #include <linux/printk.h> |
Kever Yang | 86d0eca | 2019-03-29 09:09:01 +0800 | [diff] [blame] | 21 | |
Kever Yang | 4dd4fc3 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 22 | #define GRF_BASE 0x20008000 |
| 23 | |
Kever Yang | 3b3c623 | 2019-07-22 19:59:17 +0800 | [diff] [blame] | 24 | const char * const boot_devices[BROM_LAST_BOOTSOURCE + 1] = { |
Johan Jonker | 5859bb2 | 2022-04-15 23:21:43 +0200 | [diff] [blame] | 25 | [BROM_BOOTSOURCE_EMMC] = "/mmc@1021c000", |
| 26 | [BROM_BOOTSOURCE_SD] = "/mmc@10214000", |
Kever Yang | 3b3c623 | 2019-07-22 19:59:17 +0800 | [diff] [blame] | 27 | }; |
| 28 | |
Kever Yang | 86d0eca | 2019-03-29 09:09:01 +0800 | [diff] [blame] | 29 | #ifdef CONFIG_DEBUG_UART_BOARD_INIT |
| 30 | void board_debug_uart_init(void) |
| 31 | { |
| 32 | /* Enable early UART on the RK3188 */ |
Kever Yang | 86d0eca | 2019-03-29 09:09:01 +0800 | [diff] [blame] | 33 | struct rk3188_grf * const grf = (void *)GRF_BASE; |
| 34 | enum { |
| 35 | GPIO1B1_SHIFT = 2, |
| 36 | GPIO1B1_MASK = 3, |
| 37 | GPIO1B1_GPIO = 0, |
| 38 | GPIO1B1_UART2_SOUT, |
| 39 | GPIO1B1_JTAG_TDO, |
| 40 | |
| 41 | GPIO1B0_SHIFT = 0, |
| 42 | GPIO1B0_MASK = 3, |
| 43 | GPIO1B0_GPIO = 0, |
| 44 | GPIO1B0_UART2_SIN, |
| 45 | GPIO1B0_JTAG_TDI, |
| 46 | }; |
| 47 | |
| 48 | rk_clrsetreg(&grf->gpio1b_iomux, |
| 49 | GPIO1B1_MASK << GPIO1B1_SHIFT | |
| 50 | GPIO1B0_MASK << GPIO1B0_SHIFT, |
| 51 | GPIO1B1_UART2_SOUT << GPIO1B1_SHIFT | |
| 52 | GPIO1B0_UART2_SIN << GPIO1B0_SHIFT); |
| 53 | } |
| 54 | #endif |
Kever Yang | 4dd4fc3 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 55 | |
Kever Yang | c14fe2a | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 56 | #ifdef CONFIG_SPL_BUILD |
Kever Yang | 4dd4fc3 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 57 | int arch_cpu_init(void) |
| 58 | { |
Kever Yang | c14fe2a | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 59 | struct rk3188_grf *grf; |
Kever Yang | 4dd4fc3 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 60 | |
Kever Yang | c14fe2a | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 61 | grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); |
| 62 | if (IS_ERR(grf)) { |
| 63 | pr_err("grf syscon returned %ld\n", PTR_ERR(grf)); |
| 64 | return 0; |
| 65 | } |
| 66 | #ifdef CONFIG_ROCKCHIP_USB_UART |
Kever Yang | 4dd4fc3 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 67 | rk_clrsetreg(&grf->uoc0_con[0], |
| 68 | SIDDQ_MASK | UOC_DISABLE_MASK | COMMON_ON_N_MASK, |
| 69 | 1 << SIDDQ_SHIFT | 1 << UOC_DISABLE_SHIFT | |
| 70 | 1 << COMMON_ON_N_SHIFT); |
| 71 | rk_clrsetreg(&grf->uoc0_con[2], |
| 72 | SOFT_CON_SEL_MASK, 1 << SOFT_CON_SEL_SHIFT); |
| 73 | rk_clrsetreg(&grf->uoc0_con[3], |
| 74 | OPMODE_MASK | XCVRSELECT_MASK | |
| 75 | TERMSEL_FULLSPEED_MASK | SUSPENDN_MASK, |
| 76 | OPMODE_NODRIVING << OPMODE_SHIFT | |
| 77 | XCVRSELECT_FSTRANSC << XCVRSELECT_SHIFT | |
| 78 | 1 << TERMSEL_FULLSPEED_SHIFT | |
| 79 | 1 << SUSPENDN_SHIFT); |
| 80 | rk_clrsetreg(&grf->uoc0_con[0], |
| 81 | BYPASSSEL_MASK | BYPASSDMEN_MASK, |
| 82 | 1 << BYPASSSEL_SHIFT | 1 << BYPASSDMEN_SHIFT); |
| 83 | #endif |
Alexander Kochetkov | a2b1cff | 2020-06-22 16:19:25 +0300 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | __weak int rk3188_board_late_init(void) |
| 89 | { |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | int rk_board_late_init(void) |
| 94 | { |
| 95 | struct rk3188_grf *grf; |
| 96 | |
| 97 | grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); |
| 98 | if (IS_ERR(grf)) { |
| 99 | pr_err("grf syscon returned %ld\n", PTR_ERR(grf)); |
| 100 | return 0; |
| 101 | } |
Kever Yang | c14fe2a | 2019-07-22 20:02:08 +0800 | [diff] [blame] | 102 | |
| 103 | /* enable noc remap to mimic legacy loaders */ |
| 104 | rk_clrsetreg(&grf->soc_con0, |
| 105 | NOC_REMAP_MASK << NOC_REMAP_SHIFT, |
| 106 | NOC_REMAP_MASK << NOC_REMAP_SHIFT); |
| 107 | |
Alexander Kochetkov | a2b1cff | 2020-06-22 16:19:25 +0300 | [diff] [blame] | 108 | return rk3188_board_late_init(); |
Kever Yang | 4dd4fc3 | 2019-07-22 19:59:14 +0800 | [diff] [blame] | 109 | } |
Kever Yang | 9323ffa | 2019-07-22 19:59:16 +0800 | [diff] [blame] | 110 | |
| 111 | #ifdef CONFIG_SPL_BUILD |
| 112 | static int setup_led(void) |
| 113 | { |
| 114 | #ifdef CONFIG_SPL_LED |
| 115 | struct udevice *dev; |
| 116 | char *led_name; |
| 117 | int ret; |
| 118 | |
Simon Glass | 7de8bd0 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 119 | led_name = ofnode_conf_read_str("u-boot,boot-led"); |
Kever Yang | 9323ffa | 2019-07-22 19:59:16 +0800 | [diff] [blame] | 120 | if (!led_name) |
| 121 | return 0; |
| 122 | ret = led_get_by_label(led_name, &dev); |
| 123 | if (ret) { |
| 124 | debug("%s: get=%d\n", __func__, ret); |
| 125 | return ret; |
| 126 | } |
Kever Yang | e2f8ba8 | 2020-08-20 17:31:16 +0800 | [diff] [blame] | 127 | ret = led_set_state(dev, LEDST_ON); |
Kever Yang | 9323ffa | 2019-07-22 19:59:16 +0800 | [diff] [blame] | 128 | if (ret) |
| 129 | return ret; |
| 130 | #endif |
| 131 | |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | void spl_board_init(void) |
| 136 | { |
| 137 | int ret; |
| 138 | |
| 139 | ret = setup_led(); |
| 140 | if (ret) { |
| 141 | debug("LED ret=%d\n", ret); |
| 142 | hang(); |
| 143 | } |
| 144 | } |
| 145 | #endif |