触摸屏驱动移植

RK 全志

Posted by LXG on July 26, 2022

A133

自 Android 10 开始,使用 longan 设计以后,大部分 BSP 的配置将不再体现在 sys_config.fex, 而是写到 board.dts 文件,但是 sys_config.fex 依然保留给客户配置,方法不变。

屏驱动源码位置

linux-4.9/drivers/video/fbdev/sunxi/disp2/disp/lcd/

brandy/brandy-2.0/u-boot-2018/drivers/video/sunxi/disp2/disp/lcd/

新屏驱动适配

如果是 LVDS 接口和不需要初始化命令的 RGB 接口的屏,那么可以直接用 default_panel.c 驱动即可, 不需要新增文件 ,在 sys_config.fex 中修改 lcd_driver_name 为 defalut_lcd, 然后根据屏手册修改其它时序参数

如何阅读屏幕规格书

General Characteristics 一般特征

  1. 尺寸
  2. 分辨率 宽高
  3. 接口
  4. 色彩

screen_general

Product drawings 产品图纸

Interface description 接口说明

屏线各个引脚接口说明, 线序排查可用

CTP interface description 触摸接口说明

Timing Characteristics 时序特性

TTL Interface Timing

screen_timing

Absolute Maximum Ratings 绝对最大额定值

Electrical Characteristics 电器特性

Backlight Characteristics 背光特性

LCD Optical specifications 光学规格

Capacitive Touch Panel specifications 电容式触控面板规格

Mechanical characteristics 机械特性

Electrical characteristics 电气特性

Interface timing characteristics 接口时序特性

RELIABILITY TEST 相关测试

Suggestions for using LCD modules 使用建议

屏幕参数board.dts

./device/config/chips/a133/configs/c3/board.dts


/*----------------------------------------------------------------------------------
;lcd0 configuration

;lcd_if:               0:hv(sync+de); 1:8080; 2:ttl; 3:lvds; 4:dsi; 5:edp; 6:extend dsi
;lcd_hv_if             0:Parallel RGB; 8:Serial RGB; 10:Dummy RGB; 11: RGB Dummy;12:CCIR656
;lcd_hv_clk_phase      0:0 degree;1:90 degree;2:180 degree;3:270 degree
;lcd_hv_sync_polarity  0:vs low,hs low; 1:vs high,hslow; 2:vs low,hs high; 3:vs high,hs high
;lcd_hv_syuv_seq       0:YUYV; 1:YVYU; 2:UYVY; 3:VYUY
;lcd_cpu_if            0:18bit/1 cycle parallel(RGB666); 4:16bit/1cycle parallel (RGB565)
;                      6:18bit/3 cycle parallel(RGB666); 7:16bit/2cycle parallel (RGB565)
;lcd_cpu_te            0:frame auto trigger; 1:frame triggered by te rising edge; 2:frame triggered by te falling edge;
;lcd_dsi_if            0:video mode; 1: Command mode; 2:video burst mode
;lcd_dsi_te            0:frame auto trigger; 1:frame triggered by te rising edge; 2:frame triggered by te falling edge;
;lcd_x:                lcd horizontal resolution
;lcd_y:                lcd vertical resolution
;lcd_width:            width of lcd in mm
;lcd_height:           height of lcd in mm
;lcd_dclk_freq:        in MHZ unit
;lcd_pwm_freq:         in HZ unit
;lcd_pwm_pol:          lcd backlight PWM polarity
;lcd_pwm_max_limit     lcd backlight PWM max limit(<=255)
;lcd_hbp:              hsync back porch(pixel) + hsync plus width(pixel);
;lcd_ht:               hsync total cycle(pixel)
;lcd_vbp:              vsync back porch(line) + vysnc plus width(line)
;lcd_vt:               vysnc total cycle(line)
;lcd_hspw:             hsync plus width(pixel)
;lcd_vspw:             vysnc plus width(pixel)
;lcd_lvds_if:          0:single link;  1:dual link
;lcd_lvds_colordepth:  0:8bit; 1:6bit
;lcd_lvds_mode:        0:NS mode; 1:JEIDA mode
;lcd_frm:              0:disable; 1:enable rgb666 dither; 2:enable rgb656 dither
;lcd_io_phase:         0:noraml; 1:intert phase(0~3bit: vsync phase; 4~7bit:hsync phase;
;                      8~11bit:dclk phase; 12~15bit:de phase)
;lcd_gamma_en          lcd gamma correction enable
;lcd_bright_curve_en   lcd bright curve correction enable
;lcd_cmap_en           lcd color map function enable
;deu_mode              0:smoll lcd screen; 1:large lcd screen(larger than 10inch)
;lcdgamma4iep:         Smart Backlight parameter, lcd gamma vale * 10;
;                      decrease it while lcd is not bright enough; increase while lcd is too bright
;smart_color           90:normal lcd screen 65:retina lcd screen(9.7inch)
;Pin setting for special function ie.LVDS, RGB data or vsync
;   name(donot care) = port:PD12<pin function><pull up or pull down><drive ability><output level>
;Pin setting for gpio:
;   lcd_gpio_X     = port:PD12<pin function><pull up or pull down><drive ability><output level>
;Pin setting for backlight enable pin
;   lcd_bl_en     = port:PD12<pin function><pull up or pull down><drive ability><output level>
;fsync setting, pulse to csi
;lcd_fsync_en          (0:disable fsync,1:enable)
;lcd_fsync_act_time    (active time of fsync, unit:pixel)
;lcd_fsync_dis_time    (disactive time of fsync, unit:pixel)
;lcd_fsync_pol         (0:positive;1:negative)
;gpio config: <&pio for cpu or &r_pio for cpus, port, port num, pio function,
pull up or pull down(default 0), driver level(default 1), data>
;For dual link lvds: use lvds2link_pins_a  and lvds2link_pins_b instead
;For rgb24: use rgb24_pins_a  and rgb24_pins_b instead
;For lvds1: use lvds1_pins_a  and lvds1_pins_b instead
;For lvds0: use lvds0_pins_a  and lvds0_pins_b instead
;----------------------------------------------------------------------------------*/
		lcd0: lcd0@01c0c000 {
			status = "okay";
		};


RGB 屏幕

./linux-4.9/arch/arm64/boot/dts/sunxi/rgb-1024x600.dtsi

./linux-4.9/drivers/video/fbdev/sunxi/disp2/disp/lcd/default_panel.c


&lcd0  {
                        lcd_used             = <1>;
                        lcd_driver_name      = "default_lcd";
                        lcd_backlight        = <255>;
                        lcd_if               = <0>;   // hv(sync+de)
                        lcd_hv_if            = <0>;   // Parallel RGB
                        lcd_x                = <1024>;
                        lcd_y                = <600>;
                        lcd_width            =<154>;  // 154.21 x 85.92
                        lcd_height           = <86>;
                        lcd_dclk_freq        = <50>;  // DCLK frequency

                        lcd_pwm_used         = <1>;
                        lcd_pwm_ch           = <0>;
                        lcd_pwm_freq         = <50000>;
                        lcd_pwm_pol          = <1>;
                        lcd_pwm_max_limit    = <255>;

                        lcd_hbp              = <20>;   //
                        lcd_ht               = <1344>; // HSD period
                        lcd_hspw             = <10>;
                        lcd_vbp              = <20>;
                        lcd_vt               = <635>;  // VSD period
                        lcd_vspw             = <10>;

                        lcd_lvds_if          = <0>;
                        lcd_lvds_colordepth  = <0>;    // 0: 8 bits; 1: 6bits
                        lcd_lvds_mode        = <0>;    // 0: NS mode; 1: JEIDA mode
                        lcd_frm              = <1>;    // RGB888 -- RGB666 dither
                        lcd_io_phase        = <0x0100>; //
                        lcd_hv_clk_phase     = <0>;
                        lcd_hv_sync_polarity = <0>;
                        lcd_gamma_en         = <0>;
                        lcd_bright_curve_en  = <0>;
                        lcd_cmap_en          = <0>;
                        deu_mode             = <0>;
                        lcdgamma4iep         = <22>;
                        smart_color          = <90>;

                        lcd_pin_power        = "dcdc1"; //配置 lcddx 的电源
                        lcd_power            = "dc1sw";
                        lcd_gpio_0 = <&pio PD 22 1 0 3 1>;
                        pinctrl-0            = <&rgb18_pins_a>;
                        pinctrl-1            = <&rgb18_pins_b>;

                };

LVDS 屏幕

./linux-4.9/arch/arm64/boot/dts/sunxi/lvds-1920x1080.dtsi

./linux-4.9/drivers/video/fbdev/sunxi/disp2/disp/lcd/bp101wx1-206.c


&lcd0 {
                        lcd_used             = <1>;
                        lcd_driver_name      = "bp101wx1";


                        lcd_if               = <3>;
                        lcd_lvds_if          = <1>;

                        lcd_x                = <1920>;
                        lcd_y                = <1080>;
                        lcd_width            = <476>;
                        lcd_height           = <268>;
                        lcd_dclk_freq        = <148>;

                        lcd_hbp              = <30>;
                        lcd_ht               = <2100>;
                        lcd_hspw             = <20>;
                        lcd_vbp              = <10>;
                        lcd_vt               = <1130>;
                        lcd_vspw             = <5>;

                        lcd_pwm_used         = <1>;
                        lcd_pwm_ch           = <0>;
                        lcd_pwm_freq         = <5000>;
                        lcd_pwm_pol          = <0>;
                        lcd_pwm_max_limit    = <255>;
                        lcd_backlight        = <150>;
                        lcd_bright_curve_en  = <0>;
                        lcd_bl_en = <&pio PH 15 1 0 3 1>;

                        lcd_lvds_colordepth  = <0>;
                        lcd_lvds_mode        = <0>;

                        lcd_frm              = <1>;
                        lcd_hv_clk_phase     = <0>;
                        lcd_hv_sync_polarity = <0>;
                        lcd_gamma_en         = <0>;
                        lcd_cmap_en          = <0>;

                        lcd_pin_power        = "bldo5";
                        lcd_power            = "dc1sw";
                        pinctrl-0            = <&lvds2link_pins_a>;
                        pinctrl-1            = <&lvds2link_pins_b>;
                };

MIPI 屏幕

./linux-4.9/arch/arm64/boot/dts/sunxi/mipi-800x1280-bxw.dtsi

./linux-4.9/drivers/video/fbdev/sunxi/disp2/disp/lcd/k101im2qa04.c


&lcd0{
                        lcd_used            = <1>;

                        lcd_driver_name     = "k101im2qa04";
                        lcd_backlight       = <50>;
                        lcd_if              = <4>;

                        lcd_x               = <800>;
                        lcd_y               = <1280>;
                        lcd_width           = <135>;
                        lcd_height          = <216>;
                        lcd_dclk_freq       = <68>;

                        lcd_pwm_used        = <1>;
                        lcd_pwm_ch          = <0>;
                        lcd_pwm_freq        = <50000>;
                        lcd_pwm_pol         = <1>;
                        lcd_pwm_max_limit   = <255>;


                        lcd_hbp             = <36>;
                        lcd_ht              = <854>;
                        lcd_hspw            = <18>;
                        lcd_vbp             = <12>;
                        lcd_vt              = <1320>;
                        lcd_vspw            = <4>;

                        lcd_frm             = <0>;
                        lcd_gamma_en        = <0>;
                        lcd_bright_curve_en = <0>;
                        lcd_cmap_en         = <0>;

                        deu_mode            = <0>;
                        lcdgamma4iep        = <22>;
                        smart_color         = <90>;

                        lcd_dsi_if          = <0>;
                        lcd_dsi_lane        = <4>;
                        lcd_dsi_format      = <0>;
                        lcd_dsi_te          = <0>;
                        lcd_dsi_eotp        = <0>;

                        lcd_pin_power = "dcdc1";
                        lcd_pin_power1 = "eldo3";

                        lcd_power = "dc1sw";
                        lcd_bl_en = <&pio PB 8 1 0 3 1>;
                        /*lcd_gpio_1 = <&pio PD 23 1 0 3 1>;*/
                        lcd_gpio_0 = <&pio PD 22 1 0 3 1>;
                        pinctrl-0 = <&dsi4lane_pins_a>;
                        pinctrl-1 = <&dsi4lane_pins_b>;
};


屏幕参数

  1. LCD接口参数
  2. LCD时序参数
  3. LCD其他参数
  4. POWER和IO参数

常用调试

查看显示信息

cat /sys/class/disp/disp/attr/sys


screen 0:
de_rate 300000000 hz, ref_fps:59
mgr0: 1024x600 fmt[rgb] cs[0x204] range[full] eotf[0x4] bits[8bits] err[0] force_sync[0] unblank direct_show[false] iommu[1]
dmabuf: cache[7] cache max[48] umap skip[5] overflow[749]
	lcd output	backlight(113)	fps:59.1	1024x 600
	err:0	skip:236	irq:4732787	vsync:4400378	vsync_skip:0	
   BUF    enable ch[0] lyr[0] z[0] prem[N] a[globl 255] fmt[  1] fb[1024, 640; 512, 320; 512, 320] crop[   0,   0,1024, 600] frame[   0,   0,1024, 600] addr[fe400000,fe4a0000,fe4c8000] flags[0x       0] trd[0,0]
depth[ 0] disp[0]all:28787, sub:28787, cur:28787, free:28779, skip:0

查看 pwm 信息

cat /sys/kernel/debug/pwm


platform/300a000.pwm, 16 PWM devices
 pwm-0   (lcd                 ): requested enabled period: 20000 ns duty: 8906 ns polarity: inverse
 pwm-1   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-2   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-3   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-4   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-5   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-6   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-7   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-8   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-9   ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-10  ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-11  ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-12  ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-13  ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-14  ((null)              ): period: 0 ns duty: 0 ns polarity: normal
 pwm-15  ((null)              ): period: 0 ns duty: 0 ns polarity: normal