目录
一、整体流程概述
二、详细流程分析
1、LK中LCD的唯一入口
target_display_init()
gcdb_display_init()
2、屏幕识别&获取初始化参数信息
oem_panel_select()
dsi_panel_init
初始化panel结构体
3、屏幕进一步初始化及点亮
mdss_dsi_panel_power()
mdss_dsi_panel_clock
msm_fb_alloc()&fbcon_setup(&(panel->fb));
display_image_on_screen()
msm_display_config
msm_display_on()
mdss_dsi_bl_enable
首先从aboot_init开始,去走LCD的初始化流程,在aboot中判断是哪种存储方式和启动方式,然后进入LCD在LK的唯一初始化入口——target_display_init。然后会调用对应的gcdb_display_init方法。判断是哪个屏,并初始化对应的参数,以及对其进行上电,最终点亮屏幕。与此同时在点亮之后,会在aboot中将对应的屏幕信息写入到pbuf中,以便kernel能够获取到对应的屏幕信息,然后加载参数并点亮。如下是简单的流程图:
首先我们从aboot_init方法开始,看如何一步步启动LCD:
void aboot_init(const struct app_descriptor *app)
{
... ...
target_display_init(device.display_panel);
... ...
}
aboot中省略了系统系统的前期准备以及相关的启动模式,这部分后续文章在进行分析,当前继续分析LCD启动相关。
这里就可以看到我们的入口方法:target_display_init()。
根据不同的平台,此处调用的target_display_init()也是不同的,我们以MSM8909为例。此处调用的是msm8909目录下的Target_display.c文件。我们开始看下target_display_init()的调用流程:
void target_display_init(const char *panel_name)
{
... ...
if (target_splash_disable())//如果splash_disable的宏开启,则LK阶段不再初始化LCD,参数等的初始化均在kernel阶段进行
return;
do {
target_force_cont_splash_disable(false);
ret = gcdb_display_init(oem.panel, MDP_REV_305, MIPI_FB_ADDR);
if (!ret || ret == ERR_NOT_SUPPORTED) {
break;
} else {
target_force_cont_splash_disable(true);
msm_display_off();
}
} while (++panel_loop <= oem_panel_max_auto_detect_panels());
... ...
}
target_display_init方法中最关键的部分即do...while结构。这里会对LCD继续做初始化,即gcdb_display_init方法。该方法在gcdb_display.c (bootable\bootloader\lk\dev\gcdb\display),我们先来看下该方法的实现:
int gcdb_display_init(const char *panel_name, uint32_t rev, void *base)
{
int ret = NO_ERROR;
int pan_type;
dsi_video_mode_phy_db.pll_type = DSI_PLL_TYPE_28NM;
//通过读取对应的ID或者mipi回读判断是哪块屏,并将屏幕信息保存在pinfo结构体中
pan_type = oem_panel_select(panel_name, &panelstruct, &(panel.panel_info),
&dsi_video_mode_phy_db);
if (pan_type == PANEL_TYPE_DSI) {
if (update_dsi_display_config())
goto error_gcdb_display_init;
target_dsi_phy_config(&dsi_video_mode_phy_db);
mdss_dsi_check_swap_status();
mdss_dsi_set_pll_src();
if (dsi_panel_init(&(panel.panel_info), &panelstruct)) {
dprintf(CRITICAL, "DSI panel init failed!\n");
ret = ERROR;
goto error_gcdb_display_init;
}
panel.panel_info.mipi.mdss_dsi_phy_db = &dsi_video_mode_phy_db;
panel.pll_clk_func = mdss_dsi_panel_clock;
panel.dfps_func = mdss_dsi_mipi_dfps_config;
panel.power_func = mdss_dsi_panel_power;
panel.pre_init_func = mdss_dsi_panel_pre_init;
panel.bl_func = mdss_dsi_bl_enable;
panel.dsi2HDMI_config = mdss_dsi2HDMI_config;
/*
* Reserve fb memory to store pll codes and pass
* pll codes values to kernel.
*/
panel.panel_info.dfps.dfps_fb_base = base;
base += DFPS_PLL_CODES_SIZE;
panel.fb.base = base;
dprintf(SPEW, "dfps base=0x%p,d, fb_base=0x%p!\n",
panel.panel_info.dfps.dfps_fb_base, base);
panel.fb.width = panel.panel_info.xres;
panel.fb.height = panel.panel_info.yres;
panel.fb.stride = panel.panel_info.xres;
panel.fb.bpp = panel.panel_info.bpp;
panel.fb.format = panel.panel_info.mipi.dst_format;
} else if (pan_type == PANEL_TYPE_EDP) {
mdss_edp_panel_init(&(panel.panel_info));
/* prepare func is set up at edp_panel_init */
panel.clk_func = mdss_edp_panel_clock;
panel.power_func = mdss_edp_panel_power;
panel.bl_func = mdss_edp_bl_enable;
panel.fb.format = FB_FORMAT_RGB888;
} else {
dprintf(CRITICAL, "Target panel init not found!\n");
ret = ERR_NOT_SUPPORTED;
goto error_gcdb_display_init;
}
panel.fb.base = base;
panel.mdp_rev = rev;
//通过获取到的屏幕信息继续进行初始化
ret = msm_display_init(&panel);
error_gcdb_display_init:
display_enable = ret ? 0 : 1;
return ret;
}
可以看到该方法主要有四个动作:
① 选取对应的屏幕:dsi_panel_init()
pan_type = oem_panel_select(panel_name, &panelstruct, &(panel.panel_info),
&dsi_video_mode_phy_db);
② 将初始化信息保存在pinfo中:dsi_panel_init()
dsi_panel_init(&(panel.panel_info), &panelstruct)
③ 根据panel type初始化panel结构体
④ 根据上述信息进一步初始化LCD:msm_display_init()
ret = msm_display_init(&panel);
该方法同样根据平台不同会各自选取对应的执行文件,我们同样使用MSM8909对应的Oem_panel.c。此方法会根据硬件ID或者回读MIPI的方法来识别不同的屏。然后将识别到的屏幕信息保存在panelstruct结构体中。
int oem_panel_select(const char *panel_name, struct panel_struct *panelstruct,
struct msm_panel_info *pinfo,
struct mdss_dsi_phy_ctrl *phy_db)
{
uint32_t hw_id = board_hardware_id();
uint32_t platform_subtype = board_hardware_subtype();
int32_t panel_override_id;
if (panel_name) {
panel_override_id = panel_name_to_id(supp_panels,
ARRAY_SIZE(supp_panels), panel_name);
if (panel_override_id < 0) {
dprintf(CRITICAL, "Not able to search the panel:%s\n",
panel_name);
} else if (panel_override_id < UNKNOWN_PANEL) {
/* panel override using fastboot oem command */
panel_id = panel_override_id;
dprintf(INFO, "OEM panel override:%s\n",
panel_name);
goto panel_init;
}
}
if((panel_id=switch_panel_id())==UNKNOWN_PANEL)//获取屏幕ID
{
return PANEL_TYPE_UNKNOWN;
}
special_panel = panel_id;
panel_init:
phy_db->regulator_mode = DSI_PHY_REGULATOR_LDO_MODE;
return init_panel_data(panelstruct, pinfo, phy_db);//获取配置参数
}
① 首先我们来看下如何识别不同的LCD:switch_panel_id()
/*
* switch panel id by id0 and id1
*/
int switch_panel_id(void)
{
int lcd_id0;
int lcd_id1;
gpio_tlmm_config(panel_id0.pin_id, 0,
panel_id0.pin_direction, panel_id0.pin_pull,
panel_id0.pin_strength, panel_id0.pin_state);
gpio_tlmm_config(panel_id1.pin_id, 0,
panel_id1.pin_direction, panel_id1.pin_pull,
panel_id1.pin_strength, panel_id1.pin_state);
//mdelay(10);
lcd_id1=1;
lcd_id0=1;
lcd_id1=gpio_status(panel_id1.pin_id);//获取gpio状态
lcd_id0=gpio_status(panel_id0.pin_id);
dprintf(INFO,"lancelot lcd_id0=%d.\n",lcd_id0);
dprintf(INFO,"lancelot lcd_id1=%d.\n",lcd_id1);
if((lcd_id1 == 1)&&(lcd_id0 == 0)){
return JD9365_STARRY_VIDEO_PANEL;
}else{
return NT35521Z_INX101_VIDEO_PANEL;
}
}
此处给出的是通过两个硬件ID脚的状态组合进行识别的。即ID0和ID1。分别有高、低两种状态。两个ID脚的组合可以实现四种状态(00,01,10,11),也就是说我们足够识别四种屏。当然硬件上首先要能够进行区分。
② 区分panel id后,我们就可以根据panel id获取不同的配置参数信息:init_panel_data()
static int init_panel_data(struct panel_struct *panelstruct,
struct msm_panel_info *pinfo,
struct mdss_dsi_phy_ctrl *phy_db)
{
int pan_type = PANEL_TYPE_DSI;//panel type
switch (panel_id) {
... ...
case NT35521Z_INX101_VIDEO_PANEL:
panelstruct->paneldata = &nt35521z_inx101_video_panel_data;
panelstruct->panelres = &nt35521z_inx101_video_panel_res;
panelstruct->color = &nt35521z_inx101_video_color ;
panelstruct->videopanel = &nt35521z_inx101_video_video_panel ;
panelstruct->commandpanel = &nt35521z_inx101_video_command_panel ;
panelstruct->state = &nt35521z_inx101_video_state;
panelstruct->laneconfig = &nt35521z_inx101_video_lane_config;
panelstruct->paneltiminginfo
= &nt35521z_inx101_video_timing_info;
panelstruct->panelresetseq
= &nt35521z_inx101_video_reset_seq;
panelstruct->backlightinfo = &nt35521z_inx101_video_backlight;
pinfo->mipi.panel_on_cmds
= nt35521z_inx101_video_on_command;
pinfo->mipi.num_of_panel_on_cmds
= NT35521Z_INX101_VIDEO_ON_COMMAND;
pinfo->mipi.panel_off_cmds
= nt35521z_inx101_video_off_command;
pinfo->mipi.num_of_panel_off_cmds
= NT35521Z_INX101_VIDEO_OFF_COMMAND;
memcpy(phy_db->timing,
nt35521z_inx101_video_timings, TIMING_SIZE);
break;
... ...
}
return pan_type;
}
init_panel_data()初始化panel数据,主要初始化panel_struct结构体数据,然后返回panel类型PANEL_TYPE_DSI(还有EDP和HDMI格式)。据对应的panel_id值将对应的屏幕参数赋值给panelstruct结构体。此结构体对应/dsi-panel-xxx-video.dtsi文件,此结构体主要成员如下:
struct panel_struct {
struct panel_config *paneldata;//基本参数信息
struct panel_resolution *panelres;//Panel的分辨率、时序参数、极性等数据
struct color_info *color;
struct videopanel_info *videopanel;
struct commandpanel_info *commandpanel;
struct command_state *state;
struct lane_configuration *laneconfig;//这里可看出只支持到4lane,支持的lane对应的state为1,否则为0
struct panel_timing *paneltiminginfo;
struct panel_reset_sequence *panelresetseq;//对应设备树文件的qcom,mdss-dsi-reset-sequence =<1 20>, <0 20>, <1 20>;这里可让pin状态及演示多久后再修改pin状态。
struct backlight *backlightinfo;
struct fb_compression fbcinfo;
struct topology_config *config;
};
struct backlight {
uint16_t bl_interface_type; //背光控制方式
uint16_t bl_min_level;//背光最小值
uint16_t bl_max_level;//背光最大值
uint16_t bl_step;//间隔值
uint16_t bl_pmic_controltype;
char *bl_pmic_model;
};
panel_display.c (bootable\bootloader\lk\dev\gcdb\display)
根据panel_info和panelstruct将对应屏幕的参数初始化到pinfo中。
int dsi_panel_init(struct msm_panel_info *pinfo,
struct panel_struct *pstruct)
{
int ret = NO_ERROR;
/* Resolution setting*/
pinfo->xres = pstruct->panelres->panel_width;
pinfo->yres = pstruct->panelres->panel_height;
pinfo->lcdc.h_back_porch = pstruct->panelres->hback_porch;
pinfo->lcdc.h_front_porch = pstruct->panelres->hfront_porch;
pinfo->lcdc.h_pulse_width = pstruct->panelres->hpulse_width;
pinfo->lcdc.v_back_porch = pstruct->panelres->vback_porch;
pinfo->lcdc.v_front_porch = pstruct->panelres->vfront_porch;
pinfo->lcdc.v_pulse_width = pstruct->panelres->vpulse_width;
pinfo->lcdc.hsync_skew = pstruct->panelres->hsync_skew;
pinfo->border_top = pstruct->panelres->vtop_border;
pinfo->border_bottom = pstruct->panelres->vbottom_border;
pinfo->border_left = pstruct->panelres->hleft_border;
pinfo->border_right = pstruct->panelres->hright_border;
... ...
}
初始化panel全局变量的其他结构体成员
panel.panel_info.mipi.mdss_dsi_phy_db = &dsi_video_mode_phy_db;
panel.pll_clk_func = mdss_dsi_panel_clock;
panel.dfps_func = mdss_dsi_mipi_dfps_config;
panel.power_func = mdss_dsi_panel_power;
panel.pre_init_func = mdss_dsi_panel_pre_init;
panel.bl_func = mdss_dsi_bl_enable;
panel.dsi2HDMI_config = mdss_dsi2HDMI_config;
/*
* Reserve fb memory to store pll codes and pass
* pll codes values to kernel.
*/
panel.panel_info.dfps.dfps_fb_base = base;
base += DFPS_PLL_CODES_SIZE;
panel.fb.base = base;
dprintf(SPEW, "dfps base=0x%p,d, fb_base=0x%p!\n",
panel.panel_info.dfps.dfps_fb_base, base);
panel.fb.width = panel.panel_info.xres;
panel.fb.height = panel.panel_info.yres;
panel.fb.stride = panel.panel_info.xres;
panel.fb.bpp = panel.panel_info.bpp;
panel.fb.format = panel.panel_info.mipi.dst_format;
获取到对应的屏幕信息以及参数后,会调用msm_display_init方法,进一步的为屏幕的点亮做初始化的动作。实际在该方法中就开始对屏幕进行上电、第一帧显示动画、背光灯的进行控制。
int msm_display_init(struct msm_fb_panel_data *pdata)
{
int ret = NO_ERROR;
... ...
/* Turn on panel 给panel上电*/
if (pdata->power_func)
ret = pdata->power_func(1, &(panel->panel_info));
... ...
/* Enable clock 使能CLK*/
if (pdata->clk_func)
ret = pdata->clk_func(1, &(panel->panel_info));
... ...
//调用calculate_clock_config(pinfo)计算时钟配置和调用target_panel_clock(enable, pinfo)配置目标panel的时钟。
if (pdata->pll_clk_func)
ret = pdata->pll_clk_func(1, &(panel->panel_info));
... ...
//为帧缓冲器(frame buffer)分配内存。
ret = msm_fb_alloc(&(panel->fb));
if (ret)
goto msm_display_init_out;
fbcon_setup(&(panel->fb));
display_image_on_screen();//调用fetch_image_from_partition()从splash分区获取lk logo图片,如果splash分区没有满足要求的数据,就显示默认的logo。
... ...
ret = msm_display_config();//根据pinfo->type,比如我们这里是MIPI_VIDEO_PANEL来配置msm平台display,配置时还需要根据MDP(MobileDisplay processor)的版本来调用对应的config函数
if (ret)
goto msm_display_init_out;
ret = msm_display_on();
if (ret)
goto msm_display_init_out;
if (pdata->post_power_func)
ret = pdata->post_power_func(1);
if (ret)
goto msm_display_init_out;
/* Turn on backlight */
if (pdata->bl_func)
ret = pdata->bl_func(1);
if (ret)
goto msm_display_init_out;
msm_display_init_out:
return ret;
}
通过上述方法可以看到,在这里就可以看到第一帧画面了。我们来拆分下msm_display_init方法,看他分别作了哪些动作。
static int mdss_dsi_panel_power(uint8_t enable,
struct msm_panel_info *pinfo)
{
int ret = NO_ERROR;
if (enable) {
ret = target_ldo_ctrl(enable, pinfo);
if (ret) {
dprintf(CRITICAL, "LDO control enable failed\n");
return ret;
}
... ...
/* Panel Reset */
if (!panelstruct.paneldata->panel_lp11_init) {
ret = mdss_dsi_panel_reset(enable);
if (ret) {
dprintf(CRITICAL, "panel reset failed\n");
return ret;
}
}
dprintf(SPEW, "Panel power on done\n");
} else {
/* Disable panel and ldo */
ret = mdss_dsi_panel_reset(enable);
if (ret) {
dprintf(CRITICAL, "panel reset disable failed\n");
return ret;
}
ret = target_ldo_ctrl(enable, pinfo);
if (ret) {
dprintf(CRITICAL, "ldo control disable failed\n");
return ret;
}
dprintf(SPEW, "Panel power off done\n");
}
return ret;
}
target_ldo_ctrl()--->regulator_enable()给L2、L6和L17供电。另外是否会进行reset,取决于我们在dtsi中给lp11附的值。
调用calculate_clock_config(pinfo)计算时钟配置和调用target_panel_clock(enable, pinfo)配置目标panel的时钟。
static uint32_t mdss_dsi_panel_clock(uint8_t enable,
struct msm_panel_info *pinfo)
{
uint32_t ret = NO_ERROR;
ret = calculate_clock_config(pinfo);
if (ret)
dprintf(CRITICAL, "Clock calculation failed\n");
else
ret = target_panel_clock(enable, pinfo);
return ret;
}
为帧缓冲器(frame buffer)分配内存。
调用fetch_image_from_partition()从splash分区获取lk logo图片,如果splash分区没有满足要求的数据,就显示默认的logo。
void display_image_on_screen(void)
{
#if DISPLAY_TYPE_MIPI
int fetch_image_from_partition();
if (fetch_image_from_partition() < 0) {
display_default_image_on_screen();
} else {
/* data has been put into the right place */
fbcon_flush();
}
#else
display_default_image_on_screen();
#endif
}
① mdss_dsi_phy_init()
如果有两个MIPI DSI接口MIPI_DSI0和MIPI_DSI1就调用两次mdss_dsi_phy_init(),msm8909只有MIPI_DSI0,MSM8994等有两个DSI接口。
② mdss_dsi_host_init()
初始化DSI接口的host控制器。
③ mdss_dsi_panel_pre_init()
根据lp11的值判定是否走reset
case MIPI_VIDEO_PANEL:
dprintf(INFO, "Config MIPI_VIDEO_PANEL.\n");
mdp_rev = mdp_get_revision();
if (mdp_rev == MDP_REV_50 || mdp_rev == MDP_REV_304 ||
mdp_rev == MDP_REV_305)
ret = mdss_dsi_config(panel);
else
ret = mipi_config(panel);
if (ret)
goto msm_display_config_out;
if (pinfo->early_config)
ret = pinfo->early_config((void *)pinfo);
ret = mdp_dsi_video_config(pinfo, &(panel->fb));
if (ret)
goto msm_display_config_out;
break;
int msm_display_on()
{
... ...
case MIPI_VIDEO_PANEL:
dprintf(INFO, "Turn on MIPI_VIDEO_PANEL.\n");
ret = mdp_dsi_video_on(pinfo);
if (ret)
goto msm_display_on_out;
ret = mdss_dsi_post_on(panel);
if (ret)
goto msm_display_on_out;
ret = mipi_dsi_on(pinfo);
if (ret)
goto msm_display_on_out;
break;
... ...
}
① 调用mdp_dsi_video_on()使能DSI VIDEO
② mdss_dsi_post_on()使用初始化命令来初始化panel,对应qcom,mdss-dsi-on-command部分。
int mdss_dsi_post_on(struct msm_fb_panel_data *panel)
{
int ret = 0;
struct msm_panel_info *pinfo = &(panel->panel_info);
if (pinfo->mipi.cmds_post_tg) {
ret = mdss_dsi_panel_initialize(&pinfo->mipi, pinfo->mipi.broadcast);
if (ret) {
dprintf(CRITICAL, "dsi panel init error\n");
}
}
return ret;
}
③ mipi_dsi_on()
int mipi_dsi_on(struct msm_panel_info *pinfo)
{
int ret = NO_ERROR;
unsigned long ReadValue;
unsigned long count = 0;
ReadValue = readl(pinfo->mipi.ctl_base + INT_CTRL) & 0x00010000;
mdelay(10);
while (ReadValue != 0x00010000) {
ReadValue = readl(pinfo->mipi.ctl_base + INT_CTRL) & 0x00010000;
count++;
if (count > 0xffff) {
dprintf(CRITICAL, "Video lane test failed\n");
return ERROR;
}
}
dprintf(INFO, "Video lane tested successfully\n");
return ret;
}
对应调用mdss_dsi_bl_enable()--->panel_backlight_ctrl(enable)--->target_backlight_ctrl(panelstruct.backlightinfo,enable)
可知根据panelstruct.backlightinfo来进行背光控制,而panelstruct.backlightinfo在oem_panel_select()--->init_panel_data()被赋值
panelstruct->backlightinfo =&xxx_video_backlight;
static int mdss_dsi_bl_enable(uint8_t enable)
{
int ret = NO_ERROR;
ret = panel_backlight_ctrl(enable);
if (ret)
dprintf(CRITICAL, "Backlight %s failed\n", enable ? "enable" :
"disable");
return ret;
}
至此,屏幕已经显示第一帧画面,且背光也是正常亮起。lk的显示已经完成。
其实LK还有一步很重要的工作,就是把我们识别到的屏幕信息传递给kernel,它是如何传递的呢?下一篇小文档将会单独讲解该信息的传递。