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.

Linux/PROCESSOR-SDK-AM335X: Dynamically disable and enable usb port configured as otg/peripheral

Part Number: PROCESSOR-SDK-AM335X


Tool/software: Linux

We are running a custom board powered by AM335x Sitara processor and it has 2 USB ports.

USB 1 is configured in "Host" mode and is connected to an external Cellular modem.

USB0 is configured as "Peripheral" mode and is used for debug purposes.

Both these ports are using network over USB driver(RNDIS g_ether) to be detected as network interfaces.

Till now everything is working fine. Now since our product is entering production, we would like to disable the USB0 peripheral port( with a catch that the support team can enable it when required via a script/command).

I have removed the usb0 interface from the /etc/network/interfaces file, but when I plug in this particular usb port to a PC, it is still detected as a network interface due to the g_ether kernel module still enabled. I cannot afford to disable the g_ether ko as it is used by the other USB interface (HOST)(USB1) interface to talk to the cellular modem.

Is there a way I can disable the detection of this  usb0(Peripheral mode) port when it is connected to any PC so that the end user doesn't get a prompt that external hardware is detected and requests any driver downloads.

Please note, that I cannot disable it via the device tree as we might need to enable it without recompiling the firmware , if there is a need to debug the product on the field.

Thanks in advance.

  • Hi Surjit,

    I suggest you software approach to disable Linux kernel console which is on USB0 in your case. See description about how to configure kernel settings at:
    www.linuxtopia.org/.../ch09s07.html

    BR
    Tsvetolin Shulev
  • Hi Tsvetolin,

    Thank you for the quick response. I have already disabled linux console access on this USB port. The issue which I want to resolve is that when this board is connected to any Windows/Linux PC, it should not be detected as a new hardware which leads to pop up on the PC requesting downloading drivers etc.

    The only way I know to do this is via the kernel device tree but I also have a request from our in house support team to have a provision to enable access to this usb via a script or linux command so that they can access logs etc over this usb port if needed once the product is deployed on field and in case customer faces any issues.

    Is there any way via Linux apart from device tree, which I can use to dynamically enable/ disable this particular USB gadget port.

    Thanks again.

    Regards,

    Surjit

  • Hi Surjit,

    I am curious to know if "Deferred init" call can help you. Basically Deferred init will enable the driver once you write a value through /proc/deferred_initcalls. This way, your support team can load a script only when needed. I have used Deferred init for boot time optimization of one ti of chip set(Not AM335x though).

    For more info, please refer, elinux.org/Deferred_Initcalls

    Hope it helps.

    Thanks,
    Prabhuraj
    BlackPepper Technologies
  • Hi Prabhuraj,

    I would need to load the g_ether(network over usb driver) early on as we need to use that driver for USB1(HOST USB) for its functionality.
    So defferent init call would not help us.
    All we want to do is power off usb0(peripheral/otg usb port) via a linux command to mask the detection of our device when its connected via usb to any PC.
  • Hi Surjit,

    You may also explore options to disable the USB through sysfs. Like "sudo sh -c "echo '0' > /sys/bus/usb/devices/usbX..."

    Thanks,
    Prabhuraj
    BlackPepper Technologies
  • Hi Surjit,

    If USB1 is acting as host, then g_ether.ko will not come into picture. As the name suggests it is for peripheral/gadget "g_". So you could make all the USB gadget drivers as modules and give a try inserting when needed.
  • Hi Prabhuraj,

    Thanks for the quick response.

    I can only see my host usb(usb1) via sysfs. The perihperal/otg usb(usb0) does not get enumerated in /sys/bus/ usb sysfs.

    [root@xxx ~]# cd /sys/bus/usb/devices/
    [root@xxx devices]# ls -ltr
    total 0
    lrwxrwxrwx 1 root root 0 Aug 31 06:29 usb1 -> ../../../devices/platform/ocp/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb1/
    lrwxrwxrwx 1 root root 0 Aug 31 06:29 1-1:1.3 -> ../../../devices/platform/ocp/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb1/1-1/1-1:1.3/
    lrwxrwxrwx 1 root root 0 Aug 31 06:29 1-1:1.2 -> ../../../devices/platform/ocp/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb1/1-1/1-1:1.2/
    lrwxrwxrwx 1 root root 0 Aug 31 06:29 1-1:1.1 -> ../../../devices/platform/ocp/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb1/1-1/1-1:1.1/
    lrwxrwxrwx 1 root root 0 Aug 31 06:29 1-1:1.0 -> ../../../devices/platform/ocp/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb1/1-1/1-1:1.0/
    lrwxrwxrwx 1 root root 0 Aug 31 06:29 1-1 -> ../../../devices/platform/ocp/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb1/1-1/
    lrwxrwxrwx 1 root root 0 Aug 31 06:29 1-0:1.0 -> ../../../devices/platform/ocp/47400000.usb/47401c00.usb/musb-hdrc.1.auto/usb1/1-0:1.0/
    [root@xxx devices]#

    Though I tried to do it via /sys/bus/platform/drivers/musb-hdrc/musb-hdrc.0.auto/power.
    # cd /sys/bus/platform/drivers/musb-hdrc/musb-hdrc.0.auto/power
    [root@cioffi power]# echo '0' > autosuspend_delay_ms
    [root@cioffi power]# echo 'auto' > control

    But it is not powering down the usb0(otg) port. :(..... It still gets detected the moment i plug in my device to any PC :(

    Regards,
    Surjit
  • Hi Dwarakesh,

    This was the first thing I tried, but as soon as I disabled g_ether module, the network interface over usb1 also went down. As soon as I reinserted the g_ether module, the network over usb for usb1(host) port starts working. Hence totally stuck. What RNDIS driver does a Host USB port uses to create a network over USB interface, if not g_ether?

    Thanks for the quick response. Appreciate it.

    Regards,
    Surjit
  • Hi Surjit,

    RNDIS driver is generally a gadget driver to connect to Windows machine.

    For Modems USB Host class driver that we have used CDC_NCM, CDC_ACM, USBNET, CDC_ETHER, CDC_WDM, etc. What modem is being used ?
  • Hi Dwarakesh,

    We are using usb1(host mode) to connect to a cellular modem. So all the data traffic passes over the ip interface created over this interface.
    I disabled the g_ether and I could see this particular usb1 (ip interface over usb host port) being taken down. And when i re-insert g_ether this ip interface over usb comes up again and all connectivity with cellular modem is fine.

    Regards,
    Surjit
  • Hi Surjit,

    On a different node, may I know if your custom board supports per port USB power handling ? I mean, how are the power lines mapped for USB ports in your board?

    In a way, I am looking at an option if there is a possibility to control the power line pins connecting to your USB0
    Look at the below links which can give a clue to you :

    e2e.ti.com/.../1215899
    e2e.ti.com/.../1382339
    e2e.ti.com/.../627977
    e2e.ti.com/.../1925709

    Also powertop utility can help you disable USB devices from command line(power top code is available and you can try to cross compile it)
    github.com/.../powertop - Source code link
    askubuntu.com/.../how-to-disable-auto-power-off-of-usb-devices-like-usb-mouse - example powertop command

    Hope it helps

    Thanks,
    Prabhuraj
    BlackPepper Technologies
  • Hi Surjit,

    Interesting. What do you see in dmesg, when this happens ? What modem are you using ? For USB Host RNDIS driver configuration is USB_NET_RNDIS_HOST is required for RDNIS complaint USB Modems.
  • Hi Dwarakesh,

    Figured out the issue. It is actually a blunder on my part. Removing g_ether actually was taking down the gadget only(usb0) and the host device was still up. Only issue was that it was getting enumerated as usb0 and not usb1.Obviously as now gadget was no longer there and hence the only usb device(host) was being enumerated as usb0. And I like an idiot was looking out for usb1. And since I was using a ifplugd daemon for hotplugging usb1 , hence it never hotplugged usb0 and hence i missed it.

    A look at the dmesg literally was a slap on my face. I should have looked at it earlier.

    Thanks all for pointing me to the right direction.

    Regards,
    Surjit
  • Hi Surjit,

    Good to know you have made progress. All the best.
  • Hi Surjit,

    Good to know that you could resolve the issue.


    Thanks,
    Prabhuraj
    BlackPepper Technologies