Qualcomm Snapdragon Sensor Core
The Qualcomm Snapdragon Sensor Core (SSC), or Sensor Low Power Island (SLPI), is a digital signal processor (DSP) used by Qualcomm SoCs that is responsible for interfacing with all sensors of a phone such as the proximity sensor, light sensor, accelerometer, gyroscope, and more. The SoC hypervisor prohibits accessing the sensors directly, so we have to interface with this component in order to get the sensors to work on these SoCs.
Two generations of SSC exist:
- Snapdragon 835 (MSM8998) & co.: QMI-only "Sensor Manager" based SSC.
- Support was being worked on in pmaports!4118 (closed)
- With this generation it is often possible to access the sensors directly anyway by bit-banging I2C
- Snapdragon 845 (SDM845) and newer: Protobuf-based SSC encapsulated in QMI.
- Support was merged in pmaports!4050 \o/
Development details
Generation 1: MSM8998
DTS
SLPI is just a regular DSP, existing drivers in the mainline kernel can be re-used to boot it.
Details: https://emainline.gitlab.io/2021/10/06/Unlocking_SSC_P1.html
Communication
All communication with the host happens with QMI messages.
The SLPI pops up as a QMI service which you can list with qrtr-lookup
$ qrtr-lookup
Service Version Instance Node Port
66 1 20 9 4 Service registry notification service
Several messages exist to retrieve sensors, their values, configure them, etc. Sensors must be initialized first before they give out data.
Details: https://emainline.gitlab.io/2022/04/08/Unlocking_SSC_P2.html
Generation 2: SDM845 or later
DTS
SLPI is just a regular DSP, existing drivers in the mainline kernel can be re-used to boot it.
Communication
While generation 1 uses only QMI, generation 2 uses Google's ProtoBuf for communicating.
ProtoBuf messages are encapsulated into QMI messages.
The SLPI pops up as a QMI service which you can list with qrtr-lookup:
$ qrtr-lookup
Service Version Instance Node Port
400 X XX X X Unknown
Since ProtoBuf messages are binary encoded, we cannot really see the content easily like with QMI's Type-Length-Value (TLV) scheme.
Fortunately, some reverse-engineering tools exist to decode ProtoBuf message such as ProtoBuf Inspector.
You may also find the ProtoBuf message definitions in Android builds as they are sometimes supplied with it, look for *.proto files.
Getting the SLPI to work on mainline
To get the SLPI working on mainline it must be enabled in the phone's DTS with a firmware location:
&slpi {
firmware-name = "qcom/soc/vendor/device/slpi.mbn";
status = "okay";
};
For the firmware take slpi.mdt from Android, squish it using
pil-squasher and put it into the correct location like this:
pil-squasher "/lib/firmware/qcom/soc/vendor/device/slpi.mbn" "/path/to/android/slpi.mdt"
Then install
hexagonrpcd and copy some files from Android according to its README.
Mainline Architecture
On mainline there are two components that talk to the SLPI:
- hexagonrpcd
- libssc (used by iio-sensor-proxy)
Hexagonrpcd is a daemon that repeatedly calls adsp_listener_next2() on the SLPI over fastrpc. This method returns an instruction for the daemon to execute. On boot the slpi reads sensor configuration and registry files through hexagonrpcd to learn about the sensors on the device. Once this is done, sensors can be read using libssc.
You can test reading sensors using $ ssccli --sensor <sensor_name>.
If this fails with an unknown error you can add --debug. Usually the SLPI is not initialized correctly using hexagonrpcd. Hexagonrpcd should run for a while and then stop waiting on the return of a function call. If it crashes before that point you may need to fix it.