Enable the SPI and I2C interface on AOSP build


Hi everyone,

I am trying to enable the SPI and I2C interfaces on my HiKey board, running Android. All Android stuff is done and in the HAL shared library I want to open the SPI like:

fh = open( "/dev/spi0", O_RDWR );

SPI is not enabled by default in the standard build. In file:
I find:

spi0: spi@f7106000 {
			compatible = "arm,pl022", "arm,primecell";
			pinctrl-0 = <&spi0_pmx_func &spi0_cfg_func>;
			num-cs = <1>;
			cs-gpios = <&gpio6 2 0>;
			status = "disabled";

I download the Kernel and change the Device Tree file, enable SPI (status=”ok”), build the kenel and move the files into device/linaro/hikey-kernel folder (AOSP build take it from here).
After building the new boot image unfortunately the SPI is still unavailable. But I see in the Kernel log:

[    1.727900] ssp-pl022 f7106000.spi: could not find pctldev for node /soc/pinmux@f7010000/spi0_pmx_func, deferring probe
[    4.991628] ssp-pl022 f7106000.spi: ARM PL022 driver, device ID: 0x00041022
[    4.998769] ssp-pl022 f7106000.spi: mapped registers from 0x00000000f7106000 to ffffff80098a0000

My question:
Can I change the Device Tree without building a new kernel? Is there a way to integrate the required steps in the AOSP build? For me it seems that the DTB file is not built.



You can change the device tree and run make dtbs instead of make to build just the DTBs. Then copy hi6220-hikey.dtb to hikey-kernel directory and rebuild the boot image.

You can also mount the new boot image after the build to make sure the new device tree is there for sure.

If you already have the full aosp source tree anyway, you can also just change the device tree of the kernel in the source tree and rebuild from a clean slate, rather than having to download the kernel again?

Ref: https://source.android.com/source/building-kernels#building



Hi Vchong,

Thanks for your answer.
That is exactly what I want. Change in hi6220.dtsi the “disabled” to “ok” and rebuild device tree binary. Copy the new dtb to:


Unfortuneatly it does not work.

“dtbs” is not a build target in ASOP:

ninja: error: unknown target 'dtbs', did you mean 'docs'?
14:37:34 ninja failed with: exit status 1
make: *** [run_soong_ui] Error 1

I also tried to build the Kernel. The current ASOP Build uses 4.9, so I did:

git clone http://android.googlesource.com/kernel/hikey-linaro
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-android-
git checkout -b android-hikey-linaro-4.9 origin/android-hikey-linaro-4.9
make hikey_defconfig
make -j4

But this Kernel crashes with my AOSP build.



Addendum: I copied the device tree files to be aligned with the kernel to the AOSP build:

hi6220-hikey.dts, hi6220-sched-energy.dtsi, hikey-pinctrl.dtsi

Making a new boot image, I get the error:

01-01 00:00:19.244  1975  1975 I SurfaceFlinger: SurfaceFlinger is starting
01-01 00:00:19.244  1975  1975 I SurfaceFlinger: SurfaceFlinger's main thread ready to run. Initializing graphics H/W...
01-01 00:00:19.249  1975  1975 D libEGL  : loaded /vendor/lib64/egl/libGLES_mali.so
01-01 00:00:19.249  1975  1975 I MaliBase: Mali libraries:
01-01 00:00:19.249  1975  1975 I MaliBase: Compiled: Feb  4 2016, time: 15:24:42.
01-01 00:00:19.249  1975  1975 I MaliBase: Driver revision: 0bc4a1ac7ab6
01-01 00:00:19.305  1975  1975 I MaliBase: ERROR in Mali driver:
01-01 00:00:19.305  1975  1975 I MaliBase:  * Device driver API mismatch
01-01 00:00:19.305  1975  1975 I MaliBase:  * Device driver API version: 900
01-01 00:00:19.305  1975  1975 I MaliBase:  * User space API version: 800
01-01 00:00:19.306  1975  1975 W libEGL  : eglInitialize(0x1) failed (EGL_BAD_ALLOC)
01-01 00:00:19.339  1975  1975 W [Gralloc-Warning]: init_frame_buffer_locked:305 fbdev pixclock is zero for fd: 19
01-01 00:00:19.339  1975  1975 I [Gralloc]: using (fd=19)
01-01 00:00:19.339  1975  1975 I [Gralloc]: refresh rate = 60.00 Hz
01-01	00:00:19.350  1975  1975 E SurfaceFlinger: hwcomposer module not found

Obviously the kernel uses API 900. I need exactly the same Kernel version from the AOSP HiKey version I has synced. Is there a way to sync the same Kernel of an AOSP release?

Any suggestions are appreciated.


@Tristar Were you able to make progress?

You’ve to run ‘make dtbs’ in the kernel dir, not aosp root, i.e. the same place where you build the kernel.

For the API mismatch, sounds like you’ll have to get the latest Mali package and rebuild.
wget https://dl.google.com/dl/android/aosp/linaro-hikey-20170523-4b9ebaff.tgz
untar it under aosp root
rebuild and reimage


Hi Vchong,

My issue was: the kernel does not fit to the AOSP build. In my case the Mali library version differ.

So I clone a new AOSP branch and this fits to the Kernel now. Unfortunately Google move the AOSP from API 25 to API 26 in the meantime. It will help if somewhere is a list where I can find which latest Git build revision of AOSP fits to the build revision of the Kernel (but I do not find such list).

Currently I make the changes in Android to allow an app to use a system service to access my hardware (again in API 26). I check also the option to implement my interface stuff in an own Kernel module instead to try to recover SPI and I2C devices.

Thanks for your reply


I am able to access my spi device with below changes:

Repo am using : https://github.com/linaro-swg/optee_android_manifest/blob/hikey-n-4.9-240/README.md

project kernel/linaro/hisilicon/
diff --git a/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts b/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
old mode 100644
new mode 100755
index 12f0bed..2777a35
--- a/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
+++ b/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts
@@ -595,10 +595,10 @@
 	#size-cells = <0>;
 	status = "ok";
-	spidev@0 {
-		compatible = "linux,spidev";
-		spi-max-frequency = <500000>;
+	myspi_device@0 {
+		compatible = "google,spid";
+		spi-max-frequency = <50000000>;
 		reg = <0>;
-		status = "disabled";
+		status = "ok";
diff --git a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
old mode 100644
new mode 100755
index b9fddbe..328883f
--- a/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
+++ b/arch/arm64/boot/dts/hisilicon/hi6220.dtsi
@@ -711,7 +711,15 @@
 			pinctrl-0 = <&spi0_pmx_func &spi0_cfg_func>;
 			num-cs = <1>;
 			cs-gpios = <&gpio6 2 0>;
-			status = "disabled";
+			status = "ok";
+			myspi_device@0 { 	/* Slave driver and CS ID */
+			    compatible = "google,spid"; 	/* Manufacturer, and Model */
+			    reg = <0x0>; /* Same as CS ID */
+			    spi-max-frequency = <50000000>;
+			};            
 		i2c0: i2c@f7100000 {

Also , to insmod your spi driver, below changes are required

diff --git a/arch/arm64/configs/hikey_defconfig b/arch/arm64/configs/hikey_defconfig
old mode 100644
new mode 100755
index ed70de7..bee2ea6
--- a/arch/arm64/configs/hikey_defconfig
+++ b/arch/arm64/configs/hikey_defconfig
@@ -34,6 +34,8 @@ CONFIG_EMBEDDED=y
 # CONFIG_BLK_DEV_BSG is not set

Hope this helps !!!