Отключить контроллер usb linux

Turning off a single usb device. again

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 
 -su: echo: write error: Invalid argument 
 echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms" 
 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 
 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

Источник

Включение/выключение питания USB устройств из консоли

Иногда бывают ситуации, когда нужно отключить USB флешку, сделать настройку какой-то программы и потом опять подключить для нормальной работы. Но что делать если эти действия нужно сделать на удаленном сервере, к которому у нас нет физического доступа. Можно обратиться в службу поддержки, но можно и сделать все своими силами «не отходя от кассы». Расскажу как это делается.

Допустим, наша флешка уже втыкнута в USB-порт. Первым делом нужно проверить так ли это.

sasha@sasha-desktop# lsusb Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 002 Device 002: ID 09da:000a A4 Tech Co., Ltd Port Mouse Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 004: ID 090c:1000 Feiya Technology Corp. Flash Drive Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Как видим, USB-флешка находиться на шине Bus 001. Следовательно нам нужно найти в /sys/bus/usb/devices/ соответствующее USB устройство и выключить питание.

sasha@sasha-desktop:~# cd /sys/bus/usb/devices/ sasha@sasha-desktop:/sys/bus/usb/devices# ls 1-0:1.0 1-6 1-6:1.0 2-0:1.0 2-2 2-2:1.0 3-0:1.0 4-0:1.0 5-0:1.0 usb1 usb2 usb3 usb4 usb5

Чтобы копаться в системных устройствах нужны права суперпользователя.

root@sasha-desktop:/sys/bus/usb/devices# cat 1-6/busnum 1 root@sasha-desktop:/sys/bus/usb/devices# cat 2-2/busnum 2

По скольку мы знаем, что наша USB флешка на физической шине с номером 1. Следовательно, нужно отключить питание устройства 1-6, так как именно оно отвечает за первую шину.

root@sasha-desktop:/sys/bus/usb/devices# echo suspend > 1-6/power/level

Приведенная выше команда, отключит питание устройства на лету. Проверим теперь, так ли это.

root@sasha-desktop:/sys/bus/usb/devices# lsusb Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 002 Device 002: ID 09da:000a A4 Tech Co., Ltd Port Mouse Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Как видим — устройство отключено.
После внесения нужных изменений, подключаем питание USB устройства.

root@sasha-desktop:/sys/bus/usb/devices# echo on > 1-6/power/level root@sasha-desktop:/sys/bus/usb/devices# lsusb Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 002 Device 002: ID 09da:000a A4 Tech Co., Ltd Port Mouse Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 004: ID 090c:1000 Feiya Technology Corp. Flash Drive Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Здравствуйте. Попробовал — не получилось. При вводе команды(echo suspend > 1-3/power/level) от суперпользователя «su», выдает «bash: echo: ошибка записи: Недопустимый аргумент» 🙁

Читайте также:  Linux pci ethernet driver

Здравствуйте. В данном случаи Вам нужно посмотреть включен ли параметр ядра CONFIG_USB_SUSPEND. Если Вы используете Ubuntu:

root@test-s01:~# grep CONFIG_USB_SUSPEND /boot/config-2.6.32-32-server CONFIG_USB_SUSPEND=y

root@ACCKEY:/boot# cat /boot/config-3.2.0-29-generic-pae | grep CONFIG_SUSPEND
CONFIG_SUSPEND=y
CONFIG_SUSPEND_FREEZER=y При этом из-под рута не дает изменить файл /power/level

Потому что эти два параметра не имеют никакого отношения к USB. Можете посмотреть их предназначение по ссылкам:
CONFIG_SUSPEND
CONFIG_SUSPEND_FREEZER Нам же нужен параметр CONFIG_USB_SUSPEND

не работает root@Zond:/sys/bus/usb/devices# echo suspend > 2-1/power/level bash: echo: ошибка записи: Недопустимый аргумент
root@Zond:/sys/bus/usb/devices# grep CONFIG_USB_SUSPEND /boot/config-3.8.0-23-generic
CONFIG_USB_SUSPEND=y
root@Zond:/sys/bus/usb/devices#

Из документации:
«In kernels up to 2.6.32, you could also specify «suspend», meaning that the device should remain suspended and autoresume was not allowed. This setting is no longer supported.»
Так как у Вас ядро 3.8 такой способ не прокатит. Вместо этого нужно сделать так:

echo "0" > /sys/bus/usb/devices/2-1/power/autosuspend echo "auto" > /sys/bus/usb/devices/2-1/power/level

Из документации:
«Starting with the 3.10 kernel release, dynamic PM support for USB is
present whenever the kernel was built with CONFIG_PM_RUNTIME enabled.
The CONFIG_USB_SUSPEND option has been eliminated.» В этом случаи вы вообще можете освободить(удалить) USB-устройство и потом снова включить.

# Смотрим какие есть устройства - находим нашу флешку на Bus 01 --> port 01, значит unbind для 1-1 устройства (может быть Bus01 --> port1 --> port1 - тогда 1-1.1, и т.п.) root@ubuntu:~# lsusb -t /: Bus 02.Port 1: Dev 1, Driver=uhci_hcd/2p, 12M |__ Port 1: Dev 2, If 0, Driver=usbhid, 12M |__ Port 1: Dev 2, If 1, Driver=usbhid, 12M |__ Port 2: Dev 3, If 0, Driver=hub/7p, 12M /: Bus 01.Port 1: Dev 1, Driver=ehci-pci/6p, 480M |__ Port 1: Dev 2, If 0, Driver=usb-storage, 480M # Проверяем, что есть такое устройство - /dev/sdb root@ubuntu:~# ls -1 /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sda5 /dev/sdb /dev/sdb1 # Теперь делаем undind (стопаем) root@ubuntu:~# echo '1-1' > /sys/bus/usb/drivers/usb/unbind # Проверяем что устройство пропало root@ubuntu:~# ls -1 /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sda5 root@ubuntu:~# lsusb -t 1-1: No such file or directory /: Bus 02.Port 1: Dev 1, Driver=uhci_hcd/2p, 12M |__ Port 1: Dev 2, If 0, Driver=usbhid, 12M |__ Port 1: Dev 2, If 1, Driver=usbhid, 12M |__ Port 2: Dev 3, If 0, Driver=hub/7p, 12M /: Bus 01.Port 1: Dev 1, Driver=ehci-pci/6p, 480M # Теперь включаем обратно root@ubuntu:~# echo '1-1' > /sys/bus/usb/drivers/usb/bind root@ubuntu:~# lsusb -t /: Bus 02.Port 1: Dev 1, Driver=uhci_hcd/2p, 12M |__ Port 1: Dev 2, If 0, Driver=usbhid, 12M |__ Port 1: Dev 2, If 1, Driver=usbhid, 12M |__ Port 2: Dev 3, If 0, Driver=hub/7p, 12M /: Bus 01.Port 1: Dev 1, Driver=ehci-pci/6p, 480M |__ Port 1: Dev 2, If 0, Driver=usb-storage, 480M root@ubuntu:~# ls -1 /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sda5 /dev/sdb /dev/sdb1

Так то оно так, устроство удаляется. Вот только питание с VBUS не снимается. В результате хардварный резет устройства не происходит.

Читайте также:  Grub customizer linux ubuntu

Вообще то как раз таки снимается, потому что система вообще не видит никакого устройства и не может подавать на него питание. Для простой проверки можно подключить USB мышку или же флешку с вечно светящимся диодиком. После unbind/bind ядро будет писать в syslog, что отключили/подключили новое устройство и питание будет выключено/включено, а флешка или мышка будут потухнет/засветиться.

# Делаем unbind и получаем одну строчку и дохнет лампочка на флешке/мышке Oct 30 01:00:55 ubuntu kernel: [ 1549.307234] usb 1-1: USB disconnect, device number 2 # Делаем bind и все возвращается (только номер устройства теперь будет на 1 больше - 3) Oct 30 01:04:03 ubuntu kernel: [ 1736.766528] usb 1-1: new high-speed USB device number 3 using ehci-pci Oct 30 01:04:03 ubuntu kernel: [ 1737.017562] usb 1-1: New USB device found, idVendor=1005, idProduct=b113 Oct 30 01:04:03 ubuntu kernel: [ 1737.017576] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 Oct 30 01:04:03 ubuntu kernel: [ 1737.017604] usb 1-1: Product: USB FLASH DRIVE Oct 30 01:04:03 ubuntu kernel: [ 1737.017610] usb 1-1: Manufacturer: Oct 30 01:04:03 ubuntu kernel: [ 1737.017615] usb 1-1: SerialNumber: 19831F3410D6 Oct 30 01:04:03 ubuntu kernel: [ 1737.034344] usb-storage 1-1:1.0: USB Mass Storage device detected Oct 30 01:04:03 ubuntu kernel: [ 1737.038342] scsi8 : usb-storage 1-1:1.0 Oct 30 01:04:04 ubuntu kernel: [ 1738.094835] scsi 8:0:0:0: Direct-Access USB FLASH DRIVE PMAP PQ: 0 ANSI: 0 CCS Oct 30 01:04:04 ubuntu kernel: [ 1738.102599] sd 8:0:0:0: Attached scsi generic sg2 type 0 Oct 30 01:04:04 ubuntu kernel: [ 1738.158247] sd 8:0:0:0: [sdb] 16121856 512-byte logical blocks: (8.25 GB/7.68 GiB) Oct 30 01:04:04 ubuntu kernel: [ 1738.188480] sd 8:0:0:0: [sdb] Write Protect is off Oct 30 01:04:04 ubuntu kernel: [ 1738.188492] sd 8:0:0:0: [sdb] Mode Sense: 23 00 00 00 Oct 30 01:04:04 ubuntu kernel: [ 1738.235283] sd 8:0:0:0: [sdb] No Caching mode page found Oct 30 01:04:04 ubuntu kernel: [ 1738.235334] sd 8:0:0:0: [sdb] Assuming drive cache: write through Oct 30 01:04:04 ubuntu kernel: [ 1738.501046] sd 8:0:0:0: [sdb] No Caching mode page found Oct 30 01:04:04 ubuntu kernel: [ 1738.501163] sd 8:0:0:0: [sdb] Assuming drive cache: write through Oct 30 01:04:05 ubuntu kernel: [ 1738.563731] sdb: sdb1 Oct 30 01:04:05 ubuntu kernel: [ 1738.813468] sd 8:0:0:0: [sdb] No Caching mode page found Oct 30 01:04:05 ubuntu kernel: [ 1738.815947] sd 8:0:0:0: [sdb] Assuming drive cache: write through Oct 30 01:04:05 ubuntu kernel: [ 1738.818371] sd 8:0:0:0: [sdb] Attached SCSI removable disk

Обе для выключения. Т.е. мы ставим автоматическое отключения питания (auto in ../power/level) если устройство нигде не используется (т.е. устройство в idle состоянии). Чтобы вручную задать состояние idle, нужно впихнуть «0» в ../power/autosuspend

Читайте также:  Linux amd graphics card

«When the counter is > 0 then the interface is deemed to be busy, and the kernel will not
autosuspend the interface’s device. When the usage counter is = 0 then the interface is
considered to be idle, and the kernel may autosuspend the device.»

Источник

disable a usb port in linux

I’ve searched a lot for an answer to this, but the closest I can get to finding a solution is this, but it doesn’t work for me. Here’s my system:

# uname -a Linux vin 4.4.0-1-amd64 #1 SMP Debian 4.4.6-1 (2016-03-17) x86_64 GNU/Linux 

The problem is this: one of my USB ports appears to be dead. Any program that tries to read «/sys/bus/usb/devices/usb1/descriptors» will cause the program to hang in an unkillable state. Unfortunately, a lot of software seems to want to access USB1, including chrome and blender, which is why this is bugging me so much. When I invoke those programs with strace, they always hang at the moment they try to open «/sys/bus/usb/devices/usb1/descriptors». I’ve tried things like «echo suspend > /sys/bus/usb/devices/usb1/power/level» but it’s no good — the command simply hangs like the others. I tried using the hubpower code mentioned in the post linked above, but it likewise seems to just hang like the others. I tried powering down the whole system and opening up the computer itself to disconnect the USB port directly, but the whole collection of USB ports (there are a lot of them) seem very tightly integrated with the motherboard, and I couldn’t see a way to unplug anything. Granted, I don’t have tons of experience plugging wires into and out of motherboards. If the only hope is to do it that way, I could hopefully manage it. I tried going into the BIOS and disabling all the USB ports except one; and then disabling all except the next; and the next; and so on, to see which one was the problem. But it didn’t seem to have any effect — Linux still was able to recognize the ports well enough to use my USB mouse and keyboard. Linux didn’t seem to care what the BIOS configuration was. The thing that occurs to me is that there may be some way to tell the Linux kernel to ignore USB1, but to do so without actually attempting to interact with USB1 (since that seems to cause the unkillable hang). But I don’t know how to do that.

Источник

Оцените статью
Adblock
detector