OpenWrt Forum Archive

Topic: How to poweroff/poweron usb port?

The content of this topic has been archived on 26 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello.
I have Linksys160NL with OpenWRT and USB modem AnyData. How to power on/off the modem? In linux this can do with the command:

echo suspend >/sys/bus/usb/devices/1-2/power/level
and to turn it back on:
echo auto >/sys/bus/usb/devices/1-2/power/level

but in openwrt this path is wrong.
How to solve this trouble?
Thanks.

Use "lsusb" to get the Bus and Device numbers of the modem - if it's not Bus 1, Device 2, then the path is wrong.  For example:

# lsusb
Bus 001 Device 004: ID 1234:5678 AnyData modem

Bus=1, Device=4, so the path to use is /sys/bus/usb/devices/1-4/power/level

"lsusb" is in the usbutils package.  If you don't have that installed, you can check the output of "cat /proc/bus/usb/devices" but that's a bit more complicated!

If you already have the right Bus-Device number, then sorry, I don't know the answer.  Good luck!

Thanks. But i have another result:

# lsusb
Bus 001 Device 002: ID 16d5:6502 AnyDATA Corporation CDMA/UMTS/GPRS modem
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

But look at this:

# ls -la /sys/bus/usb/devices/
drwxr-xr-x    2 root     root            0 Jan 21 19:30 .
drwxr-xr-x    4 root     root            0 Jan 21 19:30 ..
lrwxrwxrwx    1 root     root            0 Jan 21 19:30 1-0:1.0 -> ../../../devices/platform/ar71xx-ehci/usb1/1-0:1.0
lrwxrwxrwx    1 root     root            0 Jan 21 19:30 1-1 -> ../../../devices/platform/ar71xx-ehci/usb1/1-1
lrwxrwxrwx    1 root     root            0 Jan 21 19:30 1-1:1.0 -> ../../../devices/platform/ar71xx-ehci/usb1/1-1/1-1:1.0
lrwxrwxrwx    1 root     root            0 Jan 21 19:30 1-1:1.1 -> ../../../devices/platform/ar71xx-ehci/usb1/1-1/1-1:1.1
lrwxrwxrwx    1 root     root            0 Jan 21 19:30 1-1:1.2 -> ../../../devices/platform/ar71xx-ehci/usb1/1-1/1-1:1.2
lrwxrwxrwx    1 root     root            0 Jan 21 19:30 usb1 -> ../../../devices/platform/ar71xx-ehci/usb1

Which one for my USB modem?

By the way: in my configuration on ppp in file /etc/ppp/peers/mts i have use the device /dev/ttyUSB0 and all works fine.

# uname -sr
Linux 2.6.32.10

Also

# ls -la /sys/devices/platform/ar71xx-ehci/usb1/1-1/1-1:1.0/
drwxr-xr-x    6 root     root            0 Jan 21 19:30 .
drwxr-xr-x    6 root     root            0 Jan 21 19:30 ..
-r--r--r--    1 root     root         4096 Jan 22 16:01 bAlternateSetting
-r--r--r--    1 root     root         4096 Jan 22 16:01 bInterfaceClass
-r--r--r--    1 root     root         4096 Jan 22 16:01 bInterfaceNumber
-r--r--r--    1 root     root         4096 Jan 22 16:01 bInterfaceProtocol
-r--r--r--    1 root     root         4096 Jan 22 16:01 bInterfaceSubClass
-r--r--r--    1 root     root         4096 Jan 22 16:01 bNumEndpoints
lrwxrwxrwx    1 root     root            0 Jan 22 16:01 driver -> ../../../../../../bus/usb/drivers/usbserial_generic
drwxr-xr-x    2 root     root            0 Jan 22 16:01 ep_02
drwxr-xr-x    2 root     root            0 Jan 22 16:01 ep_81
drwxr-xr-x    2 root     root            0 Jan 22 16:01 ep_82
-r--r--r--    1 root     root         4096 Jan 22 16:01 interface
-r--r--r--    1 root     root         4096 Jan 22 16:01 modalias
lrwxrwxrwx    1 root     root            0 Jan 22 16:01 subsystem -> ../../../../../../bus/usb
-rw-r--r--    1 root     root         4096 Jan 22 16:48 supports_autosuspend
drwxr-xr-x    3 root     root            0 Jan 21 19:32 ttyUSB0
-rw-r--r--    1 root     root         4096 Jan 22 16:01 uevent

How do you know that USB port power control will even work? Very few embedded systems implement full USB port control. I doubt that a home router supports this.

What  does the output of "lsusb -v" tell you about the host controller?

i'd guess this one:

lrwxrwxrwx    1 root     root            0 Jan 21 19:30 1-1:1.2 -> ../../../devices/platform/ar71xx-ehci/usb1/1-1/1-1:1.2

just move there and then check the vendor file to find out the manufacturer. wink

also, i could not find a /power - folder on my machine!

locutus And me to. Is this a bug?

gwirth Because the modem stays on the power. Below is `lsusb -v` for my modem.

Bus 001 Device 002: ID 16d5:6502 AnyDATA Corporation CDMA/UMTS/GPRS modem
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x16d5 AnyDATA Corporation
  idProduct          0x6502 CDMA/UMTS/GPRS modem
  bcdDevice            0.00
  iManufacturer           1 AnyDATA Corporation
  iProduct                2 AnyDATA CDMA Products
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength        21760
    bNumInterfaces          3
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              3 Data Interface
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x1000  3x 0 bytes
        bInterval             128
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x4000  1x 0 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x4000  1x 0 bytes
        bInterval               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              3 Data Interface
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x4000  1x 0 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x04  EP 4 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x4000  1x 0 bytes
        bInterval               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              3 Data Interface
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x85  EP 5 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x4000  1x 0 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x05  EP 5 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x4000  1x 0 bytes
        bInterval               0
Device Status:     0x0000
  (Bus Powered)

You do not understand. The power control is done by the USB host bus controller chip,  not by the device that you are plugging in. It's like a wall switch for a lamp; the power is controlled by the switch, not the lamp. You need to see the results of "lsusb -v" for the host controller chip to see if it supports power control. Even then it might not be the truth. What you really need is a schematic for the board.

Most embedded systems have only the USB data lines as part of their output from the System-on-Chip (SoC). The power for USB devices comes directly from the power supply, not the (internal) USB controller. Therefore there is no way to control power to the USB device, unless you do some hardware hacking like hooking up a power control (transistor, relay, etc) and drive it from a GPIO port.

AnyDATA CDMA modem has independent battery as i remember.. so will be operate without USB connection also. Try it, if you unplug and LED will be stll shining.. Suspend doesn't mean switch off.
BTW: If you switch off USB port - will be not powered modem and batteries will be not recharched..  Is there some reason why it is required?

May you can use GPIO for modem controling with some workaround..

It's definitely a worthwhile thing to do - when using a USB disk (with its own power), powering off the port will spin down the disk, but leave the interface ready to come up again. My Linux and PC machines do this - how can I get my OpenWRT machine to do this?

2gwirth OK. Is it?

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            9 Hub
  bDeviceSubClass         0 Unused
  bDeviceProtocol         1 Single TT
  bMaxPacketSize0        64
  idVendor           0x1d6b Linux Foundation
  idProduct          0x0002 2.0 root hub
  bcdDevice            2.06
  iManufacturer           3 Linux 2.6.32.10 ehci_hcd
  iProduct                2 Atheros AR91xx built-in EHCI controller
  iSerial                 1 ar71xx-ehci
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength         6400
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 Hub
      bInterfaceSubClass      0 Unused
      bInterfaceProtocol      0 Full speed (or root) hub
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval              12
Hub Descriptor:
  bLength               9
  bDescriptorType      41
  nNbrPorts             1
  wHubCharacteristic 0x0009
    Per-port power switching
    Per-port overcurrent protection
    TT think time 8 FS bits
  bPwrOn2PwrGood       10 * 2 milli seconds
  bHubContrCurrent      0 milli Ampere
  DeviceRemovable    0x00
  PortPwrCtrlMask    0xff
 Hub Port Status:
   Port 1: 0000.0103 power enable connect
Device Status:     0x0001
  Self Powered

2JaromirN No, I tried to disconnect modem and LED became off.

The key lines from the "lsusb -v" command:

  wHubCharacteristic 0x0009
    Per-port power switching
    Per-port overcurrent protection

This seems to indicate that the USB port does support power switching. I can't confirm that it is really true without the specification sheet for the AR71xx chip.

EXCEPT: The info is for the EHCI driver, which is high speed 2.0
The modem is USB 1.10 (see the output of lsusb -v for the modem: bcdUSB 1.10), which means that you will be using the OHCI driver. It looks like the OHCI driver doesn't implement power control. Source code is in:

<source_root>/target/linux/ar71xx/files/drivers/usb/host/

for the OpenWrt parts and in

<kernel_root>/drivers/usb/host/

for the main kernel.

Support for the AR71xx chips is supplied by the OpenWrt team and not the mainline kernel. You would need to ask them (the OpenWrt developers) about power control in the OHCI driver for the AR71xx chips.

ellow

How to set up usb poweroff/poweron sequence at reboot?

have a nice day,
vedro

skeletor wrote:
echo suspend >/sys/bus/usb/devices/1-2/power/level

When I do this, I get an error:

ash: write error: Invalid argument
noobody wrote:
skeletor wrote:
echo suspend >/sys/bus/usb/devices/1-2/power/level

When I do this, I get an error:

ash: write error: Invalid argument

Use "usbreset" package.

opkg update
opkg install usbreset

KHAN85 wrote:
noobody wrote:
skeletor wrote:
echo suspend >/sys/bus/usb/devices/1-2/power/level

When I do this, I get an error:

ash: write error: Invalid argument

Use "usbreset" package.

opkg update
opkg install usbreset

Thx for answering.
Installed it, what should I do now?
Sry I'm really n00by

It's a very easy command, use "usbreset" command.

usbreset PPPP:VVVV - reset by product and vendor id
usbreset BBB/DDD   - reset by bus and device number
usbreset "Product" - reset by product name

e.g.: in the command of your post ("echo suspend >/sys/bus/usb/devices/1-2/power/level") power off the usb device in bus 1 and device number 2. Then the command to reset with usbreset is:

usbreset 001/002

KHAN85 wrote:

It's a very easy command, use "usbreset" command.

usbreset PPPP:VVVV - reset by product and vendor id
usbreset BBB/DDD   - reset by bus and device number
usbreset "Product" - reset by product name

e.g.: in the command of your post ("echo suspend >/sys/bus/usb/devices/1-2/power/level") power off the usb device in bus 1 and device number 2. Then the command to reset with usbreset is:

usbreset 001/002


Ah, now I understand better. Thanks!

The discussion might have continued from here.