1 /* 2 * (C) Copyright 2015 Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <clk.h> 9 #include <dm.h> 10 #include <ram.h> 11 #include <asm/io.h> 12 #include <asm/arch/clock.h> 13 #include <asm/arch/periph.h> 14 #include <asm/arch/grf_rk3036.h> 15 #include <asm/arch/boot_mode.h> 16 #include <asm/arch/sdram_rk3036.h> 17 #include <asm/gpio.h> 18 #include <dm/pinctrl.h> 19 20 DECLARE_GLOBAL_DATA_PTR; 21 22 #define GRF_BASE 0x20008000 23 24 static void setup_boot_mode(void) 25 { 26 struct rk3036_grf *const grf = (void *)GRF_BASE; 27 int boot_mode = readl(&grf->os_reg[4]); 28 29 debug("boot mode %x.\n", boot_mode); 30 31 /* Clear boot mode */ 32 writel(BOOT_NORMAL, &grf->os_reg[4]); 33 34 switch (boot_mode) { 35 case BOOT_FASTBOOT: 36 printf("enter fastboot!\n"); 37 setenv("preboot", "setenv preboot; fastboot usb0"); 38 break; 39 case BOOT_UMS: 40 printf("enter UMS!\n"); 41 setenv("preboot", "setenv preboot; ums mmc 0"); 42 break; 43 } 44 } 45 46 __weak int rk_board_late_init(void) 47 { 48 return 0; 49 } 50 51 int board_late_init(void) 52 { 53 setup_boot_mode(); 54 55 return rk_board_late_init(); 56 } 57 58 int board_init(void) 59 { 60 return 0; 61 } 62 63 int dram_init(void) 64 { 65 gd->ram_size = sdram_size(); 66 67 return 0; 68 } 69 70 #ifndef CONFIG_SYS_DCACHE_OFF 71 void enable_caches(void) 72 { 73 /* Enable D-cache. I-cache is already enabled in start.S */ 74 dcache_enable(); 75 } 76 #endif 77 78 #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) 79 #include <usb.h> 80 #include <usb/dwc2_udc.h> 81 82 static struct dwc2_plat_otg_data rk3036_otg_data = { 83 .rx_fifo_sz = 512, 84 .np_tx_fifo_sz = 16, 85 .tx_fifo_sz = 128, 86 }; 87 88 int board_usb_init(int index, enum usb_init_type init) 89 { 90 int node; 91 const char *mode; 92 bool matched = false; 93 const void *blob = gd->fdt_blob; 94 95 /* find the usb_otg node */ 96 node = fdt_node_offset_by_compatible(blob, -1, 97 "rockchip,rk3288-usb"); 98 99 while (node > 0) { 100 mode = fdt_getprop(blob, node, "dr_mode", NULL); 101 if (mode && strcmp(mode, "otg") == 0) { 102 matched = true; 103 break; 104 } 105 106 node = fdt_node_offset_by_compatible(blob, node, 107 "rockchip,rk3288-usb"); 108 } 109 if (!matched) { 110 debug("Not found usb_otg device\n"); 111 return -ENODEV; 112 } 113 rk3036_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg"); 114 115 return dwc2_udc_probe(&rk3036_otg_data); 116 } 117 118 int board_usb_cleanup(int index, enum usb_init_type init) 119 { 120 return 0; 121 } 122 #endif 123