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