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