xref: /rk3399_rockchip-uboot/arch/arm/mach-rockchip/usbplug.c (revision 827e2ae92e2103f82dab5b54228ad24e40db6263)
1 /*
2  * (C) Copyright 2020 Rockchip Electronics Co., Ltd.
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <debug_uart.h>
9 #include <malloc.h>
10 #include <mmc.h>
11 #include <stdlib.h>
12 
13 DECLARE_GLOBAL_DATA_PTR;
14 
15 static char *bootdev_rockusb_cmd(void)
16 {
17 	const char *devtype, *devnum;
18 	const char *bootdev_list[] = {
19 		"mmc",		"0",
20 		"mtd_blk",	"0",
21 		"mtd_blk",	"1",
22 		"mtd_blk",	"2",
23 		"rknand",	"0",
24 		"rksfc",	"0",
25 		"rksfc",	"1",
26 		NULL,		NULL,
27 	};
28 	char *cmd;
29 	int i = 0;
30 
31 	devtype = bootdev_list[0];
32 	devnum = bootdev_list[1];
33 	while (devtype) {
34 		if (!strcmp("mmc", devtype))
35 			mmc_initialize(gd->bd);
36 
37 		if (blk_get_devnum_by_typename(devtype, atoi(devnum)))
38 			break;
39 
40 		i += 2;
41 		devtype = bootdev_list[i];
42 		devnum = bootdev_list[i + 1];
43 	}
44 
45 	if (!devtype) {
46 		printf("No boot device\n");
47 		return NULL;
48 	}
49 
50 	printf("Bootdev: %s %s\n", devtype, devnum);
51 
52 	cmd = malloc(32);
53 	if (!cmd)
54 		return NULL;
55 
56 	snprintf(cmd, 32, "rockusb 0 %s %s", devtype, devnum);
57 
58 	return cmd;
59 }
60 
61 int board_init(void)
62 {
63 	return run_command(bootdev_rockusb_cmd(), 0);
64 }
65 
66