Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning off a single usb device... again

Tags:

debian

usb

I know that this topic has been discussed many times, but none of the answers helped me. For the record, i'm running Debian.

The deal is: I bought an usb powered led lamp, which is very simple and doesn't even have an on/off switch (it works and is always on). I want to be able to turn it on/off via command line. Here's what i tried:

    echo on > /sys/bus/usb/devices/usb1/power/level       # turn on
    echo suspend > /sys/bus/usb/devices/usb1/power/level  # turn off

which is what i've found on many forums. Turning "on" works, but "suspending" yields

    -su: echo: write error: Invalid argument

for every usbN. I also tried

    echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms"

which doesn't give an error, but also doesn't do anything (again, for every usbN)

trying

    echo "usb1" > /sys/bus/usb/drivers/usb/unbind

works only for more "inteligent" devices, like the keyboard, the mouse, or the usb wifi card. What i mean is that only tyhose devices are turned off, other usbN don't give an error, but the lamp never goes off.

the contents of /sys/bus/usb/devices/ are

    1-0:1.0 1-1:1.0 1-2:1.0 1-2:1.2 2-0:1.0 4-0:1.0 4-1:1.0 6-0:1.0 8-0:1.0 8-2:1.0 usb2 usb4 usb6 usb8
    1-1 1-2 1-2:1.1 1-2:1.3 3-0:1.0 4-1 5-0:1.0 7-0:1.0 8-2 usb1 usb3 usb5 usb7

i tried to do

    echo device_name > /sys/bus/usb/drivers/usb/unbind

with every single one of them, but only the devices usbN and N-M react, the ones of the form n-m:x.y yield

    tee: /sys/bus/usb/drivers/usb/bind: No such device

(i tried putting in, for instance, "1-0:1.0", "1-0\:1.0" and "1-0\:1.0", all gave the same result).

One last thing, what is shown after executing

    lsusb -t

does not change when i plug or unplug the lamp.

Any ideas?

like image 839
user2772761 Avatar asked Sep 12 '13 13:09

user2772761


People also ask

Does unplugging USB damage?

Detaching the USB cable while file transfer is in progress can damage your computer and/or Portable Series External Hard Drive.

Can you disable certain USB ports?

Enable or Disable Usb Ports Through Device Manager Right-click on the “Start” button on the taskbar and select “Device Manager”. Expand USB Controllers. Right-click on all entries, one after another, and click “Disable Device”.

How do I turn off a USB device in Windows 10?

1 Open Device Manager. 2 Expand the Universal Serial Bus Controllers option. 3 Double-click on the USB device to enter the Properties window. 4 Switch to the Power Management tab. 5 Uncheck Allow the computer to turn off this device to save power. 6 Press OK to keep the change.

How do I Stop my USB port from disconnecting?

USB Keeps Disconnecting FAQ. 1 Open Device Manager. 2 Expand the Universal Serial Bus Controllers option. 3 Double-click on the USB device to enter the Properties window. 4 Switch to the Power Management tab. 5 Uncheck Allow the computer to turn off this device to save power. 6 Press OK to keep the change. Can a USB port go bad?

How to Disable USB selective suspend in Windows 10?

Press Win + X and select Device Manager. Expand the Universal Serial Bus controllers section, right-click on your USB driver, and select Properties. Uncheck the Allow the computer to turn off this device to save power box and press OK. Restart your PC to save these changes. 4. Disable the USB Selective Suspend Setting

How do I disable/enable a single USB port?

Re: How do I disable/enable a single USB port only? The easiest way to turn off a single USB port might be to just install a mechanical switch. Re: How do I disable/enable a single USB port only?


2 Answers

Turn off device ID 2-1:

echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/unbind

Turn device ID 2-1 back on:

echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/bind

In my case, using device ID 2-1 controls power to my usb stick, and as a consequence controls the light.

  • TIP: If they work for you in Debian, create an alias for them to make life easier for you later.

Hope this helps, Su

like image 95
user3534136 Avatar answered Sep 22 '22 13:09

user3534136


If all you want to do is reset a USB device to fix it once it gets into a broken state, then using the bind/unbind usbfs special files can be a bit of a pain (since device IDs can change, and they're a bit tricky to identify precisely if you don't want to rebind other devices). In this case I've found it much easier to use the vendor and product IDs given by lsusb with usb_modeswitch. For example, if I identify my wireless adapter using:

$ lsusb
Bus 001 Device 042: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
Bus 001 Device 035: ID 0409:005a NEC Corp. HighSpeed Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I can then reset the wireless adapter using:

$ sudo usb_modeswitch -v 0x7392 -p 0x7811 --reset-usb

If you have more than one device attached with the same vendor and product IDs then usb_modeswitch provides bus and device number flags. For the wireless adapter example above I'd add -b 1 -g 42 to the flags.

like image 24
jwatt Avatar answered Sep 23 '22 13:09

jwatt