Git Product home page Git Product logo

amd-sfh-hid-dkms's Introduction

Archive Note

Since the current state of this driver is good-enough for my current laptop, which is nearing the end of its life cycle, I chose to archive this repo in its current state, since I will most likely no longer work on it. Please use the kernel's upstream version instead.

Kernel drivers: amd-sfh

Supported adapters:
  • AMD Sensor Fusion Hub PCIe interface

Datasheet: not publicly available.

Authors:

Description

The AMD Sensor Fusion Hub (SFH) is part of a SOC on Ryzen-based platforms. The SFH uses HID over PCIe bus. In terms of architecture it resembles the ISH. However, the major difference is that currently HID reports are being generated within the kernel driver.

Block Diagram

+-------------------------------+
|  HID User Space Applications  |
+-------------------------------+
=================================
+-------------------------------+
|      HID low-level driver     |
|   with HID report generator   |
+-------------------------------+

+-------------------------------+
|     HID client interface      |
+-------------------------------+

+-------------------------------+
|      AMD SFH PCIe driver      |
+-------------------------------+
=================================
+-------------------------------+
|       SFH MP2 Processor       |
+-------------------------------+

HID low-level driver

The driver is conceived in a multi-layer architecture. The level closest to the applications is the HID low-level (LL) driver, which implements the functions defined by the hid-core API to manage the respective HID devices and process reports. Therefor, the HID-LL-driver starts and stops the sensors as needed by invoking the exposed functions from the PCI driver (see below) and creates DMA mappings to access the DRAM of the PCI device to retrieve feature and input reports from it.

HID client interface

The aforementioned HID devices are being managed, i.e. created on probing and destroyed on removing, by the client interface used by the PCI driver. It determines the HID devices to be created on startup using the connected sensors bitmask retrieved by invoking the respective function of the PCI driver.

PCI device driver (amd-sfh)

The PCI driver is responsible for making all transactions with the chip's firmware over PCI-e. The sensors are started and stopped respectively by writing commands and, where applicable, DRAM addresses to certain device registers. The sensor's input report data can then be accessed by accessing the DRAM through DMA-mapped virtual addresses. Commands are sent to the device using CPU to PCI (C2P) mail box registers. These C2P registers are mapped in PCIe address space. Writing into the device message registers generates interrupts. The device's firmware uses DRAM interface registers to indirectly access DRAM memory. It is recommended to always write a minimum of 32 bytes into the DRAM.

Driver loading

PCI driver HID low-level driver
Loaded at boot time if device is present. Used by spawned HIDs

Data flow table

                                                +===============================================+
   +============+        Get sensor mask        |                   HID client                  |
   | PCI driver | <---------------------------- +===============================================+
   +============+    of available HID devices   | * Probe HID devices according to sensor mask. |
         ^                                      | * Start periodic polling from DRAM.           |
         |                                      +-----------------------------------------------+
Start / stop sensor on                                                 |
respective HID requests.                                               |
         |                +==============================+             |
         |                |        HID ll-driver         |             |
         +--------------- +==============================+ <-----------+
                          | Provide reports as requested |
                          | by hid-code.                 |
                          +------------------------------+

Quirks

On some systems, the sensor hub has not been programmed with information about the sensors available on the device. This would result in no sensors being activated and no HID devices being spawned by the driver. The driver already has quirks for some devices, that automatically compensate for this by DMI matching an appropriate sensor mask for the respective system. You can also activate the respective sensors manually, by loading the module amd-sfh with the kernel parameter sensor_mask=<int>. Available sensors are:

sensor index mask
accelerometer 0 BIT(0) = 1
gyroscope 1 BIT(1) = 2
magnetometer 2 BIT(2) = 4
ambient light sensor 19 BIT(19) = 524288

The values are additive, so to enable the gyroscope and the ambient light sensor, use a value of 524290.

$ cat /etc/modprobe.d/amd_sfh.conf
options amd_sfh sensor_mask=524290

amd-sfh-hid-dkms's People

Contributors

conqp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

amd-sfh-hid-dkms's Issues

Question about HP ProBook x360 435 G8

For this laptop, the module is loaded but I do not see any reaction during screen rotation. (I was testing it with Linux 5.15.16; this driver is probably newer but is also unlikely to address this issue.) I experimented with different sensor masks (supplied to modprobe) but it still does not work. Is there any way to debug it and hopefully provide some data for "quirks" in the driver?

Update: never mind, the issue is somewhere else (monitor-sensor shows accelerometer changes)

Support for Asus Vivobook Flip 14 (TM420IA-EC172T)

Hi,

I tried your driver on a Asus Vivobook Flip 14 laptop (TM420IA-EC172T) that also has an AMD SFH.

The module loads fine and an accelerometer device appears, but it does not return any value:

==> /sys/bus/iio/devices/iio:device0/current_timestamp_clock <==
realtime

==> /sys/bus/iio/devices/iio:device0/dev <==
234:0

==> /sys/bus/iio/devices/iio:device0/in_accel_hysteresis <==
1.270000

==> /sys/bus/iio/devices/iio:device0/in_accel_offset <==
0

==> /sys/bus/iio/devices/iio:device0/in_accel_sampling_frequency <==
12.500000

==> /sys/bus/iio/devices/iio:device0/in_accel_scale <==
0.098066500

==> /sys/bus/iio/devices/iio:device0/in_accel_x_raw <==
0

==> /sys/bus/iio/devices/iio:device0/in_accel_y_raw <==
0

==> /sys/bus/iio/devices/iio:device0/in_accel_z_raw <==
0

==> /sys/bus/iio/devices/iio:device0/name <==
accel_3d

==> /sys/bus/iio/devices/iio:device0/uevent <==
MAJOR=234
MINOR=0
DEVNAME=iio:device0
DEVTYPE=iio_device

I built your driver as an out-of-tree module, and I tried with and without the amd_iommu=off boot option.
By default, only an accelerometer device is created. I tried to force the other sensors with sensor_mask: it creates new devices for gyroscope and magnetometer, but they also don't return any value.

I also tried to backport the upstream driver that was merged in linux 5.11 (see https://github.com/zorun/amd-sfh-hid-backport) and it gives the same result (accelerometer device, but no value).

This is on Ubuntu 20.04 with a 5.8 kernel: Linux axoloto 5.8.0-41-generic #46~20.04.1-Ubuntu SMP Mon Jan 18 17:52:23 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Any idea on how to further debug this? Thanks!

Any plans to support Renoir (4000 series devices)

I have an HP Envy x360 with a 4700U CPU in it. This driver allows my computer to see the rotation sensor:

$ monitor-sensor
    Waiting for iio-sensor-proxy to appear
+++ iio-sensor-proxy appeared
=== Has accelerometer (orientation: undefined)
=== No ambient light sensor
=== No proximity sensor

But rotating the laptop does not produce any results. Is this a limitation which having hardware could help resolve? I am happy to provide hardware details and do some digging if it will help push this forward.

Sensors stop working when using this module, while attempting to detect lid flip

Hi, first thank you for your work. I would appreciate some assistance with the lid flip functionality to detect the tablet mode. My current expectation is to be able to receive an event that has detected that the lid has been flipped more than 180 degrees. On the Win10 side, if the lid is folded past the 180 degrees, windows detects that the tablet has entered tablet mode.

My system:

Asus ROG Flow X13 (non eGPU)
5.14.9-arch1-g14 (This is a kernel provided by the Asus Linux group)

Here is the current status of what's working;

The accelerometer is working and when I run monitor-sensor it correctly detects orientation changes. I also enabled the ambient light sensor with the sensor_mask. However this is with included amd-sfh module in my kernel, not the one provided here.

    Waiting for iio-sensor-proxy to appear
+++ iio-sensor-proxy appeared
=== Has accelerometer (orientation: normal)
=== Has ambient light sensor (value: 0.000000, unit: lux)
=== No proximity sensor
    Accelerometer orientation changed: right-up
    Accelerometer orientation changed: normal
    Accelerometer orientation changed: bottom-up
    Accelerometer orientation changed: normal

When I try to install this module, all sensors stop working. Only thing I get from dmesg is the following

[ 1526.368027] amd_sfh: loading out-of-tree module taints kernel.
[ 1526.368131] amd_sfh: module verification failed: signature and/or required key missing - tainting kernel

Going back to the default module in the kernel, I can see that it's detecting other iio devices as well;

total 0
lrwxrwxrwx 1 root root 0 Oct  7 18:24 iio:device0 -> ../../../devices/0020:1022:0001.0003/HID-SENSOR-200083.3.auto/iio:device0
lrwxrwxrwx 1 root root 0 Oct  7 18:24 iio:device1 -> ../../../devices/0020:1022:0001.0001/HID-SENSOR-200073.1.auto/iio:device1
lrwxrwxrwx 1 root root 0 Oct  7 18:24 iio:device2 -> ../../../devices/0020:1022:0001.0002/HID-SENSOR-200076.2.auto/iio:device2
lrwxrwxrwx 1 root root 0 Oct  7 18:25 iio:device3 -> ../../../devices/0020:1022:0001.0004/HID-SENSOR-200041.4.auto/iio:device3
lrwxrwxrwx 1 root root 0 Oct  7 18:24 iio:device4 -> ../../../devices/0020:1022:0001.0005/HID-SENSOR-200011.5.auto/iio:device4
lrwxrwxrwx 1 root root 0 Oct  7 18:24 trigger0 -> ../../../devices/0020:1022:0001.0003/HID-SENSOR-200083.3.auto/trigger0
lrwxrwxrwx 1 root root 0 Oct  7 18:24 trigger1 -> ../../../devices/0020:1022:0001.0001/HID-SENSOR-200073.1.auto/trigger1
lrwxrwxrwx 1 root root 0 Oct  7 18:24 trigger2 -> ../../../devices/0020:1022:0001.0002/HID-SENSOR-200076.2.auto/trigger2
lrwxrwxrwx 1 root root 0 Oct  7 18:24 trigger3 -> ../../../devices/0020:1022:0001.0005/HID-SENSOR-200011.5.auto/trigger3
lrwxrwxrwx 1 root root 0 Oct  7 18:25 trigger4 -> ../../../devices/0020:1022:0001.0004/HID-SENSOR-200041.4.auto/trigger4

dmesg does not show any entries for sfh

Here's a higly abbreviated tree that hints as to what each sensor is, and they do seem to change in order on reboot;

iio:device0
├── in_accel_x_raw
iio:device1
├── in_anglvel_x_raw
iio:device2
├── in_magn_x_raw
iio:device3
├── in_illuminance_scale
├── in_intensity_hysteresis
iio:device4
├── in_proximity_raw

Which sensor do you think is the one most likely to be responsible for emitting the lid flip event? I grabbed your python script from here and tried playing around trying to read data from them, however, nothing happened when folding the lid. When pointing to the right accelerometer device it does show the orientation changes though.

This is what I have so far. I'm pretty new to this so if you have suggestions on how to reverse engineer those sensors to try and read the events they emit, I would great appreciate it.

Thank you for your time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.