From 2052e95ece6f8bcccc2ed101651090e290056d2a Mon Sep 17 00:00:00 2001
From: Devin Kim <dojip.kim@lge.com>
Date: Thu, 2 Oct 2014 19:33:26 -0700
Subject: [PATCH] msm: mdss: Fix the mis-matched ulps ref count

If there is an error in mdss_dsi_ulps_config_sub(), ulps_ref_count will
not be handled forever. So should restore the value in that case.

Change-Id: Ib30b2f37a508dd4abf0812ab7b36f22a178cac22
Signed-off-by: Devin Kim <dojip.kim@lge.com>
---
 drivers/video/msm/mdss/mdss_dsi.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/video/msm/mdss/mdss_dsi.c b/drivers/video/msm/mdss/mdss_dsi.c
index 7983ff04512c..4c85c4f806e7 100644
--- a/drivers/video/msm/mdss/mdss_dsi.c
+++ b/drivers/video/msm/mdss/mdss_dsi.c
@@ -477,8 +477,8 @@ static int mdss_dsi_ulps_config_sub(struct mdss_dsi_ctrl_pdata *ctrl_pdata,
 	if (enable && ctrl_pdata->ulps_ref_count < 1) {
 		pr_err("%s: Try to enable ulps which has not been disabled"
 			"count = %d\n", __func__, ctrl_pdata->ulps_ref_count);
-		ret = -EINVAL;
-		goto error;
+		mutex_unlock(&ctrl_pdata->ulps_lock);
+		return -EINVAL;
 	}
 
 	if (enable)
@@ -489,8 +489,9 @@ static int mdss_dsi_ulps_config_sub(struct mdss_dsi_ctrl_pdata *ctrl_pdata,
 	if (enable && ctrl_pdata->ulps_ref_count == 0) {
 		/* No need to configure ULPS mode when entering suspend state */
 		if (!pdata->panel_info.panel_power_on) {
-			pr_err("%s: panel off. returning\n", __func__);
-			goto error;
+			pr_warn("%s: panel off. returning\n", __func__);
+			mutex_unlock(&ctrl_pdata->ulps_lock);
+			return 0;
 		}
 
 		if (__mdss_dsi_clk_enabled(ctrl_pdata, DSI_LINK_CLKS)) {
@@ -610,7 +611,14 @@ static int mdss_dsi_ulps_config_sub(struct mdss_dsi_ctrl_pdata *ctrl_pdata,
 	pr_debug("%s: DSI lane status = 0x%08x. Ulps %s\n", __func__,
 		lane_status, enable ? "enabled" : "disabled");
 
+	mutex_unlock(&ctrl_pdata->ulps_lock);
+	return 0;
+
 error:
+	if (enable)
+		ctrl_pdata->ulps_ref_count++;
+	else
+		ctrl_pdata->ulps_ref_count--;
 
 	mutex_unlock(&ctrl_pdata->ulps_lock);
 
-- 
GitLab