This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM62P: [AM62P] Require help in performing Usb role-switch in Linux

Part Number: AM62P

Hi Team,

We are trying to perform Usb role-switch from Host mode to Device mode.
After following the forum, we found a ticket where the user is trying to perform role-switch in another platform.
https://e2e.ti.com/support/processors-group/processors/f/processors-forum/953719/dra72xevm-usb-role-switch-is-not-working?keyMatch=usb+role-switch&tisearch=universal_search

We tried following that, still the Usb controller is not getting switched to Device mode. We are able to see two usb end points (31000000.usb & 31100000.usb). By default 31000000.usb is in "device" mode and 31100000.usb is in "host" mode. Since the Usb devices are getting detected on the system, we assumed that 31100000.usb has to be updated to "device" mode, but it was not taking effect.

Whereas, if we update 31000000.usb, it is changing the values, but it doesn't make sense to move the "device" to "host" mode here as we are expecting the Usb to go to "device" mode. Also, when we do that, still the usb is staying connected. Thus the purpose is not met.

Attached the logs for the same (including the dmesg prints).
usb_role-switch.log 

Please check this and guide us on how to proceed further on this.

Thanks & Regards,
Mohammed Shakir

  • Hi Mohammed,

    First of all, this debugfs mode entry is for debug purpose only, it is not meant for production. You would have to be very careful when using this debugfs to switch the mode, and ensure the entire process compliant with the USB Specs. One of the problems would be to not cause VBUS contention when both ends of the USB bus are in host mode.

    Then you need to ensure the 'dr_mode" property in kernel devicetree for the corresponding USB port to be configured "otg", not "host" or "device". The debugfs mode entry only works for USB port which has its dr_mode = otg.

  • Hi Bin Liu,

    Thank you for your prompt response. Really appreciate that.

    Unfortunately, we don't have access to the Build System, is it possible to do this inside the running system without modifying any devicetree?

    Thanks & Regards,
    Mohammed Shakir

  • The debugfs function is implemented in kernel, and its behavior is based on the devicetree setting and determined at the kernel boot time parsing the devicetree. I am unable to think of any easy way to resolve this without modifying and recompiling the kernel devicetree.

  • Hi Bin Liu,

    I have managed to setup the tisdk. We had checked the dts and dtsi files, all the files which which is having am62p are having dr_mode="otg' for the usb.

    Ref from k3-am62p-main.dtsi

    		usb1: usb@31100000 {
    			compatible = "snps,dwc3";
    			reg = <0x00 0x31100000 0x00 0x50000>;
    			interrupts = <GIC_SPI 226 IRQ_TYPE_LEVEL_HIGH>, /* irq.0 */
    			<GIC_SPI 226 IRQ_TYPE_LEVEL_HIGH>; /* irq.0 */
    			interrupt-names = "host", "peripheral";
    			maximum-speed = "high-speed";
    			dr_mode = "otg";
    			snps,usb2-gadget-lpm-disable;
    			snps,usb2-lpm-disable;
    		};
    


    Ref from: k3-am62p-j722s-common-main.dtsi
                    usb0: usb@31000000 {
                            compatible = "snps,dwc3";
                            reg = <0x00 0x31000000 0x00 0x50000>;
                            interrupts = <GIC_SPI 188 IRQ_TYPE_LEVEL_HIGH>, /* irq.0 */
                            <GIC_SPI 188 IRQ_TYPE_LEVEL_HIGH>; /* irq.0 */
                            interrupt-names = "host", "peripheral";
                            maximum-speed = "high-speed";
                            dr_mode = "otg";
                            bootph-all;
                            snps,usb2-gadget-lpm-disable;
                            snps,usb2-lpm-disable;
                    };


    Except in the file below, (k3-am62p5-sk.dts)
    &usb0 {
    	usb-role-switch;
    
    	port {
    		usb0_hs_ep: endpoint {
    			remote-endpoint = <&usb_con_hs>;
    		};
    	};
    };
    
    &usb0_phy_ctrl {
    	bootph-all;
    };
    
    &usb1 {
    	dr_mode = "host";
    	pinctrl-names = "default";
    	pinctrl-0 = <&main_usb1_pins_default>;
    };


    Since the usb@31100000 and usb@310000000 was the ones I can see in the target, I assumed the above one might not be getting used. Please correct me if I am wrong here.

    I will meantime try to edit here and generate an image.

    Thanks & Regards,
    Mohammed Shakir

  • Hi Mohammed,

    I assumed the above one might not be getting used. Please correct me if I am wrong here.

    I am not sure what you exactly mean here, please elaborate.

  • Hi Bin Liu,

    Sorry, I am not well-versed in this topic yet.
    Just to clarify my understanding, as mentioned in the initial ticket, 31100000 & 31000000 are the base addresses of the usb in the current AM62P Sitara EVM target. And k3-am62p-main.dtsi & k3-am62p-j722s-common-main.dtsi seems to be having configurations of those. Both of them are configured to have dr_mode as "otg" as we are expecting.

    Whereas, k3-am62p5-sk.dts is not having any configurations about the 31100000 & 31000000, so I suspect this file might not getting used for the tisdk-default-image which is getting build.

    So, do we need to edit those files to proceed further on the Usb Role-Switch feature bring up?

    Thanks & Regards,
    Mohammed Shakir

  • Hi Mohammed,

    Now I understand the question. Thanks for the clarification.

    The nodes 31100000 and 31000000 in the *.dtsi files have label usb1 and usb0 respectively. The labels are referenced in file k3-am62p5-sk.dts. So yes both usb nodes defined in *.dtsi are indeed used in k3-am62p5-sk.dts, and usb1 dr_mode has been changed from "org" to "host".

  • Thanks  
    The changes you suggested is working.
    On top of that, I had to add 'usb-role-switch;' also on the usb1.

    --- a/arch/arm64/boot/dts/ti/k3-am62p5-sk.dts
    +++ b/arch/arm64/boot/dts/ti/k3-am62p5-sk.dts
    @@ -699,7 +699,8 @@ &usb0_phy_ctrl {
     };
     
     &usb1 {
    -       dr_mode = "host";
    +       usb-role-switch;
    +       dr_mode = "otg";
            pinctrl-names = "default";
            pinctrl-0 = <&main_usb1_pins_default>;
     };

  • Glad it is working now. Thanks for the update.