How to change the USB0_DP from OTG to host mode?

Reference to this patch ,I can froce change usb mode to host with update kernel.
NVIDIA NX disabling USB0 as serial console:

But what should we do if we want to automatic detect otg or host mode?
Or do we have any method to change otg/host mode with specific operation in the system?