Add custom Sensor in AOSP

Hello all,

I want to add the LSM6DS3 sensor driver in my AOSP source code. I am using SC600T device.

1. I have already add lsm6ds3 driver folder in to below location with makefile and kconfig file.

/SC600T/SC60_SC600_Android9.0.0_kernel4.9_r029/kernel/msm-4.9/drivers/iio/imu/st_lsm6ds3

2. add below line to /../../iio/imu/Kconfig file.
source “drivers/iio/imu/st_lsm6ds3/Kconfig”

3. add below line to /../../iio/imu/Makefile .
obj-y += st_lsm6ds3/

4. /SC600T/../../iio/imu/st_lsm6ds3 - Makefile

This is Makefile content of LSM6DS3 Driver

SPDX-License-Identifier: GPL-2.0-only

st_lsm6dsx-y := st_lsm6dsx_core.o st_lsm6dsx_buffer.o
st_lsm6dsx_shub.o

obj-$(CONFIG_IIO_ST_LSM6DSX) += st_lsm6dsx.o
obj-$(CONFIG_IIO_ST_LSM6DSX_I2C) += st_lsm6dsx_i2c.o
obj-$(CONFIG_IIO_ST_LSM6DSX_SPI) += st_lsm6dsx_spi.o
obj-$(CONFIG_IIO_ST_LSM6DSX_I3C) += st_lsm6dsx_i3c.o

5.I have also add lsm6ds3 node in device tree file:

&i2c_2 {
status = “ok”;
#address-cells = <0x1>;
#size-cells = <0x0>;
lsm6ds3@6b {
compatible = “st,lsm6ds3”;
reg = <0x6b>;
interrupt-parent = <&tlmm>;
interrupt-gpios = <&tlmm 45 0x2008>;
interrupts = <45 0x02>;
};

I have connected LSM6DS3 accelerometer Sensor on SENSOR_I2C_SCL (Pin number 131) and
SENSOR_I2C_SDA (Pin number 132).

after that I have compiled the source code and flash boot and dtbo on target device(SC600T) succesfully.

when I am trying to check sensor data in adb shell >> /sys/bus/devices/i2C/devices node is available and
lsm6ds3 adress node which is 6b is also available.
but lsm6ds3 sensor is not probed.


image

then after I will add below lines in msm8953_defconfig file.
6.add below lines in msm8953_defconfig fie:

CONFIG_IIO_ST_LSM6DSX=y
CONFIG_IIO_ST_LSM6DSX_I2C=y
CONFIG_IIO_ST_LSM6DSX_SPI=y
CONFIG_IIO_ST_LSM6DSX_I3C=y

after adding this file when i compiling the source code getting below errors:

Blockquote

[ 2% 309/12824] Building kernel…
FAILED: out/target/product/msm8953_64/obj/kernel/msm-4.9/arch/arm64/boot/Image.gz-dtb
/bin/bash -c “(rm -rf out/target/product/msm8953_64/obj/kernel/msm-4.9/arch/arm64/boot/dts ) && (make -j3 -C kernel/msm-4.9 O=…/…/out/target/product/msm8953_64/obj/kernel/msm-4.9 DTC_EXT=dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- KCFLAGS=-mno-android ) && (make -j3 -C kernel/msm-4.9 O=…/…/out/target/product/msm8953_64/obj/kernel/msm-4.9 DTC_EXT=dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- KCFLAGS=-mno-android modules ) && (make -j3 -C kernel/msm-4.9 O=…/…/out/target/product/msm8953_64/obj/kernel/msm-4.9 INSTALL_MOD_PATH=…/…/…/dlkm INSTALL_MOD_STRIP=1 DTC_EXT=dtc CONFIG_BUILD_ARM64_DT_OVERLAY=y ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- modules_install ) && (mdpath=`find out/target/product/msm8953_64/dlkm/lib/modules -type f -name modules.dep`; if [ “$mdpath” != “” ];then mpath=`dirname $mdpath`; ko=`find $mpath/kernel -type f -name *.ko`; for i in $ko; do mv $i out/target/product/msm8953_64/dlkm/lib/modules/; done; fi ) && (mdpath=`find out/target/product/msm8953_64/dlkm/lib/modules -type f -name modules.dep`; if [ “$mdpath” != “” ];then mpath=`dirname $mdpath`; rm -rf $mpath; fi )”
make: Entering directory /media/ubuntu/Vezo_360/SC600T/SC60_SC600_Android9.0.0_kernel4.9_r029/kernel/msm-4.9' make[1]: Entering directory /media/ubuntu/Vezo_360/SC600T/SC60_SC600_Android9.0.0_kernel4.9_r029/out/target/product/msm8953_64/obj/kernel/msm-4.9’
GEN ./Makefile
scripts/kconfig/conf --silentoldconfig Kconfig
make[1]: Leaving directory /media/ubuntu/Vezo_360/SC600T/SC60_SC600_Android9.0.0_kernel4.9_r029/out/target/product/msm8953_64/obj/kernel/msm-4.9' make[1]: Entering directory /media/ubuntu/Vezo_360/SC600T/SC60_SC600_Android9.0.0_kernel4.9_r029/out/target/product/msm8953_64/obj/kernel/msm-4.9’
CHK include/config/kernel.release
GEN ./Makefile
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
Using /media/ubuntu/Vezo_360/SC600T/SC60_SC600_Android9.0.0_kernel4.9_r029/kernel/msm-4.9 as source for kernel
/media/ubuntu/Vezo_360/SC600T/SC60_SC600_Android9.0.0_kernel4.9_r029/kernel/msm-4.9 is not clean, please run ‘make mrproper’
in the ‘/media/ubuntu/Vezo_360/SC600T/SC60_SC600_Android9.0.0_kernel4.9_r029/kernel/msm-4.9’ directory.
make[1]: *** [prepare3] Error 1
make[1]: *** Waiting for unfinished jobs…
make[1]: Leaving directory /media/ubuntu/Vezo_360/SC600T/SC60_SC600_Android9.0.0_kernel4.9_r029/out/target/product/msm8953_64/obj/kernel/msm-4.9' make: *** [sub-make] Error 2 make: Leaving directory /media/ubuntu/Vezo_360/SC600T/SC60_SC600_Android9.0.0_kernel4.9_r029/kernel/msm-4.9’
[ 2% 312/12824] target C: libdsutils <= vendor/qcom/proprietary/data/dsutils/src/ds_util.c
vendor/qcom/proprietary/data/dsutils/src/ds_util.c:719:7: warning: unused variable ‘adb_lvl’ [-Wunused-variable]
int adb_lvl = 0;
^
vendor/qcom/proprietary/data/dsutils/src/ds_util.c:2357:5: warning: unused function ‘ds_can_exec’ [-Wunused-function]
int ds_can_exec
^
2 warnings generated.
[ 2% 314/12824] target C++: KmInstallKeybox <= ven…ecuremsm/keymaster_install_toolbox/InstallKeybox.cpp
ninja: build stopped: subcommand failed.
20:36:27 ninja failed with: exit status 1

failed to build some targets (42 seconds)

Blockquote

adding any custom sensor in the AOSP, this all steps are mandatory or not?
why lsm6ds3 sensor is not probed. need to check anything from the hardware side?

Hi Aditya_Qza:
Android 9.0 uses the adsp sensor architecture. The sensor driver of adsp architecture needs to be provided to our company for debugging and integration. You can submit debugging requirement through e-service or email, thank you.

Hi Customer,

I see you build issue on e-service, i’ll check it in system, thanks!

hiii thanks for the reply. i have already generate ticket for the same.

Hello abby,

please look in to in and update me

Hi Aditya,

I have replied you in ticket, please refer the document to configure the sensor, LSM6DS3 is a default sensor in the code.