]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: hwdb: Match iio sensors based on their label
authorAlper Nebi Yasak <alpernebiyasak@gmail.com>
Thu, 18 Aug 2022 14:27:22 +0000 (17:27 +0300)
committerAlper Nebi Yasak <alpernebiyasak@gmail.com>
Thu, 18 Aug 2022 18:17:19 +0000 (21:17 +0300)
The IIO subsystem exposes a 'label' sysfs file to help userspace better
identify its devices [1]. Standardized labels include the sensor type
along with its location, including 'accel-base' and 'accel-display'.

Most Chrome OS boards have two accelerometers that are indistinguishable
except for this label (or a 'location' sysfs file before Linux v6.0),
and need different mounting matrix corrections based on their location.

Add a udev rule that matches hwdb entries using this label, so we can
correct both accelerometers on these devices with hwdb entries. The
existing rules and hwdb entries are not modified to keep potential
out-of-tree entries working, but new entries in this form will override
existing ones. Also add currently standardized labels to parse-hwdb.py.

[1] https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio

hwdb.d/60-sensor.hwdb
hwdb.d/parse_hwdb.py
rules.d/60-sensor.rules

index 7978675943c63bca5a980031070a1dec42246314..b8331243c629f3c48914d4361875f71db9575567 100644 (file)
@@ -4,10 +4,13 @@
 #   60-sensor.rules
 #
 # Match string formats:
+# sensor:<label>:modalias:<parent modalias pattern>:dmi:<dmi pattern>
 # sensor:modalias:<parent modalias pattern>:dmi:<dmi pattern>
 #
 # The device modalias can be seen in the `modalias` file of the sensor parent,
+# and the device label can be seen in the `label` file of the sensor,
 # for example:
+#   cat /sys/`udevadm info -q path -n /dev/iio:device0`/label
 #   cat /sys/`udevadm info -q path -n /dev/iio:device0`/../modalias
 #
 # The full DMI string of the running machine can be read from
index 7bad559699b0e99789501cbc5762e1ec03dbb979..61932fb0185b766456ee3534424eccd7c5abca64 100755 (executable)
@@ -72,7 +72,20 @@ TYPES = {'mouse':    ('usb', 'bluetooth', 'ps2', '*'),
          'touchpad': ('i8042', 'rmi', 'bluetooth', 'usb'),
          'joystick': ('i8042', 'rmi', 'bluetooth', 'usb'),
          'keyboard': ('name', ),
-         'sensor':   ('modalias', ),
+         'sensor':   ('modalias',
+                      'accel-base',
+                      'accel-display',
+                      'accel-camera',
+                      'proximity-palmrest',
+                      'proximity-palmrest-left',
+                      'proximity-palmrest-right',
+                      'proximity-lap',
+                      'proximity-wifi',
+                      'proximity-lte',
+                      'proximity-wifi-lte',
+                      'proximity-wifi-left',
+                      'proximity-wifi-right',
+                      ),
          'ieee1394-unit-function' : ('node', ),
          'camera':   ('usb'),
         }
index 7b9b7d2887bb6673f873c89c1f4d47245a9d6f11..99b8f5fc7aed795bb5ade6ac44f8def0834a2685 100644 (file)
@@ -2,6 +2,11 @@
 
 ACTION=="remove", GOTO="sensor_end"
 
+# device matching the sensor's label, name and the machine's DMI data for IIO devices
+SUBSYSTEM=="iio", KERNEL=="iio*", SUBSYSTEMS=="usb|i2c|platform", ATTR{label}!="", \
+  IMPORT{builtin}="hwdb 'sensor:$attr{label}:modalias:$attr{modalias}:$attr{[dmi/id]modalias}'", \
+  GOTO="sensor_end"
+
 # device matching the sensor's name and the machine's DMI data for IIO devices
 SUBSYSTEM=="iio", KERNEL=="iio*", SUBSYSTEMS=="usb|i2c|platform", \
   IMPORT{builtin}="hwdb 'sensor:modalias:$attr{modalias}:$attr{[dmi/id]modalias}'", \