Kever Yang | bb33773 | 2019-07-22 20:02: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> |
| 6 | #include <clk.h> |
| 7 | #include <dm.h> |
| 8 | #include <ram.h> |
| 9 | #include <syscon.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/arch-rockchip/boot_mode.h> |
| 12 | #include <asm/arch-rockchip/clock.h> |
| 13 | #include <asm/arch-rockchip/periph.h> |
Rohan Garg | cfdc192 | 2019-08-12 17:04:34 +0200 | [diff] [blame] | 14 | #include <asm/arch-rockchip/misc.h> |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 15 | #include <power/regulator.h> |
| 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
| 19 | __weak int rk_board_late_init(void) |
| 20 | { |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | int board_late_init(void) |
| 25 | { |
| 26 | setup_boot_mode(); |
| 27 | |
| 28 | return rk_board_late_init(); |
| 29 | } |
| 30 | |
| 31 | int board_init(void) |
| 32 | { |
| 33 | int ret; |
| 34 | |
| 35 | #ifdef CONFIG_DM_REGULATOR |
| 36 | ret = regulators_enable_boot_on(false); |
| 37 | if (ret) |
| 38 | debug("%s: Cannot enable boot on regulator\n", __func__); |
| 39 | #endif |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | #if !defined(CONFIG_SYS_DCACHE_OFF) && !defined(CONFIG_ARM64) |
| 45 | void enable_caches(void) |
| 46 | { |
| 47 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 48 | dcache_enable(); |
| 49 | } |
| 50 | #endif |
| 51 | |
| 52 | #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) |
| 53 | #include <usb.h> |
| 54 | #include <usb/dwc2_udc.h> |
| 55 | |
| 56 | static struct dwc2_plat_otg_data otg_data = { |
| 57 | .rx_fifo_sz = 512, |
| 58 | .np_tx_fifo_sz = 16, |
| 59 | .tx_fifo_sz = 128, |
| 60 | }; |
| 61 | |
| 62 | int board_usb_init(int index, enum usb_init_type init) |
| 63 | { |
Kever Yang | 45bda03 | 2019-10-16 17:13:31 +0800 | [diff] [blame^] | 64 | ofnode node; |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 65 | const char *mode; |
| 66 | bool matched = false; |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 67 | |
| 68 | /* find the usb_otg node */ |
Kever Yang | 45bda03 | 2019-10-16 17:13:31 +0800 | [diff] [blame^] | 69 | node = ofnode_by_compatible(ofnode_null(), "snps,dwc2"); |
| 70 | while (ofnode_valid(node)) { |
| 71 | mode = ofnode_read_string(node, "dr_mode"); |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 72 | if (mode && strcmp(mode, "otg") == 0) { |
| 73 | matched = true; |
| 74 | break; |
| 75 | } |
| 76 | |
Kever Yang | 45bda03 | 2019-10-16 17:13:31 +0800 | [diff] [blame^] | 77 | node = ofnode_by_compatible(node, "snps,dwc2"); |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 78 | } |
| 79 | if (!matched) { |
| 80 | debug("Not found usb_otg device\n"); |
| 81 | return -ENODEV; |
| 82 | } |
Kever Yang | 45bda03 | 2019-10-16 17:13:31 +0800 | [diff] [blame^] | 83 | otg_data.regs_otg = ofnode_get_addr(node); |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 84 | |
| 85 | return dwc2_udc_probe(&otg_data); |
| 86 | } |
| 87 | |
| 88 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 89 | { |
| 90 | return 0; |
| 91 | } |
| 92 | #endif |
| 93 | |
| 94 | #if CONFIG_IS_ENABLED(FASTBOOT) |
| 95 | int fastboot_set_reboot_flag(void) |
| 96 | { |
| 97 | printf("Setting reboot to fastboot flag ...\n"); |
| 98 | /* Set boot mode to fastboot */ |
| 99 | writel(BOOT_FASTBOOT, CONFIG_ROCKCHIP_BOOT_MODE_REG); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | #endif |
Rohan Garg | cfdc192 | 2019-08-12 17:04:34 +0200 | [diff] [blame] | 104 | |
| 105 | #ifdef CONFIG_MISC_INIT_R |
| 106 | __weak int misc_init_r(void) |
| 107 | { |
| 108 | const u32 cpuid_offset = 0x7; |
| 109 | const u32 cpuid_length = 0x10; |
| 110 | u8 cpuid[cpuid_length]; |
| 111 | int ret; |
| 112 | |
| 113 | ret = rockchip_cpuid_from_efuse(cpuid_offset, cpuid_length, cpuid); |
| 114 | if (ret) |
| 115 | return ret; |
| 116 | |
| 117 | ret = rockchip_cpuid_set(cpuid, cpuid_length); |
| 118 | if (ret) |
| 119 | return ret; |
| 120 | |
| 121 | ret = rockchip_setup_macaddr(); |
| 122 | |
| 123 | return ret; |
| 124 | } |
| 125 | #endif |