Skip to content

udev: hwdb: Add orientation quirk for base-mounted accelerometers on Chromebooks#24353

Merged
yuwata merged 3 commits intosystemd:mainfrom
alpernebbi:hwdb-cros-ec-accel-base
Aug 19, 2022
Merged

udev: hwdb: Add orientation quirk for base-mounted accelerometers on Chromebooks#24353
yuwata merged 3 commits intosystemd:mainfrom
alpernebbi:hwdb-cros-ec-accel-base

Conversation

@alpernebbi
Copy link
Copy Markdown
Contributor

This is a follow-up to #24276, which added generic hwdb entries for cros-ec-accel devices. Also see the post-merge comments to that. In short, the existing hwdb fragment is correct for the display-mounted accelerometer, but not for the base-mounted one. The only way to distinguish the two devices is a location sysfs file before Linux v6.0, and a label file after that version.

The iio device label looks like it would be useful for similar cases later on, so the first commit adds a rule to match it in the hwdb entries. The second commit adds entries in this style for cros-ec-accel. The third commit tries to import these rules based on the location file for older kernels, though I guess it's not essential and can be dropped if you want to keep driver-specific things out of the rules.

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
The base-mounted accelerometer on Chromebooks return values same as the
display when the lid angle is 180 degrees, instead of when the lid is
closed. To match userspace expectations we must further rotate the
existing accelerometer mounting matrix by 180 degrees around the X axis:

    [[-1,  0,  0],    [[ 1,  0,  0],    [[-1,  0,  0],
     [ 0, -1,  0],  X  [ 0, -1,  0],  =  [ 0,  1,  0],
     [ 0,  0, -1]]     [ 0,  0, -1]]     [ 0,  0,  1]]

A previous commit lets us distinguish between the two cros-ec-accel
devices on these boards by their 'label' sysfs file. Add hwdb entries
that make base-mounted accelerometers use this correct matrix, and
display-mounted ones use the existing one.

Note that the cros-ec-accel drivers use 'label' only since Linux v6.0.
The old match strings are not removed to support older kernels, even
though they are only correct for the display-mounted sensor.
The cros-ec-accel devices report their mounting location by the 'label'
sysfs file only since Linux v6.0. With earlier kernels, a nonstandard
'location' file reports this, but slightly differently (lid instead of
display) [1].

Add udev rules to import the correct hwdb entries based on this
'location' file for cros-ec-accel devices, so that the base-mounted
accel matrix has the correct value for older kernels as well.

[1] https://kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio-cros-ec
@alpernebbi alpernebbi force-pushed the hwdb-cros-ec-accel-base branch from 4287937 to ac3c031 Compare August 18, 2022 18:18
@alpernebbi
Copy link
Copy Markdown
Contributor Author

parse-hwdb was failing, added currently standardized iio labels to its grammar.

@amstan
Copy link
Copy Markdown

amstan commented Aug 18, 2022

You are on a roll! Looks good to me.

Reviewed-by: Alexandru Stan <[email protected]>

@gwendalg, any concerns?

@github-actions github-actions bot added the hwdb label Aug 18, 2022
@gwendalcr
Copy link
Copy Markdown
Contributor

Reviewed-by: Gwendal Grignou <[email protected]>

Thanks,
Gwendal.

@yuwata yuwata merged commit 0b755a9 into systemd:main Aug 19, 2022
@alpernebbi alpernebbi deleted the hwdb-cros-ec-accel-base branch August 19, 2022 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants