1 /* 2 * (C) Copyright 2016 Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <asm/arch/hardware.h> 9 #include <asm/arch/grf_rk3328.h> 10 #include <asm/armv8/mmu.h> 11 #include <asm/io.h> 12 #include <dwc3-uboot.h> 13 #include <power/regulator.h> 14 #include <usb.h> 15 16 DECLARE_GLOBAL_DATA_PTR; 17 18 int board_init(void) 19 { 20 int ret; 21 #define GRF_BASE 0xff100000 22 struct rk3328_grf_regs * const grf = (void *)GRF_BASE; 23 24 /* uart2 select m1, sdcard select m1*/ 25 rk_clrsetreg(&grf->com_iomux, 26 IOMUX_SEL_UART2_MASK | IOMUX_SEL_SDMMC_MASK, 27 IOMUX_SEL_UART2_M1 << IOMUX_SEL_UART2_SHIFT | 28 IOMUX_SEL_SDMMC_M1 << IOMUX_SEL_SDMMC_SHIFT); 29 30 ret = regulators_enable_boot_on(false); 31 if (ret) 32 debug("%s: Cannot enable boot on regulator\n", __func__); 33 34 return ret; 35 } 36 37 #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) 38 #include <usb.h> 39 #include <usb/dwc2_udc.h> 40 41 static struct dwc2_plat_otg_data rk3328_otg_data = { 42 .rx_fifo_sz = 512, 43 .np_tx_fifo_sz = 16, 44 .tx_fifo_sz = 128, 45 }; 46 47 int board_usb_init(int index, enum usb_init_type init) 48 { 49 int node; 50 const char *mode; 51 bool matched = false; 52 const void *blob = gd->fdt_blob; 53 54 /* find the usb_otg node */ 55 node = fdt_node_offset_by_compatible(blob, -1, 56 "rockchip,rk3328-usb"); 57 58 while (node > 0) { 59 mode = fdt_getprop(blob, node, "dr_mode", NULL); 60 if (mode && strcmp(mode, "otg") == 0) { 61 matched = true; 62 break; 63 } 64 65 node = fdt_node_offset_by_compatible(blob, node, 66 "rockchip,rk3328-usb"); 67 } 68 if (!matched) { 69 debug("Not found usb_otg device\n"); 70 return -ENODEV; 71 } 72 73 rk3328_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg"); 74 75 return dwc2_udc_probe(&rk3328_otg_data); 76 } 77 78 int board_usb_cleanup(int index, enum usb_init_type init) 79 { 80 return 0; 81 } 82 #endif 83