Skip to contentSkip to conversation

drm/msm/dp: update is_connected status base on sink count at dp_pm_resume()

PATCH Superseded Kuogee Hsieh 2 participants 3 messages Jul 28, 2021 – Aug 2, 2021

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/msm/dp: update is_connected status base on sink count at dp_pm_resume()

Currently at dp_pm_resume() is_connected state is decided base on hpd connection status only. This will put is_connected in wrongly "true" state at the scenario that dongle attached to DUT but without hmdi cable connecting to it. Fix this problem by adding read sink count from dongle and decided is_connected state base on both sink count and hpd connection status.

---
 drivers/gpu/drm/msm/dp/dp_display.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +21 -2
index 2b660e9..9bcb261 100644
@@ -1308,6 +1308,17 @@ static int dp_display_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static int dp_get_sink_count(struct dp_display_private *dp)
+{
+	u8 sink_count;
+
+	sink_count = drm_dp_read_sink_count(dp->aux);
+	if (sink_count < 0)
+		return 0;
+
+	return sink_count;
+}
+
 static int dp_pm_resume(struct device *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev);
@@ -1327,14 +1338,22 @@ static int dp_pm_resume(struct device *dev)
 
 	dp_catalog_ctrl_hpd_config(dp->catalog);
 
-	status = dp_catalog_link_is_connected(dp->catalog);
+	/*
+	 * set sink to normal operation mode -- D0
+	 * before dpcd read
+	 */
+	dp_link_psm_config(dp->link, &dp->panel->link_info, false);
 
+	if ((status = dp_catalog_link_is_connected(dp->catalog)))
+		dp->link->sink_count = dp_get_sink_count(dp);
+	else
+		dp->link->sink_count = 0;
 	/*
 	 * can not declared display is connected unless
 	 * HDMI cable is plugged in and sink_count of
 	 * dongle become 1
 	 */
-	if (status && dp->link->sink_count)
+	if (dp->link->sink_count)
 		dp->dp_display.is_connected = true;
 	else
 		dp->dp_display.is_connected = false;
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

Quoting Kuogee Hsieh (2021-07-28 14:30:54)

Quoted 6 lines

Currently at dp_pm_resume() is_connected state is decided base on hpd connection status only. This will put is_connected in wrongly "true" state at the scenario that dongle attached to DUT but without hmdi cable connecting to it. Fix this problem by adding read sink count from dongle and decided is_connected state base on both sink count and hpd connection status.

Please add a Fixes tag.

Quoted 10 lines
---
 drivers/gpu/drm/msm/dp/dp_display.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +0 -0
index 2b660e9..9bcb261 100644

drivers/gpu/drm/msm/dp/dp_display.c static int dp_display_remove(struct platform_device *pdev) · line 1315

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_display.c +5 -0
@@ -1308,6 +1308,17 @@ static int dp_display_remove(struct platform_device *pdev)
        return 0;
 }
 
+static int dp_get_sink_count(struct dp_display_private *dp)
+{
+       u8 sink_count;
+
+       sink_count = drm_dp_read_sink_count(dp->aux);

drm_dp_read_sink_count() returns an int, not a u8. Comparing a u8 to less than zero doesn't make any sense as it isn't signed.

drivers/gpu/drm/msm/dp/dp_display.c static int dp_display_remove(struct platform_device *pdev) · line 1320

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_display.c +5 -0
+       if (sink_count < 0)
+               return 0;
+
+       return sink_count;
+}

We can drop this function and just have an int count in dp_pm_resume() that is compared to < 0 and then ignored.

Quoted 7 lines
drivers/gpu/drm/msm/dp/dp_display.c +1 -0
+
 static int dp_pm_resume(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
@@ -1327,14 +1338,22 @@ static int dp_pm_resume(struct device *dev)
 
        dp_catalog_ctrl_hpd_config(dp->catalog);

drivers/gpu/drm/msm/dp/dp_display.c static int dp_pm_resume(struct device *dev) · line 1348

Quoted 10 lines
drivers/gpu/drm/msm/dp/dp_display.c +7 -1
 
-       status = dp_catalog_link_is_connected(dp->catalog);
+       /*
+        * set sink to normal operation mode -- D0
+        * before dpcd read
+        */
+       dp_link_psm_config(dp->link, &dp->panel->link_info, false);
 
+       if ((status = dp_catalog_link_is_connected(dp->catalog)))
+               dp->link->sink_count = dp_get_sink_count(dp);

Do we need to call drm_dp_read_sink_count_cap() as well?

drivers/gpu/drm/msm/dp/dp_display.c static int dp_pm_resume(struct device *dev) · line 1337

Quoted 8 lines
drivers/gpu/drm/msm/dp/dp_display.c +2 -1
+       else
+               dp->link->sink_count = 0;
        /*
         * can not declared display is connected unless
         * HDMI cable is plugged in and sink_count of
         * dongle become 1
         */
-       if (status && dp->link->sink_count)

Is 'status' used anymore? If not, please remove it.

Quoted 4 lines
drivers/gpu/drm/msm/dp/dp_display.c +1 -0
+       if (dp->link->sink_count)
                dp->dp_display.is_connected = true;
        else
                dp->dp_display.is_connected = false;
#2 lore raw
Quoted 57 lines · Stephen Boyd

Quoting Kuogee Hsieh (2021-07-28 14:30:54)

Quoted 6 lines

Currently at dp_pm_resume() is_connected state is decided base on hpd connection status only. This will put is_connected in wrongly "true" state at the scenario that dongle attached to DUT but without hmdi cable connecting to it. Fix this problem by adding read sink count from dongle and decided is_connected state base on both sink count and hpd connection status.

Please add a Fixes tag.

Quoted 10 lines
---
 drivers/gpu/drm/msm/dp/dp_display.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/dp/dp_display.c +0 -0
index 2b660e9..9bcb261 100644

drivers/gpu/drm/msm/dp/dp_display.c static int dp_display_remove(struct · line 1316

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_display.c +5 -0
@@ -1308,6 +1308,17 @@ static int dp_display_remove(struct 
 platform_device *pdev)
        return 0;
 }
 
+static int dp_get_sink_count(struct dp_display_private *dp)
+{
+       u8 sink_count;
+
+       sink_count = drm_dp_read_sink_count(dp->aux);

drm_dp_read_sink_count() returns an int, not a u8. Comparing a u8 to less than zero doesn't make any sense as it isn't signed.

drivers/gpu/drm/msm/dp/dp_display.c static int dp_display_remove(struct platform_device *pdev) · line 1320

Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_display.c +5 -0
+       if (sink_count < 0)
+               return 0;
+
+       return sink_count;
+}

We can drop this function and just have an int count in dp_pm_resume() that is compared to < 0 and then ignored.

Quoted 15 lines
drivers/gpu/drm/msm/dp/dp_display.c +1 -0
+
 static int dp_pm_resume(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
drivers/gpu/drm/msm/dp/dp_display.c +5 -1
@@ -1327,14 +1338,22 @@ static int dp_pm_resume(struct device *dev)
 
        dp_catalog_ctrl_hpd_config(dp->catalog);
 
-       status = dp_catalog_link_is_connected(dp->catalog);
+       /*
+        * set sink to normal operation mode -- D0
+        * before dpcd read
+        */
+       dp_link_psm_config(dp->link, &dp->panel->link_info, false);
 
Quoted 4 lines

drivers/gpu/drm/msm/dp/dp_display.c static int dp_pm_resume(struct device *dev) · line 1348

Quoted 2 lines
drivers/gpu/drm/msm/dp/dp_display.c +2 -0
+       if ((status = dp_catalog_link_is_connected(dp->catalog)))
+               dp->link->sink_count = dp_get_sink_count(dp);

Do we need to call drm_dp_read_sink_count_cap() as well?

no, we only need sink_count

Quoted 11 lines

drivers/gpu/drm/msm/dp/dp_display.c static int dp_pm_resume(struct device *dev) · line 1337

Quoted 9 lines
drivers/gpu/drm/msm/dp/dp_display.c +2 -1
+       else
+               dp->link->sink_count = 0;
        /*
         * can not declared display is connected unless
         * HDMI cable is plugged in and sink_count of
         * dongle become 1
         */
-       if (status && dp->link->sink_count)

Is 'status' used anymore? If not, please remove it.

Yes, it still used which used to decided to perform dpcd read sink count or not

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/msm/dp/dp_display.c +1 -0
+       if (dp->link->sink_count)
                dp->dp_display.is_connected = true;
        else
                dp->dp_display.is_connected = false;