MEMS Accelerometer Sensor (I2C interface) Device Tree configuration of kernel in Android-x86 project

299 views
Skip to first unread message

suhas m

unread,
Mar 2, 2020, 12:40:56 AM3/2/20
to Android-x86

Want to integrate the LSM6DSM  Accelerometer sensor into my AOSP oreo 8.1 Source for our Intel X86 based Tablet. As per the aatache Read.md file , i followed as per below for driver source code integration.


1. Downloded the driver package LSM6DSM.zip driver package from OEM website and extracted ti to folder "st_lsm6dsm"

2.  Copy driver source code into the target directory (e.g. kernel/drivers/iio/imu/st_lsm6dsm).

3. Edit related Kconfig (e.g. *drivers/iio/imu/Kconfig*) to include *LSM6DSM* support:

           >         source "drivers/iio/imu/st_lsm6dsm/Kconfig"

4. Edit related Makefile (e.g. *drivers/iio/imu/Makefile*) adding the following line:

           >         obj-y += lsm6dsm/

5. Add custom events into *include/uapi/linux/iio/types.h* as per attached Readme.md.

6. Device Tree configuration: To enable driver probing, we have to add the lsm6dsm node to the platform device tree as described in example below (based on Raspberry PI 3)  ,


&i2c0 {
  	status = "ok";
  	#address-cells = <0x1>;
  	#size-cells = <0x0>;
  	lsm6dsm@6b {
  		compatible = "st,lsm6dsm";
  		reg = <0x6b>;
  		interrupt-parent = <&gpio>;
  		interrupts = <26 IRQ_TYPE_LEVEL_HIGH>;
  };


but to my surprise figured out that android-x86 project do not support device tree architecture (dts and dtb, which tells the kernel to load the appropriate driver and on whic interface that the device is connected to). So how and where do i have to do the source core changes for the the above sensor to enumerate/instantiate as an IIO device at I2C port 4


7. Kernel configuration

Configure kernel with *make menuconfig*

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

8. Built the driver as module st-lsm6dsm.ko into the kernel and rebuilt the iso successfully.

9.
But still i'm not able to see the device enumerated like below

/dev/iio:device*

/sys/devices/iio:device*


(this is because kernel do not know that which I2C port to use after loading the appropriate driver module)

README.md(for STmicro IIO driver intgration into kernel)

Chih-Wei Huang

unread,
Mar 2, 2020, 3:42:13 AM3/2/20
to Android-x86
suhas m <suha...@gmail.com> 於 2020年3月2日 週一 下午1:41寫道:
Seems you are familiar with ARM embedded world but
unfamiliar with x86 world. On an x86 PC, the operating system
discovers the peripherals by enumerating the PCI bus.
Device tree is usually not necessary.
If you need more info, see, e.g.,
https://unix.stackexchange.com/questions/399619/why-do-embedded-systems-need-device-tree-while-pcs-dont

I think you should discuss with your vendor how to use their peripherals
on an x86 device. In particular, how to enumere the peripherals
without device tree. If you really need it, study it yourself.
(google 'device tree on x86')

BTW, I notice the vanilla kernel has already the driver of lsm6dsm.
Unfortunately we didn't build the module by default.
You can enable it by adding these to
kernel/arch/x86/configs/android-x86_*defconfig

CONFIG_IIO_ST_LSM6DSX=m
CONFIG_IIO_ST_LSM6DSX_I2C=m

The driver will be called st_lsm6dsx.

--
Chih-Wei
Android-x86 project
http://www.android-x86.org
Reply all
Reply to author
Forward
0 new messages