OLD | NEW |
---|---|
1 #! /bin/sh | 1 #! /bin/sh |
2 # | 2 # |
3 # Laptop mode tools module: usb-autosuspend. | 3 # Laptop mode tools module: usb-autosuspend. |
4 # | 4 # |
5 | 5 |
6 blacklisted() { | 6 blacklisted() { |
7 for usbid in $AUTOSUSPEND_USBID_BLACKLIST; do | 7 for usbid in $AUTOSUSPEND_USBID_BLACKLIST; do |
8 if ! echo $usbid | grep -q ':'; then | 8 if ! echo $usbid | grep -q ':'; then |
9 log "MSG" "WARNING: Invalid entry \"$usbid\" in AUTOSUSP END_USBID_BLACKLIST." | 9 log "MSG" "WARNING: Invalid entry \"$usbid\" in AUTOSUSP END_USBID_BLACKLIST." |
10 fi | 10 fi |
11 vendor=$(echo $usbid | cut -d: -f1) | 11 vendor=$(echo $usbid | cut -d: -f1) |
12 product=$(echo $usbid | cut -d: -f2) | 12 product=$(echo $usbid | cut -d: -f2) |
13 grep -qi $vendor $1/idVendor 2>/dev/null\ | 13 grep -qi $vendor $1/idVendor 2>/dev/null\ |
14 && grep -qi $product $1/idProduct 2>/dev/null\ | 14 && grep -qi $product $1/idProduct 2>/dev/null\ |
15 && return 0 | 15 && return 0 |
16 done | 16 done |
17 return 1 | 17 return 1 |
18 } | 18 } |
19 | 19 |
20 # Check whether the USB driver type is blacklisted | |
21 blacklisted_by_type() { | |
22 device=$1 | |
23 device_base=`basename $device` | |
24 for driver_type in $AUTOSUSPEND_USBTYPE_BLACKLIST; do | |
25 if grep -q DRIVER=$driver_type $device/uevent; then | |
26 return 0 | |
27 fi | |
28 # Check child devices as well. The actual driver type is | |
29 # listed in a child device, not the top-level device. | |
30 for subdevice in $device/$device_base*; do | |
31 if [ -f $subdevice/uevent ]; then | |
32 if grep -q DRIVER=$driver_type\ | |
33 $subdevice/uevent; then | |
34 return 0 | |
35 fi | |
36 fi | |
37 done | |
38 done | |
39 | |
Benson Leung
2010/10/01 20:45:39
Delete empty line.
| |
40 return 1 | |
41 } | |
42 | |
43 | |
20 if [ x$CONTROL_USB_AUTOSUSPEND = x1 ] ; then | 44 if [ x$CONTROL_USB_AUTOSUSPEND = x1 ] ; then |
21 if [ $ON_AC -eq 1 ]; then | 45 if [ $ON_AC -eq 1 ]; then |
22 if [ "$ACTIVATE" -eq 1 ]; then | 46 if [ "$ACTIVATE" -eq 1 ]; then |
23 SUSPEND_USB_DEVICES="$LM_AC_SUSPEND_USB" | 47 SUSPEND_USB_DEVICES="$LM_AC_SUSPEND_USB" |
24 else | 48 else |
25 SUSPEND_USB_DEVICES="$NOLM_AC_SUSPEND_USB" | 49 SUSPEND_USB_DEVICES="$NOLM_AC_SUSPEND_USB" |
26 fi | 50 fi |
27 else | 51 else |
28 SUSPEND_USB_DEVICES="$BATT_SUSPEND_USB" | 52 SUSPEND_USB_DEVICES="$BATT_SUSPEND_USB" |
29 fi | 53 fi |
30 | 54 |
31 if [ x$SUSPEND_USB_DEVICES = x1 ]; then | 55 if [ x$SUSPEND_USB_DEVICES = x1 ]; then |
32 if [ -f /sys/module/usbcore/parameters/autosuspend ]; then | 56 if [ -f /sys/module/usbcore/parameters/autosuspend ]; then |
33 echo $AUTOSUSPEND_TIMEOUT > /sys/module/usbcore/parameters/autosus pend | 57 echo $AUTOSUSPEND_TIMEOUT > /sys/module/usbcore/parameters/autosus pend |
34 log "VERBOSE" "Enabling autosuspend mode for USBCORE Controller, w ith timeout $AUTOSUSPEND_TIMEOUT." | 58 log "VERBOSE" "Enabling autosuspend mode for USBCORE Controller, w ith timeout $AUTOSUSPEND_TIMEOUT." |
35 else | 59 else |
36 log "VERBOSE" "Not enabling autosuspend mode for USBCORE Controlle r. Not Supported" | 60 log "VERBOSE" "Not enabling autosuspend mode for USBCORE Controlle r. Not Supported" |
37 fi | 61 fi |
38 if [ -d /sys/bus/usb/devices ]; then | 62 if [ -d /sys/bus/usb/devices ]; then |
39 for usb_device in /sys/bus/usb/devices/*; | 63 for usb_device in /sys/bus/usb/devices/*; |
40 do | 64 do |
41 usb_device=`basename $usb_device`; | 65 usb_device=`basename $usb_device`; |
42 if ! blacklisted /sys/bus/usb/devices/$usb_device; then | 66 if ! blacklisted /sys/bus/usb/devices/$usb_device; then |
67 if ! blacklisted_by_type /sys/bus/usb/devices/$usb_devic e; then | |
43 if [ -f /sys/bus/usb/devices/$usb_device/power/autosus pend ]; then | 68 if [ -f /sys/bus/usb/devices/$usb_device/power/autosus pend ]; then |
44 echo $AUTOSUSPEND_TIMEOUT > /sys/bus/usb/devic es/$usb_device/power/autosuspend; | 69 echo $AUTOSUSPEND_TIMEOUT > /sys/bus/usb/devic es/$usb_device/power/autosuspend; |
45 log "VERBOSE" "Enabling auto suspend mode for usb device $usb_device." | 70 log "VERBOSE" "Enabling auto suspend mode for usb device $usb_device." |
46 else | 71 else |
47 log "VERBOSE" "Not enabling auto suspend mode for usb device $usb_device" | 72 log "VERBOSE" "Not enabling auto suspend mode for usb device $usb_device" |
48 fi | 73 fi |
49 | 74 |
50 if [ -f /sys/bus/usb/devices/$usb_device/power/level ] ; then | 75 if [ -f /sys/bus/usb/devices/$usb_device/power/level ] ; then |
51 echo "auto" > /sys/bus/usb/devices/$usb_device /power/level; | 76 echo "auto" > /sys/bus/usb/devices/$usb_device /power/level; |
52 log "VERBOSE" "Enabling auto power level for u sb device $usb_device." | 77 log "VERBOSE" "Enabling auto power level for u sb device $usb_device." |
53 else | 78 else |
54 log "VERBOSE" "Not enabling auto power level f or usb device $usb_device" | 79 log "VERBOSE" "Not enabling auto power level f or usb device $usb_device" |
55 fi | 80 fi |
81 else | |
82 log "VERBOSE" "Device $usb_device has blacklisted driv er type, skipping auto suspend." | |
83 fi | |
56 else | 84 else |
57 log "VERBOSE" "USB device $usbid is in the autosuspend blacklist." | 85 log "VERBOSE" "USB device $usbid is in the autosuspend blacklist." |
58 fi | 86 fi |
59 done | 87 done |
60 else | 88 else |
61 # This will rarely happen. | 89 # This will rarely happen. |
62 log "VERBOSE" "There are no USB devices." | 90 log "VERBOSE" "There are no USB devices." |
63 fi | 91 fi |
64 else | 92 else |
65 AUTOSUSPEND_TIMEOUT=0 | 93 AUTOSUSPEND_TIMEOUT=0 |
(...skipping 23 matching lines...) Expand all Loading... | |
89 done | 117 done |
90 else | 118 else |
91 # This will rarely happen. | 119 # This will rarely happen. |
92 log "VERBOSE" "There are no USB devices." | 120 log "VERBOSE" "There are no USB devices." |
93 fi | 121 fi |
94 fi | 122 fi |
95 else | 123 else |
96 log "VERBOSE" "USB autosuspend is disabled." | 124 log "VERBOSE" "USB autosuspend is disabled." |
97 fi | 125 fi |
98 | 126 |
OLD | NEW |