[android12-linux-5.1][ST chip][RK3588][LSM6DSR] driver transplantation

1. Introduction to the environment

The RK3588 motherboard is equipped with the Android12 operating system, the kernel is Linux5.10, and uses ST's six-axis sensor LSM6DSR chip.

2. Chip introduction

The LSM6DSR is a six-axis acceleration and angular velocity (gyro) sensor that also has a built-in temperature sensor. This chip can choose I2C, SPI communication, as well as programmable terminals, and can be equipped with rear cameras and other equipment. The functions are very powerful (if you are interested, you can read the data sheet). The original manufacturer of this chip has disclosed two drivers: input and iio. I chose the iio driver here.

3. Driver transplantation

The target of driver transplantation is the kernel, so the following paths are all in the kernel directory.

Source code link: https://github.com/STMicroelectronics/STMems_Linux_IIO_drivers/tree/linux-4.19.y-gh

1. Copy the drivers/iio/imu/st_lsm6dsr folder to the corresponding path in the source code kernel

2. Add driver support in drivers/iio/imu/Kconfig. If there is a built-in st_lsm6dsx driver in the source code, you need to comment it out with # in front of the corresponding code to avoid affecting the transplanted driver.

source "drivers/iio/imu/st_lsm6dsr/Kconfig"

3. Add driver compilation in drivers/iio/imu/Makefile. If there is a built-in st_lsm6dsx driver in the source code, you need to comment out the corresponding code with # in front of it to avoid affecting the transplanted driver.

obj-y += st_lsm6dsr/

4. Add the enumeration value in include/uapi/linux/iio/types.h (find the corresponding enum, check whether the following values ​​are missing, and just add the missing ones)

     enum iio_event_type {
            IIO_EV_TYPE_THRESH_ADAPTIVE,
            IIO_EV_TYPE_MAG_ADAPTIVE,
            IIO_EV_TYPE_CHANGE,
            IIO_EV_TYPE_FIFO_FLUSH,
    };

     enum iio_event_direction {
            IIO_EV_DIR_RISING,
            IIO_EV_DIR_FALLING,
            IIO_EV_DIR_NONE,
            IIO_EV_DIR_FIFO_EMPTY,
            IIO_EV_DIR_FIFO_DATA,
    };

5. Add enumeration value in include/uapi/linux/iio/types.h

     enum iio_chan_type {
             IIO_ELECTRICALCONDUCTIVITY,
             IIO_COUNT,
             IIO_INDEX,
             IIO_SIGN_MOTION,
             IIO_STEP_DETECTOR,
             IIO_STEP_COUNTER,
             IIO_TILT,
             IIO_TAP,
             IIO_TAP_TAP,
             IIO_WRIST_TILT_GESTURE,
             IIO_GESTURE,
             IIO_WKUP,
             IIO_FREE_FALL,
             IIO_GRAVITY,
     };

6. Add device tree support in arch/arm64/boot/dts/rockchip/rd-rk3588.dts

&i2c1 {#总线名称需根据自身情况修改

	status = "okay";

	st_lsm6dsr: lsm6dsr@6b {
		compatible = "st,lsm6dsr";
		reg = <0x6b>;
		interrupt-parent = <&gpio3>;#需根据自身情况修改
		interrupts = <RK_PC3 IRQ_TYPE_LEVEL_HIGH>;#需根据自身情况修改
	};
}

7. Enter the source code root directory and execute the command " ./build.sh menuconfig " to configure and add chip support (you can also compile directly, and then enter Y according to the prompts)

  Device Drivers  --->
  	<M> Industrial I/O support  --->
  		Inertial measurement units  --->
  		<M>   STMicroelectronics LSM6DSM/LSM6DSL sensor  --->

8. Modify the time calling interface

[android12-linux-5.1] [ST chip] Compilation fails after driver transplantation__Huahua's Blog-CSDN Blog

9. Add iio driver name definition

[android12-linux-5.1] [ST chip] Compilation fails after driver transplantation__Huahua's Blog-CSDN Blog

10. Check the device status after compilation and burning.

1) "adb shell" command to enter the device

Guess you like

Origin blog.csdn.net/lsh670660992/article/details/132693894