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> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 7 | #include <cpu_func.h> |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <ram.h> |
| 10 | #include <syscon.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/arch-rockchip/boot_mode.h> |
| 13 | #include <asm/arch-rockchip/clock.h> |
| 14 | #include <asm/arch-rockchip/periph.h> |
Rohan Garg | cfdc192 | 2019-08-12 17:04:34 +0200 | [diff] [blame] | 15 | #include <asm/arch-rockchip/misc.h> |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 16 | #include <power/regulator.h> |
| 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
| 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 | |
| 32 | int board_init(void) |
| 33 | { |
| 34 | int ret; |
| 35 | |
| 36 | #ifdef CONFIG_DM_REGULATOR |
| 37 | ret = regulators_enable_boot_on(false); |
| 38 | if (ret) |
| 39 | debug("%s: Cannot enable boot on regulator\n", __func__); |
| 40 | #endif |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | #if !defined(CONFIG_SYS_DCACHE_OFF) && !defined(CONFIG_ARM64) |
| 46 | void enable_caches(void) |
| 47 | { |
| 48 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 49 | dcache_enable(); |
| 50 | } |
| 51 | #endif |
| 52 | |
Jagan Teki | 886ecb2 | 2019-11-19 13:56:22 +0530 | [diff] [blame] | 53 | #if defined(CONFIG_USB_GADGET) |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 54 | #include <usb.h> |
Jagan Teki | 886ecb2 | 2019-11-19 13:56:22 +0530 | [diff] [blame] | 55 | |
| 56 | #if defined(CONFIG_USB_GADGET_DWC2_OTG) |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 57 | #include <usb/dwc2_udc.h> |
| 58 | |
| 59 | static struct dwc2_plat_otg_data otg_data = { |
| 60 | .rx_fifo_sz = 512, |
| 61 | .np_tx_fifo_sz = 16, |
| 62 | .tx_fifo_sz = 128, |
| 63 | }; |
| 64 | |
| 65 | int board_usb_init(int index, enum usb_init_type init) |
| 66 | { |
Kever Yang | 45bda03 | 2019-10-16 17:13:31 +0800 | [diff] [blame] | 67 | ofnode node; |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 68 | const char *mode; |
| 69 | bool matched = false; |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 70 | |
| 71 | /* find the usb_otg node */ |
Kever Yang | 45bda03 | 2019-10-16 17:13:31 +0800 | [diff] [blame] | 72 | node = ofnode_by_compatible(ofnode_null(), "snps,dwc2"); |
| 73 | while (ofnode_valid(node)) { |
| 74 | mode = ofnode_read_string(node, "dr_mode"); |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 75 | if (mode && strcmp(mode, "otg") == 0) { |
| 76 | matched = true; |
| 77 | break; |
| 78 | } |
| 79 | |
Kever Yang | 45bda03 | 2019-10-16 17:13:31 +0800 | [diff] [blame] | 80 | node = ofnode_by_compatible(node, "snps,dwc2"); |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 81 | } |
| 82 | if (!matched) { |
| 83 | debug("Not found usb_otg device\n"); |
| 84 | return -ENODEV; |
| 85 | } |
Kever Yang | 45bda03 | 2019-10-16 17:13:31 +0800 | [diff] [blame] | 86 | otg_data.regs_otg = ofnode_get_addr(node); |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 87 | |
Kever Yang | 6169a0d | 2019-10-16 17:13:32 +0800 | [diff] [blame] | 88 | #ifdef CONFIG_ROCKCHIP_RK3288 |
| 89 | int ret; |
| 90 | u32 phandle, offset; |
| 91 | ofnode phy_node; |
| 92 | |
| 93 | ret = ofnode_read_u32(node, "phys", &phandle); |
| 94 | if (ret) |
| 95 | return ret; |
| 96 | |
| 97 | node = ofnode_get_by_phandle(phandle); |
| 98 | if (!ofnode_valid(node)) { |
| 99 | debug("Not found usb phy device\n"); |
| 100 | return -ENODEV; |
| 101 | } |
| 102 | |
| 103 | phy_node = ofnode_get_parent(node); |
| 104 | if (!ofnode_valid(node)) { |
| 105 | debug("Not found usb phy device\n"); |
| 106 | return -ENODEV; |
| 107 | } |
| 108 | |
| 109 | otg_data.phy_of_node = phy_node; |
| 110 | ret = ofnode_read_u32(node, "reg", &offset); |
| 111 | if (ret) |
| 112 | return ret; |
| 113 | otg_data.regs_phy = offset + |
| 114 | (u32)syscon_get_first_range(ROCKCHIP_SYSCON_GRF); |
| 115 | #endif |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 116 | return dwc2_udc_probe(&otg_data); |
| 117 | } |
| 118 | |
| 119 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 120 | { |
| 121 | return 0; |
| 122 | } |
Jagan Teki | 886ecb2 | 2019-11-19 13:56:22 +0530 | [diff] [blame] | 123 | #endif /* CONFIG_USB_GADGET_DWC2_OTG */ |
| 124 | |
| 125 | #if defined(CONFIG_USB_DWC3_GADGET) && !defined(CONFIG_DM_USB_GADGET) |
| 126 | #include <dwc3-uboot.h> |
| 127 | |
| 128 | static struct dwc3_device dwc3_device_data = { |
| 129 | .maximum_speed = USB_SPEED_HIGH, |
| 130 | .base = 0xfe800000, |
| 131 | .dr_mode = USB_DR_MODE_PERIPHERAL, |
| 132 | .index = 0, |
| 133 | .dis_u2_susphy_quirk = 1, |
| 134 | .hsphy_mode = USBPHY_INTERFACE_MODE_UTMIW, |
| 135 | }; |
| 136 | |
| 137 | int usb_gadget_handle_interrupts(void) |
| 138 | { |
| 139 | dwc3_uboot_handle_interrupt(0); |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | int board_usb_init(int index, enum usb_init_type init) |
| 144 | { |
| 145 | return dwc3_uboot_init(&dwc3_device_data); |
| 146 | } |
| 147 | #endif /* CONFIG_USB_DWC3_GADGET */ |
| 148 | |
| 149 | #endif /* CONFIG_USB_GADGET */ |
Kever Yang | bb33773 | 2019-07-22 20:02:01 +0800 | [diff] [blame] | 150 | |
| 151 | #if CONFIG_IS_ENABLED(FASTBOOT) |
| 152 | int fastboot_set_reboot_flag(void) |
| 153 | { |
| 154 | printf("Setting reboot to fastboot flag ...\n"); |
| 155 | /* Set boot mode to fastboot */ |
| 156 | writel(BOOT_FASTBOOT, CONFIG_ROCKCHIP_BOOT_MODE_REG); |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | #endif |
Rohan Garg | cfdc192 | 2019-08-12 17:04:34 +0200 | [diff] [blame] | 161 | |
| 162 | #ifdef CONFIG_MISC_INIT_R |
| 163 | __weak int misc_init_r(void) |
| 164 | { |
| 165 | const u32 cpuid_offset = 0x7; |
| 166 | const u32 cpuid_length = 0x10; |
| 167 | u8 cpuid[cpuid_length]; |
| 168 | int ret; |
| 169 | |
| 170 | ret = rockchip_cpuid_from_efuse(cpuid_offset, cpuid_length, cpuid); |
| 171 | if (ret) |
| 172 | return ret; |
| 173 | |
| 174 | ret = rockchip_cpuid_set(cpuid, cpuid_length); |
| 175 | if (ret) |
| 176 | return ret; |
| 177 | |
| 178 | ret = rockchip_setup_macaddr(); |
| 179 | |
| 180 | return ret; |
| 181 | } |
| 182 | #endif |