/
tlp-usb-udev.in
42 lines (32 loc) · 1.18 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
#!/bin/sh
# tlp - handle added usb devices
#
# Copyright (c) 2019 Thomas Koch <linrunner at gmx.net> and others.
# This software is licensed under the GPL v2 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@/20-tlp-func-usb; do
. $lib
done
# --- MAIN
# read config
read_defaults
# exit if TLP or autosuspend disabled
: ${USB_AUTOSUSPEND:=${DEFAULT_USB_AUTOSUSPEND}}
check_tlp_enabled 0 && [ "$USB_AUTOSUSPEND" = "1" ] || exit 0
# 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
# do exit if mode 1 and no startup completion flag
[ "$X_TLP_USB_MODE" = "1" ] && [ ! -f $RUNDIR/$USB_DONE ] && exit 0
# handle device
usb_suspend_device "/sys$1" "udev"
exit 0