Linux内核-RGB LCD驱动移植

来自华清远见研发中心
FarSight讨论 | 贡献2021年3月19日 (五) 10:28的版本 实验原理

跳转至: 导航搜索

实验原理

前文介绍过LTDC的内容,本节只需为LTDC添加一个面板即可。内核中包含一个通用的面板驱动,驱动之包含大量各种各样的面板。

  1. 驱动修改
  2. 驱动路径为:drivers/gpu/drm/panel/panel-simple.c

    移植时可以在驱动中支持新的面板的内容,也可以找到一个与自己面板相仿的内容进行修改,本节即使用在原有面板修改的方法。如本节参考面板名称为zj070na-01p,对于一个面板最关键的内容在驱动通过drm_display_mode的结构体描述,zj070na-01p的描述如下:

    static const struct drm_display_mode innolux_zj070na_01p_mode = {
    	.clock = 51501,
    	.hdisplay = 1024,
    	.hsync_start = 1024 + 128,
    	.hsync_end = 1024 + 128 + 64,
    	.htotal = 1024 + 128 + 64 + 128,
    	.vdisplay = 600,
    	.vsync_start = 600 + 16,
    	.vsync_end = 600 + 16 + 4,
    	.vtotal = 600 + 16 + 4 + 16,
    	.vrefresh = 60,
    };
    

    这个结构体主要用来描述面板的时序相关信息,时序框图如下:

    55-1-1-1.png

    hdisplay:有效显示区水平像素数量,对应Active Width

    hsync_start:水平同步开始,对应hdispay + HFP

    hsync_end:水平同步结束,对应hdisplay + HFP + HSYNC width(HPW)

    htotal:水平总像素,对应hdisplay + HFP + HSYNC width + HBP

    vdisplay:垂直显示像素,对应Active Height

    vsync_start:垂直同步开始,对应vdispay + VFP

    vsync_end:垂直像素结束,对应vdisplay + VFP + VSYNC width(VPW)

    vtotal:垂直总像素,对应vdisplay + VFP + VSYNC width + VBP

    vrefresh:刷新率

    面板芯片手册中关于时序的描述如下:

    55-1-1-2.png

    表中可以确认HBP=140、HPW=20、HFP=160、VBP=20、VPW=3、VFP=12,修改面板信息如下:

    static const struct drm_display_mode innolux_zj070na_01p_mode = {
    	.clock = 51501,
    	.hdisplay = 1024,
    	.hsync_start = 1024 + 160,
    	.hsync_end = 1024 + 160 + 20,
    	.htotal = 1024 + 160 + 20 + 140,
    	.vdisplay = 600,
    	.vsync_start = 600 + 12,
    	.vsync_end = 600 + 12 + 3,
    	.vtotal = 600 + 12 + 3 + 12,
    	.vrefresh = 60,
    };
    
  3. 设备树修改
  4. 增加ltdc输出端口:

    &ltdc {
    	status = "okay";
    
    	port {
    		#address-cells = <1>;
    		#size-cells = <0>;
    
    		ltdc_ep1_out: endpoint@1 {
    			reg = <1>;
    			remote-endpoint = <&panel_in_rgb>;
    		};
    	};
    };
    

    增加面板节点:

    panel: panel-rgb {
    	compatible = "innolux,zj070na-01p";
    	pinctrl-names = "default", "sleep";
    	backlight = <&panel_backlight>;
    	status = "okay";
    
    	port {
    		panel_in_rgb: endpoint {
    			remote-endpoint = <&ltdc_ep1_out>;
    		};
    	};
    };
    
  5. PWM设备节点
  6. 参考文档:

    Documentation/devicetree/bindings/pwm/pwm-stm32.txt
    

    内核中ST对STM32MP15x系列芯片的设备树资源了做了定义,可参见:

    arch/arm/boot/dts/stm32mp151.dtsi
    

    stm32mp151中timers2定义如下:

    timers2: timer@40000000 {
    	#address-cells = <1>;
    	#size-cells = <0>;
    	compatible = "st,stm32-timers";
    	reg = <0x40000000 0x400>;
    	clocks = <&rcc TIM2_K>;
    	clock-names = "int";
    	dmas = <&dmamux1 18 0x400 0x80000001>,
    	       <&dmamux1 19 0x400 0x80000001>,
    	       <&dmamux1 20 0x400 0x80000001>,
    	       <&dmamux1 21 0x400 0x80000001>,
    	       <&dmamux1 22 0x400 0x80000001>;
    	dma-names = "ch1", "ch2", "ch3", "ch4", "up";
    	status = "disabled";
    
    	pwm {
    		compatible = "st,stm32-pwm";
    		#pwm-cells = <3>;
    		status = "disabled";
    	};
    
    	timer@1 {
    		compatible = "st,stm32h7-timer-trigger";
    		reg = <1>;
    		status = "disabled";
    	};
    
    	counter {
    			compatible = "st,stm32-timer-counter";
    			status = "disabled";
    		};
    	};
    
    

    上述代码只对timers5做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。 参考文档或stm32mp15xx-dkx.dtsi对于i2c设备节点的描述,增加timers内容如下:

    &timers2 {
    	/* spare dmas for other usage */
    	/delete-property/dmas;
    	/delete-property/dma-names;
    	status = "okay";
    	pwm2: pwm {
    		pinctrl-0 = <&pwm2_pins_b>;
    		pinctrl-1 = <&pwm2_sleep_pins_b>;
    		pinctrl-names = "default", "sleep";
    		#pwm-cells = <2>;
    		status = "okay";
    	};
    	timer@2 {
    		status = "disabled";
    	};
    };
    

    stm32mp15-pinctrl.dtsi对于pwm2的描述与FS-MP1A所使用管脚不一致,所以无法直接使用,需参考其增加如下内容:

    pwm2_pins_b: pwm2-0 {
    	pins {
    		pinmux = <STM32_PINMUX('A', 5, AF1)>; /* TIM2_CH1 */
    		bias-pull-down;
    		drive-push-pull;
    		slew-rate = <0>;
    	};
    };
    pwm2_sleep_pins_b: pwm1-sleep-0 {
    	pins {
    		pinmux = <STM32_PINMUX('A', 5, ANALOG)>; /* TIM2_CH1 */
    	};
    };
    
  7. 背光设备节点
  8. 参考文档:

    Documentation/devicetree/bindings/leds/backlight/pwm-backlight.txt
    Documentation/devicetree/bindings/leds/backlight/gpio-backlight.txt
    

    FS-MP1A背光可以通过GPIO驱动也可通过PWM2的通道1驱动,可以对比参考文档或内核中其他设备树关于背光的定义。

    GPIO驱动背光节点内容如下:

    panel_backlight: panel-backlight {
    	compatible = "gpio-backlight";
    	gpios = <&gpiod 13 GPIO_ACTIVE_LOW>;
    		default-on;
    	status = "okay";
    };
    

    PWM驱动背光节点内容如下:

    panel_backlight: panel-backlight {
    	compatible = "pwm-backlight";
    	pwms = <&pwm2 0 5000000>;
    	brightness-levels = <0 4 8 16 32 64 128 255>;
    	default-brightness-level = <6>;
    	status = "okay";
    };
    

实验目的

熟悉基于Linux操作系统下的摄像头设备驱动移植配置过程。

实验平台

华清远见开发环境,FS-MP1A平台;

实验步骤

  • 增加设备树文件

由于RGB LCD并非FS-MP1A必须配置,本节增加一个设备树文件,对应增加了屏幕的设备。

在内核的arch/arm/boot/dts目录下新建文件stm32mp157a-fsmp1a-rgb070.dts文件并添加如下内容:

#include "stm32mp157a-fsmp1a.dts"

/ {
    model = "HQYJ STM32MP157 FSMP1A RGB Discovery Board";
    compatible = "st,stm32mp157a-dk1", "st,stm32mp157";
};

由于增加了新的设备树文件需修改arm/arm/boot/dts/Makefile,在文件中增加新的条目,红色字体部分为增加内容

dtb-$(CONFIG_ARCH_STM32) += \
stm32mp157a-dk1.dtb \
stm32mp157a-fsmp1a.dtb \
stm32mp157a-fsmp1a-mipi050.dtb \

stm32mp157a-fsmp1a-rgb070.dtb \

stm32mp157d-dk1.dtb \
  • 添加ltdc端口

修改文件arm/arm/boot/dts/stm32mp157a-fsmp1a-rgb070.dts,在文件末尾添加如下内容:

&ltdc {
	status = "okay";

	port {
		#address-cells = <1>;
		#size-cells = <0>;
		ltdc_ep1_out: endpoint@1 {
			reg = <1>;
			remote-endpoint = <&panel_in_rgb>;
		};
	};
};
  • 添加面板信息

修改文件arm/arm/boot/dts/stm32mp157a-fsmp1a-rgb070.dts,在根节点中添加如下内容:

panel: panel-rgb {
	compatible = "innolux,zj070na-01p";
	pinctrl-names = "default", "sleep";
	backlight = <&panel_backlight>;
	status = "okay";
	port {
		panel_in_rgb: endpoint {
			remote-endpoint = <&ltdc_ep1_out>;
		};
	};
};  
  • 修改面板驱动,修改面板时序参数

修改文件drivers/gpu/drm/panel/panel-simple.c,修改zj070na-01p面板信息,对照面板芯片手册修改原有内容,红色字体部分为修改内容:

static const struct drm_display_mode innolux_zj070na_01p_mode = {
	.clock = 51501,
	.hdisplay = 1024,
	.hsync_start = 1024 + 160,
	.hsync_end = 1024 + 160 + 20,
	.htotal = 1024 + 160 + 20 + 140,
	.vdisplay = 600,
	.vsync_start = 600 + 12,
	.vsync_end = 600 + 12 + 3,
	.vtotal = 600 + 12 + 3 + 12,
	.vrefresh = 60,
};
  • 配置内核

由于内核默认支持通用面板驱动,本节列出主要选项,如下

linux@ubuntu:$ make menuconfig
Device Drivers  --->
	Graphics support  --->
		<*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)  --->
		<*> DRM Support for STMicroelectronics SoC Series
		Display Panels  --->
			<*> support for simple panels
		Backlight & LCD device support  --->
			<*>   Generic PWM based Backlight Driver
  • 编译内核及设备树
linux@ubuntu:$ make -j4 uImage dtbs LOADADDR=0xC2000040
  • 重启测试

安装上7寸LCD面板,将编译好的设备树和内核镜像拷贝到/tftpboot目录下,通过tftp引导内核,启动后可正常显示,如果屏幕显示不正可适当调节面板参数。

55-1-4-1.png