-
Notifications
You must be signed in to change notification settings - Fork 132
/
tlp-usb-udev.in
65 lines (52 loc) · 1.87 KB
/
tlp-usb-udev.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
# tlp - handle added usb devices
#
# Copyright (c) 2024 Thomas Koch <linrunner at gmx.net> and others.
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Remark: the calling udev rule is triggered for "base" devices only,
# not for the corresponding subdevices.
# --- Source libraries
for lib in @TLP_TLIB@/tlp-func-base @TLP_FLIB@/15-tlp-func-disk @TLP_FLIB@/20-tlp-func-usb; do
# shellcheck disable=SC1090
. "$lib" || exit 70
done
# --- MAIN
# shellcheck disable=SC2034
_bgtask=1
# read configuration: quit on error, trace allowed
read_config 1 0
# quit if TLP disabled
check_tlp_enabled || do_exit 0
if [ "$X_USB_ENV_TRACE" = "1" ]; then
echo_debug "usb" "tlp_usb_udev.env = $(printenv)"
fi
case "$1" in
usb) # usb devices in general
[ "$USB_AUTOSUSPEND" = "1" ] || do_exit 0
# quit if usb autosuspend disabled
# USB autosuspend has two principal operation modes:
#
# Mode 1 (optional):
# - System startup is handled by tlp-functions:set_usb_suspend()
# - Startup completion is signaled by "flag file" $USB_DONE
# - Newly added devices are handled by this udev script
# - Mode 1 is enabled by the private config variable X_TLP_USB_MODE=1
#
# Mode 2 (default):
# - Everything - including system startup, but not shutdown - is handled by this udev script
# quit if mode 1 and no startup completion flag
[ "$X_TLP_USB_MODE" = "1" ] && ! check_run_flag "$USB_DONE" && do_exit 0
# handle device
usb_suspend_device "/sys$2" "udev"
;;
disk) # (s)ata disks attached via usb
get_power_mode; pwrmode=$?
dev="${2##*/block/}"
set_ahci_disk_runtime_pm $pwrmode "$dev"
set_disk_apm_level $pwrmode "$dev"
set_disk_spindown_timeout $pwrmode "$dev"
set_disk_iosched "$dev"
;;
esac
do_exit 0