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.

  • Resolved

USB1 power control with DRVVBUS

Prodigy 50 points

Replies: 16

Views: 10788

Hello, 

I am using a custom board with AM335x (mostly cloned from BeagleBone). We use USB1 host, with a UVC-compatible USB camera always plugged.

USB1_ID is grounded, USB1_DRVVBUS connected to TPS2051 (power switch) enable signal, USB1_VBUS connected to the TPS2051 output  and to the pin1 of USB A connector (usb power 5V). 

The camera works fine, but we want to control (switch-on and switch-off) the USB power (for power saving). And I don't know I to do it. 

We have found two problems:

  1. the USB1_DRVVBUS is controlled from the linux driver (and I don't found any way to instruct the driver to move it). 
  2. if I unplug and plug again the camera, the system disconnect and found the camera, but there is same dmesg errors: "[ 2037.444946] 6:3:1: cannot set freq 16000 to ep 0x86".... and when I try to use the camera another error: "uvcvideo: Failed to set UVC probe control : -110 (exp. 26)."

I can solve the second problem doing "rmmod uvcvideo" before pluging the camera. But probably there is a better solution!!

And about the first problem, I don't have a good solution. What could I do to control USB_DRVVBUS1? (from command line, from programm, from kernel...).

I have try to change USB1_DRVVBUS pin mux to 7 (gpio) and control it manually. It removes the power from USB but there is a lot of dmesg errors (every 250ms) "hub 1-0:1.0: over-current condition on port 1".

I have try to change USB1 mode to manually device (USB1MODE=0x180), trying to override the ID pin, and hopping that this would turn-off the DRVVBUS, but it didn´t work (probably only works on boot?). 

I could change the hardware layout in order to cheat  the driver: with a transistor I can send 5V to USB1_VBUS when the USB1_DRVVBUS is active; an I can use any other gpio to control from my program the TPS2051 switch to send power to the USB connector. I don´t know if this would work, but there should be a simpler software solution. 

Any idea? Thanks in advance, 

Alfredo Agudo

uname -a
Linux ibernexNX050x 3.2.42 #19 Mon Jun 3 19:06:27 CEST 2013 armv7l GNU/Linux

lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 046d:0825 Logitech, Inc.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

  • Guru 52370 points

    Alfredo Agudo
    the USB1_DRVVBUS is controlled from the linux driver (and I don't found any way to instruct the driver to move it). 

    If you look at the MUSB linux driver (drivers/usb/musb/musb_regs.h), you will find a 8-bit register called MUSB_DEVCTL, its bit0 MUSB_DEVCTL_SESSION controls USBx_DRVVBUS.

    The physical address of MUSB_DEVCTL for MUSB1 is 0x47401C60, you can use devmem2 tool to play with it.

    The MUSB driver in TI provided AM335x kernel already has a user-space interface in procfs (drivers/usb/musb/musb_procfs.c) to set the SESSION bit to turn on USBx_DRVVBUS, which is command 'echo F > /proc/driver/musb_hdrc.1' for MUSB1, you can use it as a reference to implement a new procfs interface to clear the SESSION bit to turn off USBx_DRVVBUS, if want your application to control the USB power.

    Alfredo Agudo
    if I unplug and plug again the camera, the system disconnect and found the camera, but there is same dmesg errors: "[ 2037.444946] 6:3:1: cannot set freq 16000 to ep 0x86".... and when I try to use the camera another error: "uvcvideo: Failed to set UVC probe control : -110 (exp. 26)."

    I do have a Logitech uvc webcam which has the 'cannot set freq...' error, even with my Linux PC (ubuntu 12.04), but it seems have no issue to use.

    The '-110' enumeration error needs further debug. Have you tried other uvc cams? Do you use kernel from TI.com? what is the psp/sdk version?

    Alfredo Agudo
    I have try to change USB1_DRVVBUS pin mux to 7 (gpio) and control it manually.

    This pinmux should not be changed in runtime.

    Alfredo Agudo
    I have try to change USB1 mode to manually device (USB1MODE=0x180), trying to override the ID pin, and hopping that this would turn-off the DRVVBUS, but it didn´t work (probably only works on boot?). 

    This change only take effect after clear then set the DEVCTL SESSION bit.

  • In reply to Bin Liu:

    Thank you!

    It works perfectly: Modifying bit 0 of 8 bit register address 0x47401C60 it switch on/off USB1_DRVVBUS pin, without dmesg errors. 

    About the second problem ( "uvcvideo: Failed to set UVC probe control : -110 (exp. 26)" )  I am using Logitech C270 (but I still don´t know which will be the final model) and the Linux 3.2.41  from Angstrom.

    I don´t know the source of the second problem, but  I have found a solution: in order to revive the camera after the USB power on, instead of doing "rmmod uvcvideo; modprobe uvcvideo" I just call "v4l2-ctl --list-devices" or "v4l2-ctl -V" and then I can use the camera without problem. 

    Best Regards, 

    Alfredo Agudo

  • In reply to Bin Liu:

    Hi Bin,

    I am unable control usb power with DRVVBUS at runtime, I was using above procfs command i.e  echo F > /proc/driver/musb_hdrc.1 which showing below log message 

    root@am335x-evm:~# echo F > /proc/driver/musb_hdrc.1
    -sh: /proc/driver/musb_hdrc.1: No such file or directory

    could you tell me how to turn off and turn on USBx_DRVVBUS.

    Thanks & Regards 

    srinivas 

  • Guru 52370 points

    In reply to Srini:

    Srinivas,

    Which SDK do you use?

    'echo F ...' is only applicable to SDK6.0 or older. It does not exist since SDK7.0.

  • In reply to Bin Liu:

    Hi Bin liu,


    We are using sdk 8.0(kernel 3.14) 
    In our custom board(host mode) we are trying to disable USB charging for slave devices. 

    But we are facing an over-current issue with our board. USB controller on AM3352 processor is detecting over-current event which means the Mobile phone is trying to source more current from our board, which the board is not able to feed in. This is because of current being limited to 150mA for USB on the board. We have tried on multiple mobile phones (Samsung S4, Moto G, Sony, etc) and seeing the same issue on all of them.


    we do not want charging of phones using our board !

    could you tell me how disable usb controller. 

    Kindly do the needful as early as possible

    Many Thanks in advance,

  • Guru 52370 points

    In reply to Srini:

    I am not sure what is your reason of limiting the VBUS current to 150mA, but this violates the USB2.0 Spec. The USB2.0 host should provided minimum 500mA.

    Another issue is that even if you could disable the USB controller in your use case, then what is the point to connect the phone to your board via USB?

  • In reply to Bin Liu:

    Sorry bin Liu,

    Its not disabling the usb controller, actually our usb switch current limit is 150mA and our board usb otg is a power supplier, and an usb otg device is a power consumer(like mobile phones),

    Could you please help me how to stop charging devices from the USB otg port because Mobile USB devices require more power than it is permitted by the specifications for a single port.
  • Guru 52370 points

    In reply to Srini:

    Srini
    actually our usb switch current limit is 150mA

    As I said before, this design violates the USB2.0 Specs.

    Srini
    how to stop charging devices from the USB otg port

    I don't think there is any way to achieve this.

    Srini
    because Mobile USB devices require more power than it is permitted by the specifications for a single port.

    How much is the current? If it is not more than 500mA from the AM335x USB port, the mobile device still complies with the USB Spec.

  • In reply to Bin Liu:

    The USB OTG specification says an OTG device that sources more than 100ma on VBUS is required to follow the power delivery requirements defined in the USB 2.0 specification. The USB 2.0 specification requires a standard host to source 500ma minimum. Therefore, your product should be able to source 500ma.

    The USB 2.0 specification also says a peripheral shall never consume more than 100ma before enumerating and asking permission to consume more power.

    Your product operating as host may not be compliant to the specification, but it should work when connected directly connected to a compliant peripheral. Your product is able to source 150ma, the compliant peripheral should only consume up to 100ma while negotiating with the driver for higher power, the driver should not give permission if the peripheral requests more than 150ma. In this case, the driver should disconnect the peripheral or continue to operate with reduced functionality at the lower power level. If the peripheral ignores the driver and begins to draw more power than your product can source, the VBUS source will current limit and indicate an over-current condition.

    Your product would never be able to support inserting a bus powered USB hub in downstream path as the hub may require up to 100ma and there would only be 50ma remaining for any peripheral.

    You may be able to get limited functionality if you could modify the mobile phone driver such that it would never give the mobile phone permission to consume more than 150ma.

    Regards,
    Paul
  • In reply to peaves:

    Hi paul & Bin,

     Thanks for yours response,

    Problem: over current detection.

    I am using sdk 8.0 and kernel 3.14, In usb otg when I plugin any device to board after that  the USB OTG controller begins a host session the DRVVBUS output is driven high to enable a VBUS power switch.  The OTG controller is monitoring the VBUS voltage after a host session.

    how to determine if there is an over-current condition on VBUS line in driver level.

    Please find the below details.

    Usb power switch max current is150mA

    processor:am3352

    Schematic: BBB reff

    Thanks

    N Shankar.

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.