I'm new with Android developpemnent but I want to write a SPI driver to connect a SPI IC and then an Android application to send and receive data from and to the IC.
From there, I don't really know where to create the driver (and what it should contain) and how to link an application in top of that. I have a customisable Android kernel (9.0 Pie, APQ8096_LA.UM.7.5.r1-03100-8x96.0_P_v5.0) with all its .dts, .dtsi, .c, and so on. I also got an eval board and the adequate documentation for the mapping.
I googled for a week and didn't found what I was looking for. I learned a bit about the device tree system. Since I have a Snapdragon 820 msm8996, I modified "msm8996-blsp.dtsi" and "msm8996-pinctrl.dtsi". I had this bit of code:
msm8996-pinctrl.dtsi
&soc {
...
spi_0 {
spi_0_active: spi_0_active {
spi_0 {
pins = "gpio0", "gpio1", "gpio2", "gpio3";
function = "blsp_spi1";
drive-strength = <6>;
bias-disable;
};
};
spi_0_sleep: spi_0_sleep {
spi_0 {
pins = "gpio0", "gpio1", "gpio2", "gpio3";
function = "blsp_spi1";
drive-strength = <6>;
bias-disable;
};
};
};
...
msm8996-blsp.dtsi
&soc {
...
spi_0: spi@7575000 { //QUP Base address for BLSP1_QUP0
compatible = "qcom,spi-qup-v2"; //Manufacturer and Model
#address-cells = <1>;
#size-cells = <0>;
reg-names = "spi_physical", "spi_bam_physical";
reg = <0x07575000 0x600>,
<0x07544000 0x2b000>;
interrupt-names = "spi_irq", "spi_bam_irq";
interrupts = <0 95 0>, <0 238 0>;
spi-max-frequency = <5000000>; //Maximum supported frequency in HZ
qcom,infinite-mode = <0>;
qcom,use-bam; // Enable BAM mode
/* Add BAM pipes */
qcom,bam-consumer-pipe-index = <12>;
qcom,bam-producer-pipe-index = <13>;
qcom,ver-reg-exists;
qcom,master-id = <86>;
qcom,use-pinctrl;
pinctrl-names = "spi_default", "spi_sleep";
pinctrl-0 = <&spi_0_active>;
pinctrl-1 = <&spi_0_sleep>;
clock-names = "iface_clk", "core_clk";
clocks = <&clock_gcc clk_gcc_blsp1_ahb_clk>,
<&clock_gcc clk_gcc_blsp1_qup1_spi_apps_clk>;
status = "enabled";
}
...
I build this kernel with
$ ./build.sh msm8996 -j $(nproc)
I flashed my eval board with fastboot and then I went in adb.
$ adb root
$ adb wait-for-device
$ adb shell
# cd /sys/class/spi_master
# ls
// Nothing here
Considering my spi adress is defined at @7575000, I expected the output to be
# spi_0
Is my code correct to enable it (I'm not good with device tree yet)? If so, why isn't visible with adb and how should I make it visible? What should be the next steps to access this SPI with an Android application?
I searched stackoverflow and so many places, but writing device drivers for Android doesn't seem to be common...
<title>
of this page is prefixed withandroid
already, as that is the question's primary tag. – halfer