From da5968ecbdce00570b8cf39a2d078ab14492cf3b Mon Sep 17 00:00:00 2001 From: Sasirekaa Madhesu Date: Thu, 22 Feb 2018 17:34:07 +0530 Subject: [PATCH] ipq40xx: Enable USB device mode through dts patching This commit enables USB device mode through dts patching. To enable 'setenv usb_mode device' to be executed in u-boot environment before booting the kernel. Change-Id: I2bcba292a514d04eed7e941a7feba00600fc1fc9 Signed-off-by: Sasirekaa Madhesu --- board/qca/arm/ipq40xx/ipq40xx.c | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/board/qca/arm/ipq40xx/ipq40xx.c b/board/qca/arm/ipq40xx/ipq40xx.c index 1ae791371b..bde4301903 100644 --- a/board/qca/arm/ipq40xx/ipq40xx.c +++ b/board/qca/arm/ipq40xx/ipq40xx.c @@ -35,6 +35,7 @@ #include "ipq_phy.h" #define DLOAD_MAGIC_COOKIE 0x10 +#define TCSR_USB_HSPHY_DEVICE_MODE 0x00C700E70 DECLARE_GLOBAL_DATA_PTR; qca_mmc mmc_host; @@ -316,6 +317,58 @@ void ipq_fdt_fixup_socinfo(void *blob) void ipq_fdt_fixup_usb_device_mode(void *blob) { + int nodeoff, ret, i; + int phy_mode = htonl(TCSR_USB_HSPHY_DEVICE_MODE); + const char *mode = "peripheral"; + const char *node[] = {"/soc/ssphy", "/soc/hsphy", "/soc/usb3"}; + char *usb_cfg; + + usb_cfg = getenv("usb_mode"); + if (!usb_cfg) + return; + + if (strcmp(usb_cfg, "device")) + return; + + nodeoff = fdt_path_offset(blob, "/soc/tcsr"); + if (nodeoff < 0) { + printf("ipq: fdt fixup unable to find node /soc/tcsr\n"); + return; + } + ret = fdt_setprop(blob, nodeoff, "ipq,usb-hsphy-mode-select", + &phy_mode, sizeof(phy_mode)); + if (ret != 0) { + printf("ipq: unable to set prop: %d\n", ret); + return; + } + + phy_mode = 0; + for (i = 0; i < (sizeof(node) / sizeof(node[0])); i++) { + nodeoff = fdt_path_offset(blob, node[i]); + if (nodeoff < 0) { + printf("ipq: fdt fixup unable to find node %s\n", + node[i]); + continue; + } + ret = fdt_setprop(blob, nodeoff, "qca,host", + &phy_mode, sizeof(phy_mode)); + if (ret != 0) { + printf("ipq: unable to set prop: %d\n", ret); + continue; + } + } + + nodeoff = fdt_path_offset(blob, "/soc/usb3/dwc3"); + if (nodeoff < 0) { + printf("ipq: fdt fixup unable to find node /soc/usb3/dwc3\n"); + return; + } + ret = fdt_setprop(blob, nodeoff, "dr_mode", + mode, (strlen(mode) + 1)); + if (ret != 0) { + printf("ipq: unable to set prop: %d\n", ret); + return; + } return; }