xref: /rk3399_rockchip-uboot/arch/arm/mach-rockchip/board.c (revision 8dd9db5d1cd5826638c3cdb5f681300ff2f29f3b)
1 /*
2  * (C) Copyright 2017 Rockchip Electronics Co., Ltd.
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 #include <common.h>
7 #include <amp.h>
8 #include <clk.h>
9 #include <bidram.h>
10 #include <dm.h>
11 #include <debug_uart.h>
12 #include <key.h>
13 #include <memblk.h>
14 #include <ram.h>
15 #include <syscon.h>
16 #include <sysmem.h>
17 #include <asm/io.h>
18 #include <asm/arch/vendor.h>
19 #include <misc.h>
20 #include <asm/gpio.h>
21 #include <dm/uclass-internal.h>
22 #include <asm/arch/clock.h>
23 #include <asm/arch/cpu.h>
24 #include <asm/arch/periph.h>
25 #include <asm/arch/boot_mode.h>
26 #include <asm/arch/hotkey.h>
27 #include <asm/arch/rk_atags.h>
28 #include <asm/arch/param.h>
29 #ifdef CONFIG_DM_CHARGE_DISPLAY
30 #include <power/charge_display.h>
31 #endif
32 #ifdef CONFIG_DM_DVFS
33 #include <dvfs.h>
34 #endif
35 #ifdef CONFIG_ROCKCHIP_IO_DOMAIN
36 #include <io-domain.h>
37 #endif
38 #ifdef CONFIG_DM_REGULATOR
39 #include <power/regulator.h>
40 #endif
41 #ifdef CONFIG_DRM_ROCKCHIP
42 #include <video_rockchip.h>
43 #endif
44 #ifdef CONFIG_ROCKCHIP_DEBUGGER
45 #include <rockchip_debugger.h>
46 #endif
47 #include <of_live.h>
48 #include <dm/root.h>
49 #include <console.h>
50 
51 DECLARE_GLOBAL_DATA_PTR;
52 /* define serialno max length, the max length is 512 Bytes
53  * The remaining bytes are used to ensure that the first 512 bytes
54  * are valid when executing 'env_set("serial#", value)'.
55  */
56 #define VENDOR_SN_MAX	513
57 #define CPUID_LEN       0x10
58 #define CPUID_OFF       0x7
59 
60 static int rockchip_set_ethaddr(void)
61 {
62 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION
63 	int ret;
64 	u8 ethaddr[ARP_HLEN];
65 	char buf[ARP_HLEN_ASCII + 1];
66 
67 	ret = vendor_storage_read(VENDOR_LAN_MAC_ID, ethaddr, sizeof(ethaddr));
68 	if (ret > 0 && is_valid_ethaddr(ethaddr)) {
69 		sprintf(buf, "%pM", ethaddr);
70 		env_set("ethaddr", buf);
71 	}
72 #endif
73 	return 0;
74 }
75 
76 static int rockchip_set_serialno(void)
77 {
78 	char serialno_str[VENDOR_SN_MAX];
79 	int ret = 0, i;
80 	u8 cpuid[CPUID_LEN] = {0};
81 	u8 low[CPUID_LEN / 2], high[CPUID_LEN / 2];
82 	u64 serialno;
83 
84 	/* Read serial number from vendor storage part */
85 	memset(serialno_str, 0, VENDOR_SN_MAX);
86 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION
87 	ret = vendor_storage_read(VENDOR_SN_ID, serialno_str, (VENDOR_SN_MAX-1));
88 	if (ret > 0) {
89 		env_set("serial#", serialno_str);
90 	} else {
91 #endif
92 #ifdef CONFIG_ROCKCHIP_EFUSE
93 		struct udevice *dev;
94 
95 		/* retrieve the device */
96 		ret = uclass_get_device_by_driver(UCLASS_MISC,
97 						  DM_GET_DRIVER(rockchip_efuse), &dev);
98 		if (ret) {
99 			printf("%s: could not find efuse device\n", __func__);
100 			return ret;
101 		}
102 		/* read the cpu_id range from the efuses */
103 		ret = misc_read(dev, CPUID_OFF, &cpuid, sizeof(cpuid));
104 		if (ret) {
105 			printf("%s: reading cpuid from the efuses failed\n", __func__);
106 			return ret;
107 		}
108 #else
109 		/* generate random cpuid */
110 		for (i = 0; i < CPUID_LEN; i++) {
111 			cpuid[i] = (u8)(rand());
112 		}
113 #endif
114 		/* Generate the serial number based on CPU ID */
115 		for (i = 0; i < 8; i++) {
116 			low[i] = cpuid[1 + (i << 1)];
117 			high[i] = cpuid[i << 1];
118 		}
119 		serialno = crc32_no_comp(0, low, 8);
120 		serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
121 		snprintf(serialno_str, sizeof(serialno_str), "%llx", serialno);
122 
123 		env_set("serial#", serialno_str);
124 #ifdef CONFIG_ROCKCHIP_VENDOR_PARTITION
125 	}
126 #endif
127 	return ret;
128 }
129 
130 #if defined(CONFIG_USB_FUNCTION_FASTBOOT)
131 int fb_set_reboot_flag(void)
132 {
133 	printf("Setting reboot to fastboot flag ...\n");
134 	/* Set boot mode to fastboot */
135 	writel(BOOT_FASTBOOT, CONFIG_ROCKCHIP_BOOT_MODE_REG);
136 
137 	return 0;
138 }
139 #endif
140 
141 __weak int rk_board_init(void)
142 {
143 	return 0;
144 }
145 
146 __weak int rk_board_late_init(void)
147 {
148 	return 0;
149 }
150 
151 __weak int soc_clk_dump(void)
152 {
153 	return 0;
154 }
155 
156 __weak int set_armclk_rate(void)
157 {
158 	return 0;
159 }
160 
161 int board_late_init(void)
162 {
163 	rockchip_set_ethaddr();
164 	rockchip_set_serialno();
165 #if (CONFIG_ROCKCHIP_BOOT_MODE_REG > 0)
166 	setup_boot_mode();
167 #endif
168 
169 #ifdef CONFIG_DM_CHARGE_DISPLAY
170 	charge_display();
171 #endif
172 
173 #ifdef CONFIG_DRM_ROCKCHIP
174 	rockchip_show_logo();
175 #endif
176 
177 	soc_clk_dump();
178 
179 	return rk_board_late_init();
180 }
181 
182 #ifdef CONFIG_USING_KERNEL_DTB
183 #include <asm/arch/resource_img.h>
184 
185 /* Here, only fixup cru phandle, pmucru is not included */
186 static int phandles_fixup(void *fdt)
187 {
188 	const char *props[] = { "clocks", "assigned-clocks" };
189 	struct udevice *dev;
190 	struct uclass *uc;
191 	const char *comp;
192 	u32 id, nclocks;
193 	u32 *clocks;
194 	int phandle, ncells;
195 	int off, offset;
196 	int ret, length;
197 	int i, j;
198 	int first_phandle = -1;
199 
200 	phandle = -ENODATA;
201 	ncells = -ENODATA;
202 
203 	/* fdt points to kernel dtb, getting cru phandle and "#clock-cells" */
204 	for (offset = fdt_next_node(fdt, 0, NULL);
205 	     offset >= 0;
206 	     offset = fdt_next_node(fdt, offset, NULL)) {
207 		comp = fdt_getprop(fdt, offset, "compatible", NULL);
208 		if (!comp)
209 			continue;
210 
211 		/* Actually, this is not a good method to get cru node */
212 		off = strlen(comp) - strlen("-cru");
213 		if (off > 0 && !strncmp(comp + off, "-cru", 4)) {
214 			phandle = fdt_get_phandle(fdt, offset);
215 			ncells = fdtdec_get_int(fdt, offset,
216 						"#clock-cells", -ENODATA);
217 			break;
218 		}
219 	}
220 
221 	if (phandle == -ENODATA || ncells == -ENODATA)
222 		return 0;
223 
224 	debug("%s: target cru: clock-cells:%d, phandle:0x%x\n",
225 	      __func__, ncells, fdt32_to_cpu(phandle));
226 
227 	/* Try to fixup all cru phandle from U-Boot dtb nodes */
228 	for (id = 0; id < UCLASS_COUNT; id++) {
229 		ret = uclass_get(id, &uc);
230 		if (ret)
231 			continue;
232 
233 		if (list_empty(&uc->dev_head))
234 			continue;
235 
236 		list_for_each_entry(dev, &uc->dev_head, uclass_node) {
237 			/* Only U-Boot node go further */
238 			if (!dev_read_bool(dev, "u-boot,dm-pre-reloc"))
239 				continue;
240 
241 			for (i = 0; i < ARRAY_SIZE(props); i++) {
242 				if (!dev_read_prop(dev, props[i], &length))
243 					continue;
244 
245 				clocks = malloc(length);
246 				if (!clocks)
247 					return -ENOMEM;
248 
249 				/* Read "props[]" which contains cru phandle */
250 				nclocks = length / sizeof(u32);
251 				if (dev_read_u32_array(dev, props[i],
252 						       clocks, nclocks)) {
253 					free(clocks);
254 					continue;
255 				}
256 
257 				/* Fixup with kernel cru phandle */
258 				for (j = 0; j < nclocks; j += (ncells + 1)) {
259 					/*
260 					 * Check: update pmucru phandle with cru
261 					 * phandle by mistake.
262 					 */
263 					if (first_phandle == -1)
264 						first_phandle = clocks[j];
265 
266 					if (clocks[j] != first_phandle)
267 						printf("WARN: %s: first cru phandle=%d, this=%d\n",
268 						       dev_read_name(dev),
269 						       first_phandle, clocks[j]);
270 
271 					clocks[j] = phandle;
272 				}
273 
274 				/*
275 				 * Override live dt nodes but not fdt nodes,
276 				 * because all U-Boot nodes has been imported
277 				 * to live dt nodes, should use "dev_xxx()".
278 				 */
279 				dev_write_u32_array(dev, props[i],
280 						    clocks, nclocks);
281 				free(clocks);
282 			}
283 		}
284 	}
285 
286 	return 0;
287 }
288 
289 int init_kernel_dtb(void)
290 {
291 	int ret = 0;
292 	ulong fdt_addr = 0;
293 
294 	fdt_addr = env_get_ulong("fdt_addr_r", 16, 0);
295 	if (!fdt_addr) {
296 		printf("No Found FDT Load Address.\n");
297 		return -1;
298 	}
299 
300 	ret = rockchip_read_dtb_file((void *)fdt_addr);
301 	if (ret < 0) {
302 		printf("%s dtb in resource read fail\n", __func__);
303 		return 0;
304 	}
305 
306 	/*
307 	 * There is a phandle miss match between U-Boot and kernel dtb node,
308 	 * the typical is cru phandle, we fixup it in U-Boot live dt nodes.
309 	 */
310 	phandles_fixup((void *)fdt_addr);
311 
312 	of_live_build((void *)fdt_addr, (struct device_node **)&gd->of_root);
313 
314 	dm_scan_fdt((void *)fdt_addr, false);
315 
316 	gd->fdt_blob = (void *)fdt_addr;
317 
318 	/* Reserve 'reserved-memory' */
319 	ret = boot_fdt_add_sysmem_rsv_regions((void *)gd->fdt_blob);
320 	if (ret)
321 		return ret;
322 
323 	return 0;
324 }
325 #endif
326 
327 void board_env_fixup(void)
328 {
329 	struct memblock mem;
330 	ulong u_addr_r;
331 	phys_size_t end;
332 	char *addr_r;
333 
334 #ifdef ENV_MEM_LAYOUT_SETTINGS1
335 	const char *env_addr0[] = {
336 		"scriptaddr", "pxefile_addr_r",
337 		"fdt_addr_r", "kernel_addr_r", "ramdisk_addr_r",
338 	};
339 	const char *env_addr1[] = {
340 		"scriptaddr1", "pxefile_addr1_r",
341 		"fdt_addr1_r", "kernel_addr1_r", "ramdisk_addr1_r",
342 	};
343 	int i;
344 
345 	/* 128M is a typical ram size for most platform, so as default here */
346 	if (gd->ram_size <= SZ_128M) {
347 		/* Replace orignal xxx_addr_r */
348 		for (i = 0; i < ARRAY_SIZE(env_addr1); i++) {
349 			addr_r = env_get(env_addr1[i]);
350 			if (addr_r)
351 				env_set(env_addr0[i], addr_r);
352 		}
353 	}
354 #endif
355 	/* If bl32 is disabled, maybe kernel can be load to lower address. */
356 	if (!(gd->flags & GD_FLG_BL32_ENABLED)) {
357 		addr_r = env_get("kernel_addr_no_bl32_r");
358 		if (addr_r)
359 			env_set("kernel_addr_r", addr_r);
360 	/* If bl32 is enlarged, we move ramdisk addr right behind it */
361 	} else {
362 		mem = param_parse_optee_mem();
363 		end = mem.base + mem.size;
364 		u_addr_r = env_get_ulong("ramdisk_addr_r", 16, 0);
365 		if (u_addr_r >= mem.base && u_addr_r < end)
366 			env_set_hex("ramdisk_addr_r", end);
367 	}
368 }
369 
370 static void early_download_init(void)
371 {
372 #if defined(CONFIG_PWRKEY_DNL_TRIGGER_NUM) && \
373 		(CONFIG_PWRKEY_DNL_TRIGGER_NUM > 0)
374 	if (pwrkey_download_init())
375 		printf("Pwrkey download init failed\n");
376 #endif
377 
378 	if (!tstc())
379 		return;
380 
381 	gd->console_evt = getc();
382 	if (gd->console_evt <= 0x1a) /* 'z' */
383 		printf("Hotkey: ctrl+%c\n", (gd->console_evt + 'a' - 1));
384 
385 #if (CONFIG_ROCKCHIP_BOOT_MODE_REG > 0)
386 	/* ctrl+b */
387 	if (is_hotkey(HK_BROM_DNL)) {
388 		printf("Enter bootrom download...");
389 		flushc();
390 		writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
391 		do_reset(NULL, 0, 0, NULL);
392 		printf("failed!\n");
393 	}
394 #endif
395 }
396 
397 int board_init(void)
398 {
399 	int ret;
400 
401 	board_debug_uart_init();
402 
403 #ifdef CONFIG_USING_KERNEL_DTB
404 	init_kernel_dtb();
405 #endif
406 	early_download_init();
407 
408 	/*
409 	 * pmucru isn't referenced on some platforms, so pmucru driver can't
410 	 * probe that the "assigned-clocks" is unused.
411 	 */
412 	clks_probe();
413 #ifdef CONFIG_DM_REGULATOR
414 	ret = regulators_enable_boot_on(false);
415 	if (ret)
416 		debug("%s: Cannot enable boot on regulator\n", __func__);
417 #endif
418 
419 #ifdef CONFIG_ROCKCHIP_IO_DOMAIN
420 	io_domain_init();
421 #endif
422 
423 	set_armclk_rate();
424 
425 #ifdef CONFIG_DM_DVFS
426 	dvfs_init(true);
427 #endif
428 
429 	return rk_board_init();
430 }
431 
432 int interrupt_debugger_init(void)
433 {
434 	int ret = 0;
435 
436 #ifdef CONFIG_ROCKCHIP_DEBUGGER
437 	ret = rockchip_debugger_init();
438 #endif
439 	return ret;
440 }
441 
442 #if defined(CONFIG_ROCKCHIP_RK1808) && !defined(CONFIG_COPROCESSOR_RK1808)
443 #define PINCTRL_EMMC_BUS8_PATH		"/pinctrl/emmc/emmc-bus8"
444 #define PINCTRL_EMMC_CMD_PATH		"/pinctrl/emmc/emmc-cmd"
445 #define PINCTRL_EMMC_CLK_PATH		"/pinctrl/emmc/emmc-clk"
446 #define PINCTRL_PCFG_PU_2MA_PATH	"/pinctrl/pcfg-pull-up-2ma"
447 #define MAX_ROCKCHIP_PINS_ENTRIES	12
448 
449 static int rockchip_pinctrl_cfg_fdt_fixup(const char *path, u32 new_phandle)
450 {
451 	u32 cells[MAX_ROCKCHIP_PINS_ENTRIES * 4];
452 	const u32 *data;
453 	int i, count;
454 	int node;
455 
456 	node = fdt_path_offset(gd->fdt_blob, path);
457 	if (node < 0) {
458 		debug("%s: can't find: %s\n", __func__, path);
459 		return node;
460 	}
461 
462 	data = fdt_getprop(gd->fdt_blob, node, "rockchip,pins", &count);
463 	if (!data) {
464 		debug("%s: can't find prop \"rockchip,pins\"\n", __func__);
465 		return -ENODATA;
466 	}
467 
468 	count /= sizeof(u32);
469 	if (count > MAX_ROCKCHIP_PINS_ENTRIES * 4) {
470 		debug("%s: %d is over max count\n", __func__, count);
471 		return -EINVAL;
472 	}
473 
474 	for (i = 0; i < count; i++)
475 		cells[i] = data[i];
476 
477 	for (i = 0; i < (count >> 2); i++)
478 		cells[4 * i + 3] = cpu_to_fdt32(new_phandle);
479 
480 	fdt_setprop((void *)gd->fdt_blob, node, "rockchip,pins",
481 		    &cells, count * sizeof(u32));
482 
483 	return 0;
484 }
485 #endif
486 
487 int board_fdt_fixup(void *blob)
488 {
489 	int ret = 0;
490 
491 	/*
492 	 * Common fixup for DRM
493 	 */
494 #ifdef CONFIG_DRM_ROCKCHIP
495 	rockchip_display_fixup(blob);
496 #endif
497 
498 	/*
499 	 * Platform fixup:
500 	 *
501 	 * - RK3288: Recognize RK3288W by HDMI Revision ID is 0x1A;
502 	 * - RK1808: MMC strength 2mA;
503 	 */
504 #ifdef CONFIG_ROCKCHIP_RK3288
505 	if (soc_is_rk3288w()) {
506 		ret = fdt_setprop_string(blob, 0,
507 					 "compatible", "rockchip,rk3288w");
508 		if (ret)
509 			printf("fdt set compatible failed: %d\n", ret);
510 	}
511 #elif defined(CONFIG_ROCKCHIP_RK1808) && !defined(CONFIG_COPROCESSOR_RK1808)
512 	struct tag *t;
513 	u32 ph_pu_2ma;
514 
515 	t = atags_get_tag(ATAG_SOC_INFO);
516 	if (!t)
517 		return 0;
518 
519 	debug("soc=0x%x, flags=0x%x\n", t->u.soc.name, t->u.soc.flags);
520 
521 	if (t->u.soc.flags != SOC_FLAGS_ET00)
522 		return 0;
523 
524 	ph_pu_2ma = fdt_get_phandle(gd->fdt_blob,
525 		    fdt_path_offset(gd->fdt_blob, PINCTRL_PCFG_PU_2MA_PATH));
526 	if (!ph_pu_2ma) {
527 		debug("Can't find: %s\n", PINCTRL_PCFG_PU_2MA_PATH);
528 		return -EINVAL;
529 	}
530 
531 	ret |= rockchip_pinctrl_cfg_fdt_fixup(PINCTRL_EMMC_BUS8_PATH, ph_pu_2ma);
532 	ret |= rockchip_pinctrl_cfg_fdt_fixup(PINCTRL_EMMC_CMD_PATH, ph_pu_2ma);
533 	ret |= rockchip_pinctrl_cfg_fdt_fixup(PINCTRL_EMMC_CLK_PATH, ph_pu_2ma);
534 #endif
535 
536 	return ret;
537 }
538 
539 #ifdef CONFIG_ARM64_BOOT_AARCH32
540 /*
541  * Fixup MMU region attr for OP-TEE on ARMv8 CPU:
542  *
543  * What ever U-Boot is 64-bit or 32-bit mode, the OP-TEE is always 64-bit mode.
544  *
545  * Command for OP-TEE:
546  *	64-bit mode: dcache is always enabled;
547  *	32-bit mode: dcache is always disabled(Due to some unknown issue);
548  *
549  * Command for U-Boot:
550  *	64-bit mode: MMU table is static defined in rkxxx.c file, all memory
551  *		     regions are mapped. That's good to match OP-TEE MMU policy.
552  *
553  *	32-bit mode: MMU table is setup according to gd->bd->bi_dram[..] where
554  *		     the OP-TEE region has been reserved, so it can not be
555  *		     mapped(i.e. dcache is disabled). That's also good to match
556  *		     OP-TEE MMU policy.
557  *
558  * For the data coherence when communication between U-Boot and OP-TEE, U-Boot
559  * should follow OP-TEE MMU policy.
560  *
561  * Here is the special:
562  *	When CONFIG_ARM64_BOOT_AARCH32 is enabled, U-Boot is 32-bit mode while
563  *	OP-TEE is still 64-bit mode. U-Boot would not map MMU table for OP-TEE
564  *	region(but OP-TEE requires it cacheable) so we fixup here.
565  */
566 int board_initr_caches_fixup(void)
567 {
568 	struct memblock mem;
569 
570 	mem = param_parse_optee_mem();
571 	if (mem.size)
572 		mmu_set_region_dcache_behaviour(mem.base, mem.size,
573 						DCACHE_WRITEBACK);
574 	return 0;
575 }
576 #endif
577 
578 void board_quiesce_devices(void)
579 {
580 	hotkey_run(HK_CMDLINE);
581 
582 #ifdef CONFIG_ROCKCHIP_PRELOADER_ATAGS
583 	/* Destroy atags makes next warm boot safer */
584 	atags_destroy();
585 #endif
586 
587 #if defined(CONFIG_CONSOLE_RECORD)
588 	/* Print record console data */
589 	console_record_print_purge();
590 #endif
591 }
592 
593 void enable_caches(void)
594 {
595 	icache_enable();
596 	dcache_enable();
597 }
598 
599 #ifdef CONFIG_LMB
600 /*
601  * Using last bi_dram[...] to initialize "bootm_low" and "bootm_mapsize".
602  * This makes lmb_alloc_base() always alloc from tail of sdram.
603  * If we don't assign it, bi_dram[0] is used by default and it may cause
604  * lmb_alloc_base() fail when bi_dram[0] range is small.
605  */
606 void board_lmb_reserve(struct lmb *lmb)
607 {
608 	u64 start, size;
609 	char bootm_low[32];
610 	char bootm_mapsize[32];
611 	int i;
612 
613 	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
614 		if (!gd->bd->bi_dram[i].size)
615 			break;
616 	}
617 
618 	start = gd->bd->bi_dram[i - 1].start;
619 	size = gd->bd->bi_dram[i - 1].size;
620 
621 	/*
622 	 * 32-bit kernel: ramdisk/fdt shouldn't be loaded to highmem area(768MB+),
623 	 * otherwise "Unable to handle kernel paging request at virtual address ...".
624 	 *
625 	 * So that we hope limit highest address at 768M, but there comes the the
626 	 * problem: ramdisk is a compressed image and it expands after descompress,
627 	 * so it accesses 768MB+ and brings the above "Unable to handle kernel ...".
628 	 *
629 	 * We make a appointment that the highest memory address is 512MB, it
630 	 * makes lmb alloc safer.
631 	 */
632 #ifndef CONFIG_ARM64
633 	if (start >= ((u64)CONFIG_SYS_SDRAM_BASE + SZ_512M)) {
634 		start = gd->bd->bi_dram[i - 2].start;
635 		size = gd->bd->bi_dram[i - 2].size;
636 	}
637 
638 	if ((start + size) > ((u64)CONFIG_SYS_SDRAM_BASE + SZ_512M))
639 		size = (u64)CONFIG_SYS_SDRAM_BASE + SZ_512M - start;
640 #endif
641 	sprintf(bootm_low, "0x%llx", start);
642 	sprintf(bootm_mapsize, "0x%llx", size);
643 	env_set("bootm_low", bootm_low);
644 	env_set("bootm_mapsize", bootm_mapsize);
645 }
646 #endif
647 
648 #ifdef CONFIG_BIDRAM
649 int board_bidram_reserve(struct bidram *bidram)
650 {
651 	struct memblock mem;
652 	int ret;
653 
654 	/* ATF */
655 	mem = param_parse_atf_mem();
656 	ret = bidram_reserve(MEMBLK_ID_ATF, mem.base, mem.size);
657 	if (ret)
658 		return ret;
659 
660 	/* PSTORE/ATAGS/SHM */
661 	mem = param_parse_common_resv_mem();
662 	ret = bidram_reserve(MEMBLK_ID_SHM, mem.base, mem.size);
663 	if (ret)
664 		return ret;
665 
666 	/* OP-TEE */
667 	mem = param_parse_optee_mem();
668 	ret = bidram_reserve(MEMBLK_ID_OPTEE, mem.base, mem.size);
669 	if (ret)
670 		return ret;
671 
672 	return 0;
673 }
674 
675 parse_fn_t board_bidram_parse_fn(void)
676 {
677 	return param_parse_ddr_mem;
678 }
679 #endif
680 
681 #ifdef CONFIG_ROCKCHIP_AMP
682 void cpu_secondary_init_r(void)
683 {
684 	amp_cpus_on();
685 }
686 #endif
687 
688 #if defined(CONFIG_ROCKCHIP_PRELOADER_SERIAL) && \
689     defined(CONFIG_ROCKCHIP_PRELOADER_ATAGS)
690 int board_init_f_init_serial(void)
691 {
692 	struct tag *t = atags_get_tag(ATAG_SERIAL);
693 
694 	if (t) {
695 		gd->serial.using_pre_serial = t->u.serial.enable;
696 		gd->serial.addr = t->u.serial.addr;
697 		gd->serial.baudrate = t->u.serial.baudrate;
698 		gd->serial.id = t->u.serial.id;
699 
700 		debug("%s: enable=%d, addr=0x%lx, baudrate=%d, id=%d\n",
701 		      __func__, gd->serial.using_pre_serial,
702 		      gd->serial.addr, gd->serial.baudrate,
703 		      gd->serial.id);
704 	}
705 
706 	return 0;
707 }
708 #endif
709 
710 #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
711 #include <fdt_support.h>
712 #include <usb.h>
713 #include <usb/dwc2_udc.h>
714 
715 static struct dwc2_plat_otg_data otg_data = {
716 	.rx_fifo_sz	= 512,
717 	.np_tx_fifo_sz	= 16,
718 	.tx_fifo_sz	= 128,
719 };
720 
721 int board_usb_init(int index, enum usb_init_type init)
722 {
723 	int node;
724 	fdt_addr_t addr;
725 	const fdt32_t *reg;
726 	const void *blob = gd->fdt_blob;
727 
728 	/* find the usb_otg node */
729 	node = fdt_node_offset_by_compatible(blob, -1, "snps,dwc2");
730 
731 retry:
732 	if (node > 0) {
733 		reg = fdt_getprop(blob, node, "reg", NULL);
734 		if (!reg)
735 			return -EINVAL;
736 
737 		addr = fdt_translate_address(blob, node, reg);
738 		if (addr == OF_BAD_ADDR) {
739 			pr_err("Not found usb_otg address\n");
740 			return -EINVAL;
741 		}
742 
743 #if defined(CONFIG_ROCKCHIP_RK3288)
744 		if (addr != 0xff580000) {
745 			node = fdt_node_offset_by_compatible(blob, node,
746 							     "snps,dwc2");
747 			goto retry;
748 		}
749 #endif
750 	} else {
751 		/*
752 		 * With kernel dtb support, rk3288 dwc2 otg node
753 		 * use the rockchip legacy dwc2 driver "dwc_otg_310"
754 		 * with the compatible "rockchip,rk3288_usb20_otg",
755 		 * and rk3368 also use the "dwc_otg_310" driver with
756 		 * the compatible "rockchip,rk3368-usb".
757 		 */
758 #if defined(CONFIG_ROCKCHIP_RK3288)
759 		node = fdt_node_offset_by_compatible(blob, -1,
760 				"rockchip,rk3288_usb20_otg");
761 #elif defined(CONFIG_ROCKCHIP_RK3368)
762 		node = fdt_node_offset_by_compatible(blob, -1,
763 				"rockchip,rk3368-usb");
764 #endif
765 		if (node > 0) {
766 			goto retry;
767 		} else {
768 			pr_err("Not found usb_otg device\n");
769 			return -ENODEV;
770 		}
771 	}
772 
773 	otg_data.regs_otg = (uintptr_t)addr;
774 
775 	return dwc2_udc_probe(&otg_data);
776 }
777 
778 int board_usb_cleanup(int index, enum usb_init_type init)
779 {
780 	return 0;
781 }
782 #endif
783