Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2017 Rockchip Electronics Co., Ltd. |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 4 | */ |
| 5 | #include <common.h> |
| 6 | #include <clk.h> |
| 7 | #include <dm.h> |
| 8 | #include <ram.h> |
Kever Yang | f58692a | 2017-08-09 19:28:03 +0800 | [diff] [blame] | 9 | #include <syscon.h> |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 10 | #include <asm/io.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 11 | #include <asm/arch-rockchip/boot_mode.h> |
| 12 | #include <asm/arch-rockchip/clock.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 13 | #include <asm/arch-rockchip/grf_rk322x.h> |
Kever Yang | 7ce5c0f | 2019-03-29 09:09:02 +0800 | [diff] [blame] | 14 | #include <asm/arch-rockchip/periph.h> |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 18 | __weak int rk_board_late_init(void) |
| 19 | { |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | int board_late_init(void) |
| 24 | { |
| 25 | setup_boot_mode(); |
| 26 | |
| 27 | return rk_board_late_init(); |
| 28 | } |
| 29 | |
| 30 | int board_init(void) |
| 31 | { |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 32 | #include <asm/arch-rockchip/grf_rk322x.h> |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 33 | /* Enable early UART2 channel 1 on the RK322x */ |
| 34 | #define GRF_BASE 0x11000000 |
Kever Yang | 7ce5c0f | 2019-03-29 09:09:02 +0800 | [diff] [blame] | 35 | static struct rk322x_grf * const grf = (void *)GRF_BASE; |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 36 | |
David Wu | d0f8d78 | 2017-08-14 15:04:28 +0800 | [diff] [blame] | 37 | /* |
| 38 | * The integrated macphy is enabled by default, disable it |
| 39 | * for saving power consuming. |
| 40 | */ |
| 41 | rk_clrsetreg(&grf->macphy_con[0], |
| 42 | MACPHY_CFG_ENABLE_MASK, |
| 43 | 0 << MACPHY_CFG_ENABLE_SHIFT); |
| 44 | |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | int dram_init_banksize(void) |
| 49 | { |
Kever Yang | 405b2d0 | 2017-07-21 18:21:07 +0800 | [diff] [blame] | 50 | gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE; |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 51 | gd->bd->bi_dram[0].size = 0x8400000; |
Kever Yang | 405b2d0 | 2017-07-21 18:21:07 +0800 | [diff] [blame] | 52 | /* Reserve 0x200000 for OPTEE */ |
| 53 | gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE |
| 54 | + gd->bd->bi_dram[0].size + 0x200000; |
| 55 | gd->bd->bi_dram[1].size = gd->bd->bi_dram[0].start |
| 56 | + gd->ram_size - gd->bd->bi_dram[1].start; |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 61 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Kever Yang | 57d4dbf | 2017-06-23 17:17:52 +0800 | [diff] [blame] | 62 | void enable_caches(void) |
| 63 | { |
| 64 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 65 | dcache_enable(); |
| 66 | } |
| 67 | #endif |
| 68 | |
| 69 | #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) |
| 70 | #include <usb.h> |
| 71 | #include <usb/dwc2_udc.h> |
| 72 | |
| 73 | static struct dwc2_plat_otg_data rk322x_otg_data = { |
| 74 | .rx_fifo_sz = 512, |
| 75 | .np_tx_fifo_sz = 16, |
| 76 | .tx_fifo_sz = 128, |
| 77 | }; |
| 78 | |
| 79 | int board_usb_init(int index, enum usb_init_type init) |
| 80 | { |
| 81 | int node; |
| 82 | const char *mode; |
| 83 | bool matched = false; |
| 84 | const void *blob = gd->fdt_blob; |
| 85 | |
| 86 | /* find the usb_otg node */ |
| 87 | node = fdt_node_offset_by_compatible(blob, -1, |
| 88 | "rockchip,rk3288-usb"); |
| 89 | |
| 90 | while (node > 0) { |
| 91 | mode = fdt_getprop(blob, node, "dr_mode", NULL); |
| 92 | if (mode && strcmp(mode, "otg") == 0) { |
| 93 | matched = true; |
| 94 | break; |
| 95 | } |
| 96 | |
| 97 | node = fdt_node_offset_by_compatible(blob, node, |
| 98 | "rockchip,rk3288-usb"); |
| 99 | } |
| 100 | if (!matched) { |
| 101 | debug("Not found usb_otg device\n"); |
| 102 | return -ENODEV; |
| 103 | } |
| 104 | rk322x_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg"); |
| 105 | |
| 106 | return dwc2_udc_probe(&rk322x_otg_data); |
| 107 | } |
| 108 | |
| 109 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 110 | { |
| 111 | return 0; |
| 112 | } |
| 113 | #endif |
Kever Yang | f58692a | 2017-08-09 19:28:03 +0800 | [diff] [blame] | 114 | |
Alex Kiernan | 5512c43 | 2018-05-29 15:30:46 +0000 | [diff] [blame] | 115 | #if CONFIG_IS_ENABLED(FASTBOOT) |
| 116 | int fastboot_set_reboot_flag(void) |
Kever Yang | f58692a | 2017-08-09 19:28:03 +0800 | [diff] [blame] | 117 | { |
| 118 | struct rk322x_grf *grf; |
| 119 | |
| 120 | printf("Setting reboot to fastboot flag ...\n"); |
| 121 | grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); |
| 122 | /* Set boot mode to fastboot */ |
| 123 | writel(BOOT_FASTBOOT, &grf->os_reg[0]); |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | #endif |