Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jacob Chen | 746070c | 2016-09-19 18:46:27 +0800 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Rockchip Electronics Co., Ltd |
Jacob Chen | 746070c | 2016-09-19 18:46:27 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <clk.h> |
| 8 | #include <dm.h> |
| 9 | #include <ram.h> |
Simon Glass | f473eba | 2019-01-21 14:53:31 -0700 | [diff] [blame] | 10 | #include <asm/gpio.h> |
Jacob Chen | 746070c | 2016-09-19 18:46:27 +0800 | [diff] [blame] | 11 | #include <asm/io.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 12 | #include <asm/arch-rockchip/clock.h> |
| 13 | #include <asm/arch-rockchip/periph.h> |
| 14 | #include <asm/arch-rockchip/grf_rk3036.h> |
| 15 | #include <asm/arch-rockchip/boot_mode.h> |
| 16 | #include <asm/arch-rockchip/sdram_rk3036.h> |
Jacob Chen | 746070c | 2016-09-19 18:46:27 +0800 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Jacob Chen | c95f378 | 2016-09-19 18:46:28 +0800 | [diff] [blame] | 20 | __weak int rk_board_late_init(void) |
| 21 | { |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | int board_late_init(void) |
| 26 | { |
| 27 | setup_boot_mode(); |
| 28 | |
| 29 | return rk_board_late_init(); |
| 30 | } |
| 31 | |
Jacob Chen | 746070c | 2016-09-19 18:46:27 +0800 | [diff] [blame] | 32 | int board_init(void) |
| 33 | { |
| 34 | return 0; |
| 35 | } |
| 36 | |
Kever Yang | 6c15a54 | 2017-06-23 16:11:06 +0800 | [diff] [blame] | 37 | #if !CONFIG_IS_ENABLED(RAM) |
| 38 | /* |
| 39 | * When CONFIG_RAM is enabled, the dram_init() function is implemented |
| 40 | * in sdram_common.c. |
| 41 | */ |
Jacob Chen | 746070c | 2016-09-19 18:46:27 +0800 | [diff] [blame] | 42 | int dram_init(void) |
| 43 | { |
| 44 | gd->ram_size = sdram_size(); |
| 45 | |
| 46 | return 0; |
| 47 | } |
Kever Yang | 6c15a54 | 2017-06-23 16:11:06 +0800 | [diff] [blame] | 48 | #endif |
Jacob Chen | 746070c | 2016-09-19 18:46:27 +0800 | [diff] [blame] | 49 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 50 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Jacob Chen | 746070c | 2016-09-19 18:46:27 +0800 | [diff] [blame] | 51 | void enable_caches(void) |
| 52 | { |
| 53 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 54 | dcache_enable(); |
| 55 | } |
| 56 | #endif |
| 57 | |
| 58 | #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) |
| 59 | #include <usb.h> |
| 60 | #include <usb/dwc2_udc.h> |
| 61 | |
| 62 | static struct dwc2_plat_otg_data rk3036_otg_data = { |
| 63 | .rx_fifo_sz = 512, |
| 64 | .np_tx_fifo_sz = 16, |
| 65 | .tx_fifo_sz = 128, |
| 66 | }; |
| 67 | |
| 68 | int board_usb_init(int index, enum usb_init_type init) |
| 69 | { |
| 70 | int node; |
| 71 | const char *mode; |
| 72 | bool matched = false; |
| 73 | const void *blob = gd->fdt_blob; |
| 74 | |
| 75 | /* find the usb_otg node */ |
| 76 | node = fdt_node_offset_by_compatible(blob, -1, |
| 77 | "rockchip,rk3288-usb"); |
| 78 | |
| 79 | while (node > 0) { |
| 80 | mode = fdt_getprop(blob, node, "dr_mode", NULL); |
| 81 | if (mode && strcmp(mode, "otg") == 0) { |
| 82 | matched = true; |
| 83 | break; |
| 84 | } |
| 85 | |
| 86 | node = fdt_node_offset_by_compatible(blob, node, |
| 87 | "rockchip,rk3288-usb"); |
| 88 | } |
| 89 | if (!matched) { |
| 90 | debug("Not found usb_otg device\n"); |
| 91 | return -ENODEV; |
| 92 | } |
| 93 | rk3036_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg"); |
| 94 | |
| 95 | return dwc2_udc_probe(&rk3036_otg_data); |
| 96 | } |
| 97 | |
| 98 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 99 | { |
| 100 | return 0; |
| 101 | } |
| 102 | #endif |