orangepi zero2在linux5.4以上内核使用ili9341

背景

根据orangepi zero2用户手册说明,linux5.13内核不能使用 modprobe fbtft_device 驱动spi lcd

查看linux内核源码提交记录,发现在v5.4-rc3中删除了fbtft_device.c文件

commit如下

shell 复制代码
staging/fbtft: Remove fbtft_device
Commit c440eee ("Staging: fbtft: Switch to the gpio descriptor
interface") removed the gpio code from fbtft_device rendering it useless.

fbtft_device is a module that was used on the Raspberry Pi to dynamically
add fbtft devices when the Pi didn't have Device Tree support.
Just remove the module since it's the responsibility of Device Tree, ACPI
or platform code to add devices.

Fixes: c440eee ("Staging: fbtft: Switch to the gpio descriptor interface")
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
Link: https://lore.kernel.org/r/20190917171843.10334-2-noralf@tronnes.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

"fbtft_device用来在树莓派没有设备树时,自动添加fbtft设备,删除这个模块因为添加设备是设备树、ACPI或者平台代码的责任"

所以是因为原来的代码不符合设备和驱动分离的原则,所以给删除了,但其实驱动程序依然在,理论上只需要将设备硬件信息注册到内核,就可以正常运行了,可以通过设备树或者模块

dts

下面看下orangepi官方修改后的内核源码中的设备树,分支orange-pi-6.1-sun50iw9

https://github.com/orangepi-xunlong/linux-orangepi

sun50i-h616.dtsi

从芯片级(h616)的dts可以看到spi有spi0和spi1,spi0有一个cs0,spi1有cs0和cs1

shell 复制代码
			/omit-if-no-ref/
			spi0_pins: spi0-pins {
				pins = "PC0", "PC2", "PC4";
				function = "spi0";
			};

			/omit-if-no-ref/
			spi0_cs0_pin: spi0-cs0-pin {
				pins = "PC3";
				function = "spi0";
			};

			/omit-if-no-ref/
			spi1_pins: spi1-pins {
				pins = "PH6", "PH7", "PH8";
				function = "spi1";
			};

			/omit-if-no-ref/
			spi1_cs0_pin: spi1-cs0-pin {
				pins = "PH5";
				function = "spi1";
			};

			/omit-if-no-ref/
			spi1_cs1_pin: spi1-cs1-pin {
				pins = "PH9";
				function = "spi1";
			};

spi1设备只添加了cs1,cs0引脚没有用在spi1上,而是复用在了i2c3

shell 复制代码
		spi0: spi@5010000 {
			compatible = "allwinner,sun50i-h616-spi",
				     "allwinner,sun8i-h3-spi";
			reg = <0x05010000 0x1000>;
			interrupts = <GIC_SPI 12 IRQ_TYPE_LEVEL_HIGH>;
			clocks = <&ccu CLK_BUS_SPI0>, <&ccu CLK_SPI0>;
			clock-names = "ahb", "mod";
			resets = <&ccu RST_BUS_SPI0>;
			pinctrl-names = "default";
			pinctrl-0 = <&spi0_pins>;
			dmas = <&dma 22>, <&dma 22>;
			dma-names = "rx", "tx";
			status = "disabled";
			#address-cells = <1>;
			#size-cells = <0>;
		};

		spi1: spi@5011000 {
			compatible = "allwinner,sun50i-h616-spi",
				     "allwinner,sun8i-h3-spi";
			reg = <0x05011000 0x1000>;
			interrupts = <GIC_SPI 13 IRQ_TYPE_LEVEL_HIGH>;
			clocks = <&ccu CLK_BUS_SPI1>, <&ccu CLK_SPI1>;
			clock-names = "ahb", "mod";
			resets = <&ccu RST_BUS_SPI1>;
			pinctrl-names = "default";
			pinctrl-0 = <&spi1_pins>, <&spi1_cs1_pin>;
			dmas = <&dma 23>, <&dma 23>;
			dma-names = "rx", "tx";
			status = "disabled";
			#address-cells = <1>;
			#size-cells = <0>;
		};

sun50i-h616-orangepi-zero2.dts

从板级(orangepi zero2)dts可以看到添加了一个spidev@1设备,但是默认未启用

shell 复制代码
&spi1 {
	status = "disabled";
	#address-cells = <1>;
	#size-cells = <0>;
	pinctrl-names = "default";
	pinctrl-0 = <&spi1_pins>, <&spi1_cs1_pin>;

	spidev@1 {
		compatible = "rohm,dh2228fv";
		status = "disabled";
		reg = <1>;
		spi-max-frequency = <1000000>;
	};
};

硬件

可以看到spi0用来连接NOR FLASH,所以肯定不可以再用来连接lcd了

spi1在26PIN引出,并且cs0和cs1都有,不过cs0复用在了i2c3的TWI3-SDA引脚上,所以我们使用spi1驱动lcd,并且使用cs1

硬件接线如下,实际上就是用户手册推荐的连接

dts替换

新建ili9341.dts文件

vim ili9341.dts

shell 复制代码
/dts-v1/;
/plugin/;

/ {
        fragment@0 {
                target = <&spi1>;
                __overlay__ {
                        status = "okay";
                        ili9341: ili9341@0 {
                                compatible = "ilitek,ili9341";
                                reg = <1>;
                                spi-max-frequency = <40000000>;
                                rotate = <0>;
                                bgr;
                                fps = <30>;
                                buswidth = <8>;
                                reset-gpios = <&pio 2 9 1>;
                                dc-gpios = <&pio 2 6 0>;
                                led-gpios = <&pio 2 5 0>;
                                debug = <0>;
                        };
                };
        };
};

替换设备树,执行后reboot

orangepi-add-overlay ili9341.dts

不出意外的话,console默认会显示在lcd上,可以使用fbi指令测试

shell 复制代码
su root
apt update
apt install fbi
fbi -vt 1 -noverbose -d /dev/fb0 /boot/boot.bmp

关于pinctrl-0和cs-gpios

使用cs-gpios定义片选信号使用的引脚,来自ChatGPT3.5

shell 复制代码
spi@40013000 {
    compatible = "some-vendor,spi-bus";
    reg = <0x40013000>;
    #address-cells = <1>;
    #size-cells = <0>;
    status = "okay";

    cs-gpios = <&gpio1 10 0>, <&gpio1 11 0>;  // 定义两个片选 GPIO

    spidev0: spidev@0 {
        compatible = "some-vendor,spidev";
        reg = <0>;  // 对应 cs-gpios 的第一个 GPIO (gpio1 10)
        spi-max-frequency = <10000000>;
        status = "okay";
    };

    spidev1: spidev@1 {
        compatible = "some-vendor,spidev";
        reg = <1>;  // 对应 cs-gpios 的第二个 GPIO (gpio1 11)
        spi-max-frequency = <10000000>;
        status = "okay";
    };
};

pinctrl-0已经包含了spi1_cs1_pin,所以spidev的reg直接使用1也可以找到,就不需要cs-gpios了

shell 复制代码
&spi1 {
	status = "disabled";
	#address-cells = <1>;
	#size-cells = <0>;
	pinctrl-names = "default";
	pinctrl-0 = <&spi1_pins>, <&spi1_cs1_pin>;

	spidev@1 {
		compatible = "rohm,dh2228fv";
		status = "disabled";
		reg = <1>;
		spi-max-frequency = <1000000>;
	};
};
相关推荐
2401_8504108315 分钟前
文件系统和日志管理
linux·运维·服务器
XMYX-01 小时前
使用 SSH 蜜罐提升安全性和记录攻击活动
linux·ssh
二十雨辰3 小时前
[linux]docker基础
linux·运维·docker
饮浊酒4 小时前
Linux操作系统 ------(3.文本编译器Vim)
linux·vim
lihuhelihu4 小时前
第3章 CentOS系统管理
linux·运维·服务器·计算机网络·ubuntu·centos·云计算
矛取矛求4 小时前
Linux系统性能调优技巧
linux
One_Blanks4 小时前
渗透测试-Linux基础(1)
linux·运维·安全
Perishell4 小时前
无人机避障——大疆与Airsim中的角速度信息订阅获取
linux·动态规划·无人机
爱吃喵的鲤鱼4 小时前
linux进程的状态之环境变量
linux·运维·服务器·开发语言·c++
dessler4 小时前
Linux系统-ubuntu系统安装
linux·运维·云计算