Skip to content

Draft: Qualcomm Sensor Manager support (MSM8996 & Co. SSC)

Yassine Oudjana requested to merge msm8996-mainline/pmaports:qcom-smgr into master

Sensor Manager is a QMI service available on several Qualcomm SoCs which exposes available sensors and allows for getting raw data from them. This service is provided by either:

  • SSC (Snapdragon Sensor Core): Also known as SLPI (Sensor Low Power Island). Has its own set of pins and peripherals to which sensors are connected. These peripherals are generally inaccessible from the AP, meaning sensors need to be operated exclusively through SSC. The only SoCs in this category are MSM8996 and MSM8998.
  • ADSP (Audio DSP): Shares pins and peripherals with the AP. At least on some devices these pins could be set to GPIO which allows the AP to access sensors by bit-banging their interfaces. Some SoCs in this category are MSM8953, MSM8974 and MSM8226.

Before Sensor Manager becomes accessible, another service known as Sensor Registry needs to be provided by the AP. The remote processor that provides Sensor Manager will then request data from it, and once that process is done, will expose several services including Sensor Manager.

Note that SDM845 and later don't provide Sensor Manager, opting for an entirely different interface instead. This MR is therefore unrelated to !4050 (merged)

Details

Supporting sensors on SoCs with Sensor Manager involves the following:

  • Sensor Registry server: Included in this MR (sns-reg).
  • Sensor Manager client: The biggest and most important component. Located in the kernel and summarized in these commits:

The registry

The sensor registry consists of keys organized in groups with a specific structure. Sensor registry clients (i.e. SSC) request data in groups, and the server has to obtain the values of keys belonging to the requested group then send them in the structure and order the client expects.

In Android, the individual key-value pairs are stored in plain text in /*/etc/sensors/sensor_def_qcomdev.conf. A proprietary daemon named sensors.qti reads that file and generates /persist/sensors/sns.reg, which contains the values in binary format. Some devices don't ship with a working sensor_def_qcomdev.conf and rely on the sns.reg file they ship with.

sns-reg reads key-value pairs from /etc/sns-reg.d/registry.conf. This file can either be sensor_def_qcomdev.conf unmodified, or if a working one isn't available, a generator tool is available in the sns-reg repository to generate a plain text registry from a working sns.reg.

Current status

Auto-rotation with the accelerometer works on the Xiaomi Mi Note 2 (MSM8996).

iio-sensor-proxy currently supports IIO devices that provide a raw read interface, as well as ones that have triggered buffers. However, it doesn't support devices with trigger-less buffers that also don't have a raw read interface. Therefore, this MR is necessary to support Sensor Manager accelerometers in iio-sensor-proxy: https://gitlab.freedesktop.org/hadess/iio-sensor-proxy/-/merge_requests/368

Call for testing

Anyone with one of the SoCs mentioned above or another SoC with Sensor Manager is welcome to test this.

Steps for testing:

  • Obtain registry.conf as explained above, then place it in /etc/sns-reg.d.
  • Run the Sensor Registry server, then look for the Sensor Manager service (ID 256) using qrtr-lookup.
  • If found, note the version and instance ID. Stop here and report if not found; the kernel driver will do nothing without the Sensor Manager service being available.
  • Apply kernel patches.
  • If the version and instance ID found earlier are different from what is currently in the QRTR match table of the driver (version 1, instance 50), add a new entry to the table.
  • Boot with patched kernel and run the Sensor Registry server. With driver debug messages enabled, a list of available sensors will be printed in the kernel log:
[  482.700894] smgr 9-18: Getting available sensors
[  482.779657] smgr 9-18: 0x00,0: STMicroelectronics LSM6DSM Accelerometer
[  482.783388] smgr 9-18: 0x0a,0: STMicroelectronics LSM6DSM Gyroscope
[  482.784239] smgr 9-18: 0x14,0: AKM AK09915 Magnetometer
[  482.785245] smgr 9-18: 0x28,0: Capella CM36686 PRX
[  482.785257] smgr 9-18: 0x28,1: Capella CM36686 ALS
[  482.786140] smgr 9-18: 0x1e,0: BOSCH BMP280 Pressure
[  482.786152] smgr 9-18: 0x1e,1: BOSCH BMP280 Temperature
[  482.787021] smgr 9-18: 0x50,0: Xiaomi hall Xiaomi_Hall_Dummy
  • The accelerometer can be tested either with iio_generic_buffer, or with iio-sensor-proxy after applying the MR mentioned earlier.
Edited by Yassine Oudjana

Merge request reports