一、硬件
LCD显示实验使用LC-PI-200S开发板。
屏幕使用官方的5寸电阻屏幕。
二、设备树
使用自己下载的5.2版本Linux源码,参照官方设备树修改。
suniv-f1c100s.dtsi
lcd_rgb666_pins: lcd-rgb666-pins {
pins = "PD0", "PD1", "PD2", "PD3", "PD4",
"PD5", "PD6", "PD7", "PD8", "PD9",
"PD10", "PD11", "PD12", "PD13", "PD14",
"PD15", "PD16", "PD17", "PD18", "PD19",
"PD20", "PD21";
function = "lcd";
};
tcon0: lcd-controller@1c0c000 {
compatible = "allwinner,suniv-f1c100s-tcon";
reg = <0x01c0c000 0x1000>;
interrupts = <29>;
clocks = <&ccu CLK_BUS_LCD>,
<&ccu CLK_TCON>;
clock-names = "ahb",
"tcon-ch0";
clock-output-names = "tcon-pixel-clock";
resets = <&ccu RST_BUS_LCD>;
reset-names = "lcd";
status = "disabled";
ports {
#address-cells = <1>;
#size-cells = <0>;
tcon0_in: port@0 {
#address-cells = <1>;
#size-cells = <0>;
reg = <0>;
tcon0_in_be0: endpoint@0 {
reg = <0>;
remote-endpoint = <&be0_out_tcon0>;
};
};
tcon0_out: port@1 {
#address-cells = <1>;
#size-cells = <0>;
reg = <1>;
};
};
};
lcd_rgb666_pins: lcd-rgb666-pins {
pins = "PD0", "PD1", "PD2", "PD3", "PD4",
"PD5", "PD6", "PD7", "PD8", "PD9",
"PD10", "PD11", "PD12", "PD13", "PD14",
"PD15", "PD16", "PD17", "PD18", "PD19",
"PD20", "PD21";
function = "lcd";
};
fe0: display-frontend@1e00000 {
compatible = "allwinner,suniv-f1c100s-display-frontend";
reg = <0x01e00000 0x20000>;
interrupts = <30>;
clocks = <&ccu CLK_BUS_DE_FE>, <&ccu CLK_DE_FE>,
<&ccu CLK_DRAM_DE_FE>;
clock-names = "ahb", "mod",
"ram";
resets = <&ccu RST_BUS_DE_FE>;
status = "disabled";
ports {
#address-cells = <1>;
#size-cells = <0>;
fe0_out: port@1 {
#address-cells = <1>;
#size-cells = <0>;
reg = <1>;
fe0_out_be0: endpoint@0 {
reg = <0>;
remote-endpoint = <&be0_in_fe0>;
};
};
};
};
be0: display-backend@1e60000 {
compatible = "allwinner,suniv-f1c100s-display-backend";
reg = <0x01e60000 0x10000>;
reg-names = "be";
interrupts = <31>;
clocks = <&ccu CLK_BUS_DE_BE>, <&ccu CLK_DE_BE>,
<&ccu CLK_DRAM_DE_BE>;
clock-names = "ahb", "mod",
"ram";
resets = <&ccu RST_BUS_DE_BE>;
reset-names = "be";
assigned-clocks = <&ccu CLK_DE_BE>;
assigned-clock-rates = <300000000>;
ports {
#address-cells = <1>;
#size-cells = <0>;
be0_in: port@0 {
#address-cells = <1>;
#size-cells = <0>;
reg = <0>;
be0_in_fe0: endpoint@0 {
reg = <0>;
remote-endpoint = <&fe0_out_be0>;
};
};
be0_out: port@1 {
#address-cells = <1>;
#size-cells = <0>;
reg = <1>;
be0_out_tcon0: endpoint@0 {
reg = <0>;
remote-endpoint = <&tcon0_in_be0>;
};
};
};
};
suniv-f1c100s-licheepi-nano.dts
panel: panel {
compatible = "lg,lb070wv8", "simple-panel";
#address-cells = <1>;
#size-cells = <0>;
enable-gpios = <&pio 4 6 GPIO_ACTIVE_HIGH>;
power-supply = <®_vcc3v3>;
port@0 {
reg = <0>;
#address-cells = <1>;
#size-cells = <0>;
panel_input: endpoint@0 {
reg = <0>;
remote-endpoint = <&tcon0_out_lcd>;
};
};
};
&be0 {
status = "okay";
};
&de {
status = "okay";
};
&tcon0 {
pinctrl-names = "default";
pinctrl-0 = <&lcd_rgb666_pins>;
status = "okay";
};
&tcon0_out {
tcon0_out_lcd: endpoint@0 {
reg = <0>;
remote-endpoint = <&panel_input>;
};
};
重新编译设备树。
三、内核
3.1 屏幕信息添加
在内核目录/drivers/gpu/drm/panel/panel_simple.c中,填写屏幕时序信息如下:
{
.compatible = "lemaker,bl035-rgb-002",
.data = &lemaker_bl035_rgb_002,
}, {
.compatible = "lg,lb070wv8", // 与设备树对应
.data = &lg_lb070wv8,
}, {
.compatible = "lg,lp079qx1-sp0v",
.data = &lg_lp079qx1_sp0v,
},
3.2 内核驱动修改
主要修改文件为内核目录/drivers/gpu/drm/sun4i/文件夹下的三个文件,分别为sun4i_tcon.c、sun4i_drv.c、sun4i_backend.c。
3.2.1 sun4i_backend.c文件修改
static const struct of_device_id sun4i_backend_of_table[] = {
{ // add
.compatible = "allwinner,suniv-f1c100s-display-backend",
.data = &suniv_backend_quirks,
},
{
.compatible = "allwinner,sun4i-a10-display-backend",
.data = &sun4i_backend_quirks,
},
// add
static const struct sun4i_backend_quirks suniv_backend_quirks = {
};
3.2.2 sun4i_drv.c文件修改
static bool sun4i_drv_node_is_frontend(struct device_node *node)
{
return of_device_is_compatible(node, "allwinner,suniv-f1c100s-display-frontend") || // add
of_device_is_compatible(node, "allwinner,sun4i-a10-display-frontend") ||
of_device_is_compatible(node, "allwinner,sun5i-a13-display-frontend") ||
of_device_is_compatible(node, "allwinner,sun6i-a31-display-frontend") ||
of_device_is_compatible(node, "allwinner,sun7i-a20-display-frontend") ||
of_device_is_compatible(node, "allwinner,sun8i-a23-display-frontend") ||
of_device_is_compatible(node, "allwinner,sun8i-a33-display-frontend") ||
of_device_is_compatible(node, "allwinner,sun9i-a80-display-frontend");
}
static const struct of_device_id sun4i_drv_of_table[] = {
{ .compatible = "allwinner,suniv-f1c100s-display-engine" }, // add
{ .compatible = "allwinner,sun4i-a10-display-engine" },
{ .compatible = "allwinner,sun5i-a10s-display-engine" },
3.2.3 sun4i_tcon.c文件修改
static const struct sun4i_tcon_quirks suniv_f1c100s_quirks = {
/*
* The F1C100s SoC has a second channel in TCON, but the clock input of
* it is not documented.
*/
.has_channel_0 = true,
/* .has_channel_1 = true, */
};
/* sun4i_drv uses this list to check if a device node is a TCON */
const struct of_device_id sun4i_tcon_of_table[] = {
{ .compatible = "allwinner,suniv-f1c100s-tcon", .data = &suniv_f1c100s_quirks },
{ .compatible = "allwinner,sun4i-a10-tcon", .data = &sun4i_a10_quirks },
{ .compatible = "allwinner,sun5i-a13-tcon", .data = &sun5i_a13_quirks },
{ .compatible = "allwinner,sun6i-a31-tcon", .data = &sun6i_a31_quirks },
四、开机logo显示
使用make menuconfig打开图形化配置界面,打开Bootup logo,其中的三个选项全部选中。
-> Device Drivers
-> Graphics support
-> Bootup logo (LOGO [=y])
-> Standard black and white Linux logo
-> Standard 16-color Linux logo
-> Standard 224-color Linux logo
重新编译内核。
五、测试
拷贝zImage和suniv-f1c100s-licheepi-nano.dtb之后,重启设备。
5.1 测试屏幕
cat /dev/zero > /dev/fb0
cat /dev/urandom > /dev/fb0
5.2 fb 与应用程序的交互
lcd_test.c
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/ioctl.h>
/* 显示屏相关头文件 */
#include <linux/fb.h>
#include <sys/mman.h>
typedef struct lcd_color
{
unsigned char bule;
unsigned char green;
unsigned char red;
unsigned char alpha;
} lcd_color;
/**
* 更新屏幕显示内存块信息,颜色格式为RGB8888
*/
void screen_refresh(unsigned char *fbp, lcd_color color_buff, long screen_size)
{
for(int i=0; i < screen_size; i+=4)
{
*((lcd_color*)(fbp + i)) = color_buff;
}
usleep(1000*2000);
}
int main()
{
int fp = 0;
int rgb_type = 0;
long screen_size = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
unsigned char *fbp = 0;
fp = open("/dev/fb0", O_RDWR);
if (fp < 0)
{
printf("Error : Can not open framebuffer device/n");
exit(1);
}
if (ioctl(fp, FBIOGET_FSCREENINFO, &finfo))
{
printf("Error reading fixed information/n");
exit(2);
}
if (ioctl(fp, FBIOGET_VSCREENINFO, &vinfo))
{
printf("Error reading variable information/n");
exit(3);
}
/* 打印获取的屏幕信息 */
printf("The mem is :%d\n", finfo.smem_len);
printf("The line_length is :%d\n", finfo.line_length);
printf("The xres is :%d\n", vinfo.xres);
printf("The yres is :%d\n", vinfo.yres);
printf("bits_per_pixel is :%d\n", vinfo.bits_per_pixel);
/* 获取RGB的颜色颜色格式,比如RGB8888、RGB656 */
rgb_type = vinfo.bits_per_pixel / 8;
/* 屏幕的像素点 */
screen_size = vinfo.xres * vinfo.yres * rgb_type;
/* 映射 framebuffer 的缓冲空间,得到一个指向这块空间的指针 */
fbp =(unsigned char *) mmap (NULL, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fp, 0);
if (fbp == NULL)
{
printf ("Error: failed to map framebuffer device to memory./n");
exit (4);
}
/* 刷白屏 */
memset(fbp, 0xff, screen_size);
usleep(1000*2000);
/* 我的显示屏是RGBA的,所以县色格式为32为,注意自己的显示屏信息,对应修改 */
/* 刷红色 */
screen_refresh(fbp, (lcd_color){0, 0, 255, 255}, screen_size);
usleep(1000*2000);
/* 刷绿色 */
screen_refresh(fbp, (lcd_color){0, 255, 0, 255}, screen_size);
usleep(1000*2000);
/* 刷蓝色 */
screen_refresh(fbp, (lcd_color){255, 0, 0, 255}, screen_size);
usleep(1000*2000);
/* 解除映射 */
munmap (fbp, screen_size);
close(fp);
return 0;
}
# ./lcd_test
The mem is :1536000
The line_length is :3200
The xres is :800
The yres is :480
bits_per_pixel is :32
六、参考
https://blog.csdn.net/qq_41709234/article/details/128586204
http://wiki.lcmaker.com/index.php?title=LC-PI-200S