lcd: mipi-dsi: optimize retry_enable management [2/2]
authorEvoke Zhang <evoke.zhang@amlogic.com>
Mon, 21 May 2018 06:25:07 +0000 (14:25 +0800)
committerYixun Lan <yixun.lan@amlogic.com>
Mon, 28 May 2018 03:23:03 +0000 (20:23 -0700)
PD#166330: lcd: mipi-dsi: optimize retry_enable management,
change mipi-dsi check_state after retry flow finished.
fix issue: mipi panel status is incorrect sometimes when lcd enable.

Change-Id: I5fc30f46589274b1cc2fda735c166779233ce1c2
Signed-off-by: Evoke Zhang <evoke.zhang@amlogic.com>
drivers/amlogic/drm/am_meson_lcd.c
drivers/amlogic/media/vout/lcd/lcd_common.c
drivers/amlogic/media/vout/lcd/lcd_tablet/mipi_dsi_util.c
drivers/amlogic/media/vout/lcd/lcd_vout.c
include/linux/amlogic/media/vout/lcd/lcd_vout.h

index 61e00a9..462338f 100644 (file)
@@ -255,7 +255,6 @@ static void am_lcd_encoder_enable(struct drm_encoder *encoder)
 {
        enum vmode_e vmode = get_current_vmode();
        struct am_drm_lcd_s *lcd = encoder_to_lcd(encoder);
-       int retry_cnt = 0;
 
        if (!lcd)
                return;
@@ -272,14 +271,20 @@ static void am_lcd_encoder_enable(struct drm_encoder *encoder)
        mutex_lock(&lcd->lcd_drv->power_mutex);
        aml_lcd_notifier_call_chain(LCD_EVENT_PREPARE, NULL);
        aml_lcd_notifier_call_chain(LCD_EVENT_ENABLE, NULL);
-       while (lcd->lcd_drv->lcd_config->retry_enable) {
-               if (retry_cnt++ > LCD_ENABLE_RETRY_MAX)
+
+       lcd->lcd_drv->lcd_config->retry_enable_cnt = 0;
+       while (lcd->lcd_drv->lcd_config->retry_enable_flag) {
+               if (lcd->lcd_drv->lcd_config->retry_enable_cnt++ >=
+                       LCD_ENABLE_RETRY_MAX)
                        break;
-               pr_info("am_drm_lcd: retry enable...%d\n", retry_cnt);
-               aml_lcd_notifier_call_chain(LCD_EVENT_DISABLE, NULL);
+               pr_info("am_drm_lcd: retry enable...%d\n",
+                       lcd->lcd_drv->lcd_config->retry_enable_cnt);
+               aml_lcd_notifier_call_chain(LCD_EVENT_IF_POWER_OFF, NULL);
                msleep(1000);
-               aml_lcd_notifier_call_chain(LCD_EVENT_ENABLE, NULL);
+               aml_lcd_notifier_call_chain(LCD_EVENT_IF_POWER_ON, NULL);
        }
+       lcd->lcd_drv->lcd_config->retry_enable_cnt = 0;
+
        mutex_unlock(&lcd->lcd_drv->power_mutex);
        vout_notifier_call_chain(VOUT_EVENT_MODE_CHANGE, &vmode);
        pr_info("am_drm_lcd: %s %d\n", __func__, __LINE__);
index b162b82..7af5172 100644 (file)
@@ -999,15 +999,15 @@ void lcd_venc_change(struct lcd_config_s *pconf)
 
 void lcd_if_enable_retry(struct lcd_config_s *pconf)
 {
-       int retry_cnt = 0;
-
-       while (pconf->retry_enable) {
-               if (retry_cnt++ > LCD_ENABLE_RETRY_MAX)
+       pconf->retry_enable_cnt = 0;
+       while (pconf->retry_enable_flag) {
+               if (pconf->retry_enable_cnt++ >= LCD_ENABLE_RETRY_MAX)
                        break;
-               LCDPR("retry enable...%d\n", retry_cnt);
+               LCDPR("retry enable...%d\n", pconf->retry_enable_cnt);
                aml_lcd_notifier_call_chain(LCD_EVENT_IF_POWER_OFF, NULL);
                msleep(1000);
                aml_lcd_notifier_call_chain(LCD_EVENT_IF_POWER_ON, NULL);
        }
+       pconf->retry_enable_cnt = 0;
 }
 
index c3836fb..d72586c 100644 (file)
@@ -1293,10 +1293,13 @@ static int mipi_dsi_check_state(unsigned char reg, int cnt)
        unsigned char payload[3] = {DT_GEN_RD_1, 1, 0x04};
        char str[100];
        struct aml_lcd_drv_s *lcd_drv = aml_lcd_get_driver();
+       struct dsi_config_s *dconf;
 
-       if (lcd_drv->lcd_config->lcd_control.mipi_config->check_en == 0)
+       dconf = lcd_drv->lcd_config->lcd_control.mipi_config;
+       if (dconf->check_en == 0)
                return 0;
-       LCDPR("%s\n", __func__);
+       if (lcd_debug_print_flag)
+               LCDPR("%s\n", __func__);
 
        rd_data = kmalloc_array(cnt, sizeof(unsigned char), GFP_KERNEL);
        if (rd_data == NULL) {
@@ -1306,20 +1309,13 @@ static int mipi_dsi_check_state(unsigned char reg, int cnt)
 
        payload[2] = reg;
        ret = dsi_read_single(payload, rd_data, cnt);
-       if (ret < 0) {
-               lcd_drv->lcd_config->lcd_control.mipi_config->check_state = 0;
-               lcd_vcbus_setb(L_VCOM_VS_ADDR, 0, 12, 1);
-               kfree(rd_data);
-               return -1;
-       }
+       if (ret < 0)
+               goto mipi_dsi_check_state_err;
        if (ret > cnt) {
                LCDERR("%s: read back cnt is wrong\n", __func__);
-               kfree(rd_data);
-               return -1;
+               goto mipi_dsi_check_state_err;
        }
 
-       lcd_drv->lcd_config->lcd_control.mipi_config->check_state = 1;
-       lcd_vcbus_setb(L_VCOM_VS_ADDR, 1, 12, 1);
        len = sprintf(str, "read reg 0x%02x: ", reg);
        for (i = 0; i < ret; i++) {
                if (i == 0)
@@ -1329,8 +1325,22 @@ static int mipi_dsi_check_state(unsigned char reg, int cnt)
        }
        pr_info("%s\n", str);
 
+       dconf->check_state = 1;
+       lcd_vcbus_setb(L_VCOM_VS_ADDR, 1, 12, 1);
+       lcd_drv->lcd_config->retry_enable_flag = 0;
+       LCDPR("%s: %d\n", __func__, dconf->check_state);
        kfree(rd_data);
        return 0;
+
+mipi_dsi_check_state_err:
+       if (lcd_drv->lcd_config->retry_enable_cnt >= LCD_ENABLE_RETRY_MAX) {
+               dconf->check_state = 0;
+               lcd_vcbus_setb(L_VCOM_VS_ADDR, 0, 12, 1);
+               LCDPR("%s: %d\n", __func__, dconf->check_state);
+       }
+       lcd_drv->lcd_config->retry_enable_flag = 1;
+       kfree(rd_data);
+       return -1;
 }
 
 /* *************************************************************
@@ -1864,13 +1874,6 @@ static void mipi_dsi_link_on(struct lcd_config_s *pconf)
        }
 #endif
 
-       if (dconf->check_en) {
-               if (dconf->check_state == 0)
-                       pconf->retry_enable = 1;
-               else
-                       pconf->retry_enable = 0;
-       }
-
        if (op_mode_disp != op_mode_init) {
                set_mipi_dsi_host(MIPI_DSI_VIRTUAL_CHAN_ID,
                        0, /* Chroma sub sample, only for
@@ -1990,6 +1993,10 @@ void lcd_mipi_dsi_config_set(struct lcd_config_s *pconf)
                }
        }
 
+       /* update check_state */
+       if (dconf->check_en)
+               dconf->check_state = lcd_vcbus_getb(L_VCOM_VS_ADDR, 12, 1);
+
        /* Venc resolution format */
        switch (dconf->phy_switch) {
        case 1: /* standard */
@@ -2048,10 +2055,6 @@ void lcd_mipi_dsi_config_post(struct lcd_config_s *pconf)
 
        /* phy config */
        mipi_dsi_phy_config(&dsi_phy_config, dconf->bit_rate);
-
-       /* update check_state */
-       if (dconf->check_en)
-               dconf->check_state = lcd_vcbus_getb(L_VCOM_VS_ADDR, 12, 1);
 }
 
 static void mipi_dsi_host_on(struct lcd_config_s *pconf)
index 182a62d..4c7a9c6 100644 (file)
@@ -193,7 +193,8 @@ static struct lcd_config_s lcd_config_dft = {
        .lcd_power = &lcd_power_config,
        .pinmux_flag = 0,
        .change_flag = 0,
-       .retry_enable = 0,
+       .retry_enable_flag = 0,
+       .retry_enable_cnt = 0,
 };
 
 static struct vinfo_s lcd_vinfo = {
index 261d25d..a9ccd60 100644 (file)
@@ -362,7 +362,7 @@ struct lcd_clk_gate_ctrl_s {
        struct reset_control *vencl;
 };
 
-#define LCD_ENABLE_RETRY_MAX    2
+#define LCD_ENABLE_RETRY_MAX    3
 struct lcd_config_s {
        char *lcd_propname;
        unsigned int backlight_index;
@@ -374,7 +374,8 @@ struct lcd_config_s {
        struct pinctrl *pin;
        unsigned char pinmux_flag;
        unsigned char change_flag;
-       unsigned char retry_enable;
+       unsigned char retry_enable_flag;
+       unsigned char retry_enable_cnt;
        struct lcd_clk_gate_ctrl_s rstc;
 };