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