Skip to content

Commit 79dc5d3

Browse files
committed
tools: rewrite make-autosuspend-rules.py and add udev rules
Concatenating strings is not a very efficient approach. And in this case fully unnecessary. We also need some rules to make use of those hwdb entries. PCI needs to be 8 characters, not 4. And we need to use uppercase hexadecimal for both. With udev rules this made no difference, but hwdb match is case sensitive. Fixes systemd#16119.
1 parent 876c75f commit 79dc5d3

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

rules.d/60-autosuspend.rules

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# do not edit this file, it will be overwritten on update
2+
3+
ACTION!="add", GOTO="autosuspend_end"
4+
5+
# I2C rules
6+
SUBSYSTEM=="i2c", ATTR{name}=="cyapa", \
7+
ATTR{power/control}="on", GOTO="autosuspend_end"
8+
9+
# Enable autosuspend if hwdb says so. Here we are relying on
10+
# the hwdb import done earlier based on MODALIAS.
11+
ENV{ID_AUTOSUSPEND}=="1", TEST=="power/control", \
12+
ATTR{power/control}="auto"
13+
14+
LABEL="autosuspend_end"

rules.d/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: LGPL-2.1+
22

33
rules = files('''
4+
60-autosuspend.rules
45
60-block.rules
56
60-cdrom_id.rules
67
60-drm.rules

tools/make-autosuspend-rules.py

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,23 @@
22
# SPDX-License-Identifier: LGPL-2.1+
33

44
# Generate autosuspend rules for devices that have been whitelisted (IE tested)
5-
# by the Chromium OS team. Please keep this script in sync with:
5+
# by the Chromium OS team. Based on
66
# https://chromium.googlesource.com/chromiumos/platform2/+/master/power_manager/udev/gen_autosuspend_rules.py
77

8-
import sys
98
import chromiumos.gen_autosuspend_rules
109

11-
HWDB_FILE = """\
12-
%(usb_entries)s\
13-
%(pci_entries)s\
14-
"""
15-
16-
if __name__ == '__main__':
17-
if len(sys.argv) > 1:
18-
sys.stdout = open(sys.argv[1], 'w')
19-
20-
pci_entries = ''
21-
for dev_ids in chromiumos.gen_autosuspend_rules.PCI_IDS:
22-
vendor, device = dev_ids.split(':')
23-
24-
pci_entries += ('usb:v%sp%s*\n'
25-
' ID_AUTOSUSPEND=1\n' % (vendor, device))
26-
usb_entries = ''
27-
for dev_ids in chromiumos.gen_autosuspend_rules.USB_IDS:
28-
vendor, device = dev_ids.split(':')
29-
30-
usb_entries += ('pci:v%sp%s*\n'
31-
' ID_AUTOSUSPEND=1\n' % (vendor, device))
32-
33-
print(HWDB_FILE % {'pci_entries' : pci_entries, 'usb_entries': usb_entries})
10+
print('# pci:v<00VENDOR>d<00DEVICE> (8 uppercase hexadecimal digits twice)')
11+
for entry in chromiumos.gen_autosuspend_rules.PCI_IDS:
12+
vendor, device = entry.split(':')
13+
vendor = int(vendor, 16)
14+
device = int(device, 16)
15+
print(f'pci:v{vendor:08X}d{device:08X}*')
16+
17+
print('# usb:v<VEND>p<PROD> (4 uppercase hexadecimal digits twice')
18+
for entry in chromiumos.gen_autosuspend_rules.USB_IDS:
19+
vendor, product = entry.split(':')
20+
vendor = int(vendor, 16)
21+
product = int(product, 16)
22+
print(f'usb:v{vendor:04X}p{product:04X}*')
23+
24+
print(' ID_AUTOSUSPEND=1')

0 commit comments

Comments
 (0)