]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tools: rewrite make-autosuspend-rules.py and add udev rules
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 13 Jun 2020 15:52:41 +0000 (17:52 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 22 Jun 2020 12:45:20 +0000 (14:45 +0200)
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 #16119.

rules.d/60-autosuspend.rules [new file with mode: 0644]
rules.d/meson.build
tools/make-autosuspend-rules.py

diff --git a/rules.d/60-autosuspend.rules b/rules.d/60-autosuspend.rules
new file mode 100644 (file)
index 0000000..1f9ebef
--- /dev/null
@@ -0,0 +1,14 @@
+# do not edit this file, it will be overwritten on update
+
+ACTION!="add", GOTO="autosuspend_end"
+
+# I2C rules
+SUBSYSTEM=="i2c", ATTR{name}=="cyapa", \
+  ATTR{power/control}="on", GOTO="autosuspend_end"
+
+# Enable autosuspend if hwdb says so. Here we are relying on
+# the hwdb import done earlier based on MODALIAS.
+ENV{ID_AUTOSUSPEND}=="1", TEST=="power/control", \
+  ATTR{power/control}="auto"
+
+LABEL="autosuspend_end"
index b4684486c27627c02d18ca8afa290c98fffab435..ffa010d8e39d04de3c5ef756c47795dab1255bd7 100644 (file)
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
 rules = files('''
+        60-autosuspend.rules
         60-block.rules
         60-cdrom_id.rules
         60-drm.rules
index 3faf5f4d711a81f963b8b34ea84905aa071b0bb9..1a99e02aadd17c884048b42f1278f19df101f572 100755 (executable)
@@ -2,32 +2,23 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
 # Generate autosuspend rules for devices that have been whitelisted (IE tested)
-# by the Chromium OS team. Please keep this script in sync with:
+# by the Chromium OS team. Based on
 # https://chromium.googlesource.com/chromiumos/platform2/+/master/power_manager/udev/gen_autosuspend_rules.py
 
-import sys
 import chromiumos.gen_autosuspend_rules
 
-HWDB_FILE = """\
-%(usb_entries)s\
-%(pci_entries)s\
-"""
-
-if __name__ == '__main__':
-    if len(sys.argv) > 1:
-        sys.stdout = open(sys.argv[1], 'w')
-
-    pci_entries = ''
-    for dev_ids in chromiumos.gen_autosuspend_rules.PCI_IDS:
-        vendor, device = dev_ids.split(':')
-
-        pci_entries += ('usb:v%sp%s*\n'
-                        ' ID_AUTOSUSPEND=1\n' % (vendor, device))
-    usb_entries = ''
-    for dev_ids in chromiumos.gen_autosuspend_rules.USB_IDS:
-        vendor, device = dev_ids.split(':')
-
-        usb_entries += ('pci:v%sp%s*\n'
-                        ' ID_AUTOSUSPEND=1\n' % (vendor, device))
-
-    print(HWDB_FILE % {'pci_entries' : pci_entries, 'usb_entries': usb_entries})
+print('# pci:v<00VENDOR>d<00DEVICE> (8 uppercase hexadecimal digits twice)')
+for entry in chromiumos.gen_autosuspend_rules.PCI_IDS:
+    vendor, device = entry.split(':')
+    vendor = int(vendor, 16)
+    device = int(device, 16)
+    print(f'pci:v{vendor:08X}d{device:08X}*')
+
+print('# usb:v<VEND>p<PROD> (4 uppercase hexadecimal digits twice')
+for entry in chromiumos.gen_autosuspend_rules.USB_IDS:
+    vendor, product = entry.split(':')
+    vendor = int(vendor, 16)
+    product = int(product, 16)
+    print(f'usb:v{vendor:04X}p{product:04X}*')
+
+print(' ID_AUTOSUSPEND=1')