查看“Linux内核-RGB LCD驱动移植”的源代码
←
Linux内核-RGB LCD驱动移植
跳转至:
导航
、
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
==实验原理== 前文介绍过LTDC的内容,本节只需为LTDC添加一个面板即可。内核中包含一个通用的面板驱动,驱动之包含大量各种各样的面板。<br> <ol> <li>驱动修改</li> 驱动路径为:drivers/gpu/drm/panel/panel-simple.c<br> 移植时可以在驱动中支持新的面板的内容,也可以找到一个与自己面板相仿的内容进行修改,本节即使用在原有面板修改的方法。如本节参考面板名称为zj070na-01p,对于一个面板最关键的内容在驱动通过drm_display_mode的结构体描述,zj070na-01p的描述如下: <pre><nowiki> 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, }; </nowiki></pre> 这个结构体主要用来描述面板的时序相关信息,时序框图如下: <center>[[Image:55-1-1-1.png|640px]]</center> <br> hdisplay:有效显示区水平像素数量,对应Active Width<br> hsync_start:水平同步开始,对应hdispay + HFP<br> hsync_end:水平同步结束,对应hdisplay + HFP + HSYNC width(HPW)<br> htotal:水平总像素,对应hdisplay + HFP + HSYNC width + HBP<br> vdisplay:垂直显示像素,对应Active Height<br> vsync_start:垂直同步开始,对应vdispay + VFP<br> vsync_end:垂直像素结束,对应vdisplay + VFP + VSYNC width(VPW)<br> vtotal:垂直总像素,对应vdisplay + VFP + VSYNC width + VBP<br> vrefresh:刷新率<br> 面板芯片手册中关于时序的描述如下: <center>[[Image:55-1-1-2.png|640px]]</center> <br> 表中可以确认HBP=140、HPW=20、HFP=160、VBP=20、VPW=3、VFP=12,修改面板信息如下: <pre><nowiki> 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, }; </nowiki></pre> <li>设备树修改</li> 增加ltdc输出端口: <pre><nowiki> <dc { status = "okay"; port { #address-cells = <1>; #size-cells = <0>; ltdc_ep1_out: endpoint@1 { reg = <1>; remote-endpoint = <&panel_in_rgb>; }; }; }; </nowiki></pre> 增加面板节点: <pre><nowiki> panel: panel-rgb { compatible = "innolux,zj070na-01p"; pinctrl-names = "default", "sleep"; backlight = <&panel_backlight>; status = "okay"; port { panel_in_rgb: endpoint { remote-endpoint = <<dc_ep1_out>; }; }; }; </nowiki></pre> <li>PWM设备节点</li> 参考文档: Documentation/devicetree/bindings/pwm/pwm-stm32.txt 内核中ST对STM32MP15x系列芯片的设备树资源了做了定义,可参见: arch/arm/boot/dts/stm32mp151.dtsi stm32mp151中timers2定义如下: <pre><nowiki> 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"; }; }; </nowiki></pre> 上述代码只对timers5做了基本的初始化,并没有针对不同的硬件设计做适配,所以需结合硬件补全设备树节点信息。 参考文档或stm32mp15xx-dkx.dtsi对于i2c设备节点的描述,增加timers内容如下: <pre><nowiki> &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"; }; }; </nowiki></pre> stm32mp15-pinctrl.dtsi对于pwm2的描述与FS-MP1A所使用管脚不一致,所以无法直接使用,需参考其增加如下内容: <pre><nowiki> 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 */ }; }; </nowiki></pre> <li>背光设备节点</li> 参考文档: <pre> Documentation/devicetree/bindings/leds/backlight/pwm-backlight.txt Documentation/devicetree/bindings/leds/backlight/gpio-backlight.txt </pre> FS-MP1A背光可以通过GPIO驱动也可通过PWM2的通道1驱动,可以对比参考文档或内核中其他设备树关于背光的定义。 GPIO驱动背光节点内容如下: <pre> panel_backlight: panel-backlight { compatible = "gpio-backlight"; gpios = <&gpiod 13 GPIO_ACTIVE_LOW>; default-on; status = "okay"; }; </pre> PWM驱动背光节点内容如下: <pre> 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"; }; </pre> </ol> ==实验目的== 熟悉基于Linux操作系统下的摄像头设备驱动移植配置过程。 ==实验平台== 华清远见开发环境,FS-MP1A平台; ==实验步骤== <ol> <li>导入交叉编译工具链</li> linux@ubuntu:$ source /opt/st/stm32mp1/3.1-openstlinux-5.4-dunfell-mp1-20-06-24/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi <li>增加设备树文件</li> 由于RGB LCD并非FS-MP1A必须配置,本节增加一个设备树文件,对应增加了屏幕的设备。<br> 在内核的arch/arm/boot/dts目录下新建文件stm32mp157a-fsmp1a-rgb070.dts文件并添加如下内容: <pre><nowiki> #include "stm32mp157a-fsmp1a.dts" / { model = "HQYJ STM32MP157 FSMP1A RGB Discovery Board"; compatible = "st,stm32mp157a-dk1", "st,stm32mp157"; }; </nowiki></pre> 由于增加了新的设备树文件需修改arm/arm/boot/dts/Makefile,在文件中增加新的条目,红色字体部分为增加内容 <div style="background-color:#F8F8F8;border:1px solid #E5E5E5;font-family: monospace,Courier;"> : dtb-$(CONFIG_ARCH_STM32) += \<br> :: … :: stm32mp157a-dk1.dtb \ :: stm32mp157a-fsmp1a.dtb \ :: stm32mp157a-fsmp1a-mipi050.dtb \ <font color="#FF0000"> :: stm32mp157a-fsmp1a-rgb070.dtb \ </font> :: stm32mp157d-dk1.dtb \ </div> <li>添加pwm2内容</li> 修改stm32mp15xx-fsmp1x.dtsi,在stm32mp15xx-fsmp1x.dtsi文件末尾添加如下内容: <pre> &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"; }; }; &pinctrl { 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 */ }; }; }; </pre> <li>添加背光内容</li> 修改stm32mp15xx-fsmp1x.dtsi,在根节点中添加如下内容: <pre> 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"; }; </pre> <li>添加ltdc端口</li> 修改文件arm/arm/boot/dts/stm32mp157a-fsmp1a-rgb070.dts,在文件末尾添加如下内容: <pre><nowiki> <dc { status = "okay"; port { #address-cells = <1>; #size-cells = <0>; ltdc_ep1_out: endpoint@1 { reg = <1>; remote-endpoint = <&panel_in_rgb>; }; }; }; </nowiki></pre> <li>添加面板信息</li> 修改文件arm/arm/boot/dts/stm32mp157a-fsmp1a-rgb070.dts,在根节点中添加如下内容: <pre><nowiki> panel: panel-rgb { compatible = "innolux,zj070na-01p"; pinctrl-names = "default", "sleep"; backlight = <&panel_backlight>; status = "okay"; port { panel_in_rgb: endpoint { remote-endpoint = <<dc_ep1_out>; }; }; }; </nowiki></pre> <li>修改面板驱动,修改面板时序参数</li> 修改文件drivers/gpu/drm/panel/panel-simple.c,修改zj070na-01p面板信息,对照面板芯片手册修改原有内容,红色字体部分为修改内容: <div style="background-color:#F8F8F8;border:1px solid #E5E5E5;font-family: monospace,Courier;"> :static const struct drm_display_mode innolux_zj070na_01p_mode = { :: .clock = 51501, :: .hdisplay = 1024, :: .hsync_start = 1024 + <font color="#FF0000">160</font>, :: .hsync_end = 1024 + <font color="#FF0000">160 </font>+ <font color="#FF0000">20</font>, :: .htotal = 1024 + <font color="#FF0000">160</font> + <font color="#FF0000">20</font> + <font color="#FF0000">140</font>, :: .vdisplay = 600, :: .vsync_start = 600 + <font color="#FF0000">12</font>, :: .vsync_end = 600 + <font color="#FF0000">12</font> + <font color="#FF0000">3</font>, :: .vtotal = 600 + <font color="#FF0000">12</font> + <font color="#FF0000">3</font> + <font color="#FF0000">12</font>, :: .vrefresh = 60, }; </div> <li>配置内核</li> 由于内核默认支持通用面板驱动,本节列出主要选项,如下 <pre><nowiki> 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 </nowiki></pre> <li>增加启动项</li> 在虚拟机/tftpboot /tftpboot/pxelinux.cfg/01-00-80-e1-42-60-17末尾添加 <pre> LABEL stm32mp157a-fsmp1a-mipi KERNEL /uImage FDT /stm32mp157a-fsmp1a-rgb070.dtb APPEND root=/dev/mmcblk1p4 rootwait rw console=ttySTM0,115200 </pre> <li>编译内核及设备树</li> linux@ubuntu:$ make -j4 uImage dtbs LOADADDR=0xC2000040 <li>重启测试</li> 安装上7寸LCD面板,将编译好的设备树和内核镜像拷贝到/tftpboot目录下,通过tftp引导内核,启动后可正常显示,如果屏幕显示不正可适当调节面板参数。 <center>[[Image:55-1-4-1.png]] </center><br> </ol>
返回至
Linux内核-RGB LCD驱动移植
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
关于我们
联系我们
资料下载
STM32F103开发板
STM32U575开发板
STM32MP157开发板
Hi3861鸿蒙开发板
HaaS EDU开发板
ESP32开发板
i.MX8M Plus开发板
图书下载
嵌入式系列图书
物联网系列图书
Android系列图书
高校教仪
嵌入式实验室产品
物联网实验室产品
人工智能实验室产品
虚拟仿真实验室产品
行业应用实训室产品
虚拟仿真
嵌入式虚拟仿真平台
物联网虚拟仿真平台
人工智能虚拟仿真
友情链接
华清远见研发中心
元宇宙实验中心
华清远见硬件商城
工具
链入页面
相关更改
特殊页面
页面信息