Заметка написана, как обновление статьи, поскольку в новых ядрах произошли некоторые изменения. По сути, здесь будут выдержки из документации по управлению питанием для ядра Linux.
Отключаем засыпание.
В документации написано так:
power/control
This file contains one of two words: “on” or “auto”. You can write those words to the file to change the device’s setting. “on” means that the device should be resumed and autosuspend is not allowed. (Of course, system suspends are still allowed.) “auto” is the normal state in which the kernel is allowed to autosuspend and autoresume the device. (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.)
power/autosuspend_delay_ms
This file contains an integer value, which is the number of milliseconds the device should remain idle before the kernel will autosuspend it (the idle-delay time). The default is 2000. 0 means to autosuspend as soon as the device becomes idle, and negative values mean never to autosuspend. You can write a number to the file to change the autosuspend idle-delay time.
Важным замечанием является уточнение:
Writing “-1” to power/autosuspend_delay_ms and writing “on” to power/control do essentially the same thing — they both prevent the device from being autosuspended. Yes, this is a redundancy in the API. (In 2.6.21 writing “0” to power/autosuspend would prevent the device from being autosuspended; the behavior was changed in 2.6.22. The power/autosuspend attribute did not exist prior to 2.6.21, and the power/level attribute did not exist prior to 2.6.22. power/control was added in 2.6.34, and power/autosuspend_delay_ms was added in 2.6.37 but did not become functional until 2.6.38.)
Итого, что бы отключить автозасыпаение, нужно выставить такие значения:
echo "-1" > ${path_usb}/power/autosuspend_delay_ms
echo "on" > ${path_usb}/power/control
А как же узнать этот path_usb? Это папка с указанием номера bus/port в папке /sys/bus/usb/drivers/usb.
Рассмотрим пример.
$ lsusb -t /: Bus 06.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/4p, 12M /: Bus 05.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/5p, 12M /: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/5p, 12M /: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/4p, 480M /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/5p, 480M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/5p, 480M |__ Port 3: Dev 21, If 0, Class=Communications, Driver=cdc_ether, 480M |__ Port 3: Dev 21, If 1, Class=CDC Data, Driver=cdc_ether, 480M $ ls /sys/bus/usb/drivers/usb 1-3 bind module uevent unbind usb1 usb2 usb3 usb4 usb5 usb6
В данном случае, path_usb=/sys/bus/usb/drivers/usb/1-3.
Сброс модема.
На самом деле, это не физический сброс, то есть не отключение питания, в скорее detach/hide устройства с последующим attach/unhide. Для ОС это будет выглядеть именно так, но по факту – нет. Если использовать данные с примера выше, то “сброс” будет выглядеть так:
echo '1-3' > /sys/bus/usb/drivers/usb/unbind ;sleep 3;echo '1-3' > /sys/bus/usb/drivers/usb/bind
Но если нужен именно сброс по питанию, то в документации используется такой вариант
echo 0 > power/pm_qos_no_power_off echo 0 > peer/power/pm_qos_no_power_off # if it exists echo auto > power/control # this is the default value echo auto > <child>/power/control echo 1 > <child>/power/persist # this is the default value
но у меня нет pm_qos_no_power_off