From 294ad6176b9344c6c6c89924c3e10bb27bf21891 Mon Sep 17 00:00:00 2001 From: William Wu Date: Tue, 29 Jan 2019 14:26:12 +0800 Subject: [PATCH] rockchip: board: rework board usb init Currently, usb 2.0 otg node was found by the compatible "snps,dwc2" and the property "dr_mode". However, the "dr_mode" isn't a necessary condition, more seriously, if the dr_mode is set to "host" or "peripheral", we will fail to get the otg node. This patch finds otg node by the compatible "snps,dwc2" for most of Rockchip SoCs supported only one DWC2 controller. For RK3288, it supports two DWC2 controllers with the same compatible "snps,dwc2", so we add another condition (reg addr = 0xff580000) to get the otg node. Change-Id: I16acbf3e8da9bec19b8ec0a331b9114cb5462ac0 Signed-off-by: William Wu --- arch/arm/mach-rockchip/board.c | 46 +++++++++++++++------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c index c864378f03..8108e3acc2 100644 --- a/arch/arm/mach-rockchip/board.c +++ b/arch/arm/mach-rockchip/board.c @@ -393,28 +393,33 @@ static struct dwc2_plat_otg_data otg_data = { int board_usb_init(int index, enum usb_init_type init) { int node; - const char *mode; fdt_addr_t addr; const fdt32_t *reg; - bool matched = false; const void *blob = gd->fdt_blob; /* find the usb_otg node */ - node = fdt_node_offset_by_compatible(blob, -1, - "snps,dwc2"); + node = fdt_node_offset_by_compatible(blob, -1, "snps,dwc2"); - while (node > 0) { - mode = fdt_getprop(blob, node, "dr_mode", NULL); - if (mode && strcmp(mode, "otg") == 0) { - matched = true; - break; +retry: + if (node > 0) { + reg = fdt_getprop(blob, node, "reg", NULL); + if (!reg) + return -EINVAL; + + addr = fdt_translate_address(blob, node, reg); + if (addr == OF_BAD_ADDR) { + pr_err("Not found usb_otg address\n"); + return -EINVAL; } - node = fdt_node_offset_by_compatible(blob, node, - "snps,dwc2"); - } - - if (!matched) { +#if defined(CONFIG_ROCKCHIP_RK3288) + if (addr != 0xff580000) { + node = fdt_node_offset_by_compatible(blob, node, + "snps,dwc2"); + goto retry; + } +#endif + } else { /* * With kernel dtb support, rk3288 dwc2 otg node * use the rockchip legacy dwc2 driver "dwc_otg_310" @@ -429,25 +434,14 @@ int board_usb_init(int index, enum usb_init_type init) node = fdt_node_offset_by_compatible(blob, -1, "rockchip,rk3368-usb"); #endif - if (node > 0) { - matched = true; + goto retry; } else { pr_err("Not found usb_otg device\n"); return -ENODEV; } } - reg = fdt_getprop(blob, node, "reg", NULL); - if (!reg) - return -EINVAL; - - addr = fdt_translate_address(blob, node, reg); - if (addr == OF_BAD_ADDR) { - pr_err("Not found usb_otg address\n"); - return -EINVAL; - } - otg_data.regs_otg = (uintptr_t)addr; return dwc2_udc_probe(&otg_data);