Search code examples
androidlinux-kernelandroid-kernel

How android Sensor HAL read data from Kernel?


I'm trying to understand how my system reads gyroscope data from the kernel. I have a Redmagic 8pro phone running Android 13 with a 5.15 kernel. The gyroscope sensor in my device is an LSM6DSO.

I built a GKI kernel for my phone and identified common/drivers/iio/imu/st_lsm6dsx, assuming it was the sensor's driver. I attempted to disable it by removing it from the Makefile. However, the sensor continued to function, indicating that this was not its driver. At least, on my phone, they didn't use this driver.

To better understand the sensor HAL, I want to find out how does the system read data from this sensor, and which function is used to access data from the kernel? Does anyone have any insights on this?

I searched for the device in both the dev and iio devices folders, but neither worked.


Solution

  • To better understand the sensor HAL, I want to find out how does the system read data from this sensor, and which function is used to access data from the kernel? Does anyone have any insights on this?

    The HAL gets sensor data using callback routines, being generated from lower layers. The initialize() call from HAL takes a callback function as a parameter. Android sensor HAL provides batch() function to configure sampling period and maximum allowable latency. The callback functions are called based on configured sampling period. Now it is up to vendor to implement these APIs. Please see documentation at:Sensor HAL 2.0.

    Sensor Driver

    I built a GKI kernel for my phone and identified common/drivers/iio/imu/st_lsm6dsx, assuming it was the sensor's driver. I attempted to disable it by removing it from the Makefile. However, the sensor continued to function, indicating that this was not its driver. At least, on my phone, they didn't use this driver.

    To achieve power saving and to offload sensor calculations, many mobile SoC vendors provide a separate core for sensor interfacing. Hence for given SoC the sensor driver may not be found in its kernel source code. Please refer target SoC features to know if it contains a separate sensor core.