Skip to contentSkip to conversation

Refactor MediaTek DP drivers

PATCH Superseded Bo-Chen Chen 3 participants 9 messages Sep 15, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Refactor MediaTek DP drivers

For this series, we do some clean-up and fix a build warning. This series is based on linux-next-20220914.

Bo-Chen Chen (3):
drm/mediatek: dp: Refactor drivers in mtk_dp_bdg_detect() drm/mediatek: dp: Remove unused register definitions drm/mediatek: dp: Fix warning in mtk_dp_video_mute()

 drivers/gpu/drm/mediatek/mtk_dp.c     | 70 ++++++++++++++-------------
 drivers/gpu/drm/mediatek/mtk_dp_reg.h |  6 ---
 2 files changed, 36 insertions(+), 40 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/3 drm/mediatek: dp: Refactor drivers in mtk_dp_bdg_detect()

It is more clear to modify this in mtk_dp_bdg_detect().

---
 drivers/gpu/drm/mediatek/mtk_dp.c | 66 ++++++++++++++++---------------
 1 file changed, 34 insertions(+), 32 deletions(-)
drivers/gpu/drm/mediatek/mtk_dp.c +34 -32
index dfa942ca62da..c72c646e25e9 100644
@@ -1933,39 +1933,41 @@ static enum drm_connector_status mtk_dp_bdg_detect(struct drm_bridge *bridge)
 	bool enabled = mtk_dp->enabled;
 	u8 sink_count = 0;
 
-	if (mtk_dp->train_info.cable_plugged_in) {
-		if (!enabled) {
-			/* power on aux */
-			mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE,
-					   DP_PWR_STATE_BANDGAP_TPLL_LANE,
-					   DP_PWR_STATE_MASK);
-
-			/* power on panel */
-			drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0);
-			usleep_range(2000, 5000);
-		}
-		/*
-		 * Some dongles still source HPD when they do not connect to any
-		 * sink device. To avoid this, we need to read the sink count
-		 * to make sure we do connect to sink devices. After this detect
-		 * function, we just need to check the HPD connection to check
-		 * whether we connect to a sink device.
-		 */
-		drm_dp_dpcd_readb(&mtk_dp->aux, DP_SINK_COUNT, &sink_count);
-		if (DP_GET_SINK_COUNT(sink_count))
-			ret = connector_status_connected;
-
-		if (!enabled) {
-			/* power off panel */
-			drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3);
-			usleep_range(2000, 3000);
-
-			/* power off aux */
-			mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE,
-					   DP_PWR_STATE_BANDGAP_TPLL,
-					   DP_PWR_STATE_MASK);
-		}
+	if (!mtk_dp->train_info.cable_plugged_in)
+		return ret;
+
+	if (!enabled) {
+		/* power on aux */
+		mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE,
+				   DP_PWR_STATE_BANDGAP_TPLL_LANE,
+				   DP_PWR_STATE_MASK);
+
+		/* power on panel */
+		drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0);
+		usleep_range(2000, 5000);
 	}
+	/*
+	 * Some dongles still source HPD when they do not connect to any
+	 * sink device. To avoid this, we need to read the sink count
+	 * to make sure we do connect to sink devices. After this detect
+	 * function, we just need to check the HPD connection to check
+	 * whether we connect to a sink device.
+	 */
+	drm_dp_dpcd_readb(&mtk_dp->aux, DP_SINK_COUNT, &sink_count);
+	if (DP_GET_SINK_COUNT(sink_count))
+		ret = connector_status_connected;
+
+	if (!enabled) {
+		/* power off panel */
+		drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3);
+		usleep_range(2000, 3000);
+
+		/* power off aux */
+		mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE,
+				   DP_PWR_STATE_BANDGAP_TPLL,
+				   DP_PWR_STATE_MASK);
+	}
+
 	return ret;
 }
 
Signature · 1 line
2.18.0
#6 lore raw

PATCH 3/3 drm/mediatek: dp: Fix warning in mtk_dp_video_mute()

In reply to Bo-Chen Chen

Warning:
../drivers/gpu/drm/mediatek/mtk_dp.c: In function ‘mtk_dp_video_mute’:
../drivers/gpu/drm/mediatek/mtk_dp.c:947:23: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
947 | dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: 0x%x, ret: 0x%lx-0x%lx\n",

      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../include/linux/dev_printk.h:129:27: note: in definition of macro ‘dev_printk’
129 | _dev_printk(level, dev, fmt, ##__VA_ARGS__); \
| ^~~
../include/linux/dev_printk.h:163:31: note: in expansion of macro ‘dev_fmt’
163 | dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
| ^~~~~~~
../drivers/gpu/drm/mediatek/mtk_dp.c:947:2: note: in expansion of macro ‘dev_dbg’

  947 |  dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: 0x%x, ret: 0x%lx-0x%lx\n",
      |  ^~~~~~~
../drivers/gpu/drm/mediatek/mtk_dp.c:947:36: note: format string is defined here
  947 |  dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: 0x%x, ret: 0x%lx-0x%lx\n",
      |                                   ~^
      |                                    |
      |                                    unsigned int
      |                                   %lx

To fix this issue, we use %s to replace 0x%x.

---
 drivers/gpu/drm/mediatek/mtk_dp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/mediatek/mtk_dp.c +2 -2
index c72c646e25e9..d58e98b2f83a 100644
@@ -1222,8 +1222,8 @@ static void mtk_dp_video_mute(struct mtk_dp *mtk_dp, bool enable)
 		      mtk_dp->data->smc_cmd, enable,
 		      0, 0, 0, 0, 0, &res);
 
-	dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: 0x%x, ret: 0x%lx-0x%lx\n",
-		mtk_dp->data->smc_cmd, enable, res.a0, res.a1);
+	dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: %s, ret: 0x%lx-0x%lx\n",
+		mtk_dp->data->smc_cmd, enable ? "enable" : "disable", res.a0, res.a1);
 }
 
 static void mtk_dp_audio_mute(struct mtk_dp *mtk_dp, bool mute)
Signature · 1 line
2.18.0
#3 lore raw

PATCH 2/3 drm/mediatek: dp: Remove unused register definitions

In reply to Bo-Chen Chen

Some definitions in mtk_dp_reg.h are not used, so remove these redundant codes.

---
 drivers/gpu/drm/mediatek/mtk_dp_reg.h | 6 ------
 1 file changed, 6 deletions(-)
drivers/gpu/drm/mediatek/mtk_dp_reg.h +0 -6
index 096ad6572a5e..84e38cef03c2 100644
@@ -153,8 +153,6 @@
 #define CH_STATUS_1_DP_ENC0_P0_MASK			GENMASK(15, 0)
 #define MTK_DP_ENC0_P0_3094			0x3094
 #define CH_STATUS_2_DP_ENC0_P0_MASK			GENMASK(7, 0)
-#define MTK_DP_ENC0_P0_30A0			0x30a0
-#define DP_ENC0_30A0_MASK				(BIT(7) | BIT(8) | BIT(12))
 #define MTK_DP_ENC0_P0_30A4			0x30a4
 #define AU_TS_CFG_DP_ENC0_P0_MASK			GENMASK(7, 0)
 #define MTK_DP_ENC0_P0_30A8			0x30a8
@@ -171,8 +169,6 @@
 #define MTK_DP_ENC0_P0_312C			0x312c
 #define ASP_HB2_DP_ENC0_P0_MASK				GENMASK(7, 0)
 #define ASP_HB3_DP_ENC0_P0_MASK				GENMASK(15, 8)
-#define MTK_DP_ENC0_P0_3130			0x3130
-#define MTK_DP_ENC0_P0_3138			0x3138
 #define MTK_DP_ENC0_P0_3154			0x3154
 #define PGEN_HTOTAL_DP_ENC0_P0_MASK			GENMASK(13, 0)
 #define MTK_DP_ENC0_P0_3158			0x3158
@@ -206,8 +202,6 @@
 #define SDP_PACKET_TYPE_DP_ENC1_P0_MASK			GENMASK(4, 0)
 #define SDP_PACKET_W_DP_ENC1_P0				BIT(5)
 #define SDP_PACKET_W_DP_ENC1_P0_MASK			BIT(5)
-#define MTK_DP_ENC1_P0_328C			0x328c
-#define VSC_DATA_RDY_VESA_DP_ENC1_P0_MASK		BIT(7)
 #define MTK_DP_ENC1_P0_3300			0x3300
 #define VIDEO_AFIFO_RDY_SEL_DP_ENC1_P0_VAL		2
 #define VIDEO_AFIFO_RDY_SEL_DP_ENC1_P0_MASK		GENMASK(9, 8)
Signature · 1 line
2.18.0
#7 lore raw

Re: [PATCH 3/3] drm/mediatek: dp: Fix warning in mtk_dp_video_mute()

In reply to Bo-Chen Chen

Il 15/09/22 09:50, Bo-Chen Chen ha scritto:

Quoted 24 lines

Warning:
../drivers/gpu/drm/mediatek/mtk_dp.c: In function ‘mtk_dp_video_mute’:
../drivers/gpu/drm/mediatek/mtk_dp.c:947:23: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
947 | dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: 0x%x, ret: 0x%lx-0x%lx\n",

       |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../include/linux/dev_printk.h:129:27: note: in definition of macro ‘dev_printk’
129 | _dev_printk(level, dev, fmt, ##__VA_ARGS__); \
| ^~~
../include/linux/dev_printk.h:163:31: note: in expansion of macro ‘dev_fmt’
163 | dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
| ^~~~~~~
../drivers/gpu/drm/mediatek/mtk_dp.c:947:2: note: in expansion of macro ‘dev_dbg’

   947 |  dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: 0x%x, ret: 0x%lx-0x%lx\n",
       |  ^~~~~~~
../drivers/gpu/drm/mediatek/mtk_dp.c:947:36: note: format string is defined here
   947 |  dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: 0x%x, ret: 0x%lx-0x%lx\n",
       |                                   ~^
       |                                    |
       |                                    unsigned int
       |                                   %lx
Quoted 4 lines

To fix this issue, we use %s to replace 0x%x.

Please add a Fixes tag to this commit.

Thanks,
Angelo.

#2 lore raw

Re: [PATCH 1/3] drm/mediatek: dp: Refactor drivers in mtk_dp_bdg_detect()

In reply to Bo-Chen Chen

Il 15/09/22 09:50, Bo-Chen Chen ha scritto:

Quoted 1 line

It is more clear to modify this in mtk_dp_bdg_detect().

I agree with this commit. Since you anyway have to send a v2 of this series, please clarify the commit description and title, something like:

drm/mediatek: dp: Reduce indentation in mtk_dp_bdg_detect()

In order to improve human readability, reduce the indentation by returning early if the dp/edp cable is not plugged in.

Cheers,
Angelo

maintainer Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] drm/mediatek: dp: Remove unused register definitions

In reply to Bo-Chen Chen
Quoted 4 lines · Bo-Chen Chen

Some definitions in mtk_dp_reg.h are not used, so remove these redundant codes.

Quoted 35 lines
---
  drivers/gpu/drm/mediatek/mtk_dp_reg.h | 6 ------
  1 file changed, 6 deletions(-)
drivers/gpu/drm/mediatek/mtk_dp_reg.h +0 -6
index 096ad6572a5e..84e38cef03c2 100644
@@ -153,8 +153,6 @@
  #define CH_STATUS_1_DP_ENC0_P0_MASK			GENMASK(15, 0)
  #define MTK_DP_ENC0_P0_3094			0x3094
  #define CH_STATUS_2_DP_ENC0_P0_MASK			GENMASK(7, 0)
-#define MTK_DP_ENC0_P0_30A0			0x30a0
-#define DP_ENC0_30A0_MASK				(BIT(7) | BIT(8) | BIT(12))
  #define MTK_DP_ENC0_P0_30A4			0x30a4
  #define AU_TS_CFG_DP_ENC0_P0_MASK			GENMASK(7, 0)
  #define MTK_DP_ENC0_P0_30A8			0x30a8
@@ -171,8 +169,6 @@
  #define MTK_DP_ENC0_P0_312C			0x312c
  #define ASP_HB2_DP_ENC0_P0_MASK				GENMASK(7, 0)
  #define ASP_HB3_DP_ENC0_P0_MASK				GENMASK(15, 8)
-#define MTK_DP_ENC0_P0_3130			0x3130
-#define MTK_DP_ENC0_P0_3138			0x3138
  #define MTK_DP_ENC0_P0_3154			0x3154
  #define PGEN_HTOTAL_DP_ENC0_P0_MASK			GENMASK(13, 0)
  #define MTK_DP_ENC0_P0_3158			0x3158
@@ -206,8 +202,6 @@
  #define SDP_PACKET_TYPE_DP_ENC1_P0_MASK			GENMASK(4, 0)
  #define SDP_PACKET_W_DP_ENC1_P0				BIT(5)
  #define SDP_PACKET_W_DP_ENC1_P0_MASK			BIT(5)
-#define MTK_DP_ENC1_P0_328C			0x328c
-#define VSC_DATA_RDY_VESA_DP_ENC1_P0_MASK		BIT(7)
  #define MTK_DP_ENC1_P0_3300			0x3300
  #define VIDEO_AFIFO_RDY_SEL_DP_ENC1_P0_VAL		2
  #define VIDEO_AFIFO_RDY_SEL_DP_ENC1_P0_MASK		GENMASK(9, 8)
maintainer Reviewed-by on v1 3/3
#8 lore raw

Re: [PATCH 3/3] drm/mediatek: dp: Fix warning in mtk_dp_video_mute()

In reply to Bo-Chen Chen
Quoted 24 lines · Bo-Chen Chen

Warning:
../drivers/gpu/drm/mediatek/mtk_dp.c: In function ‘mtk_dp_video_mute’:
../drivers/gpu/drm/mediatek/mtk_dp.c:947:23: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 4 has type ‘long unsigned int’ [-Wformat=]
947 | dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: 0x%x, ret: 0x%lx-0x%lx\n",

       |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../include/linux/dev_printk.h:129:27: note: in definition of macro ‘dev_printk’
129 | _dev_printk(level, dev, fmt, ##__VA_ARGS__); \
| ^~~
../include/linux/dev_printk.h:163:31: note: in expansion of macro ‘dev_fmt’
163 | dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
| ^~~~~~~
../drivers/gpu/drm/mediatek/mtk_dp.c:947:2: note: in expansion of macro ‘dev_dbg’

   947 |  dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: 0x%x, ret: 0x%lx-0x%lx\n",
       |  ^~~~~~~
../drivers/gpu/drm/mediatek/mtk_dp.c:947:36: note: format string is defined here
   947 |  dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: 0x%x, ret: 0x%lx-0x%lx\n",
       |                                   ~^
       |                                    |
       |                                    unsigned int
       |                                   %lx
Quoted 4 lines

To fix this issue, we use %s to replace 0x%x.

Quoted 19 lines
---
  drivers/gpu/drm/mediatek/mtk_dp.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/mediatek/mtk_dp.c +2 -2
index c72c646e25e9..d58e98b2f83a 100644
@@ -1222,8 +1222,8 @@ static void mtk_dp_video_mute(struct mtk_dp *mtk_dp, bool enable)
  		      mtk_dp->data->smc_cmd, enable,
  		      0, 0, 0, 0, 0, &res);
 
-	dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: 0x%x, ret: 0x%lx-0x%lx\n",
-		mtk_dp->data->smc_cmd, enable, res.a0, res.a1);
+	dev_dbg(mtk_dp->dev, "smc cmd: 0x%x, p1: %s, ret: 0x%lx-0x%lx\n",
+		mtk_dp->data->smc_cmd, enable ? "enable" : "disable", res.a0, res.a1);
  }
 
  static void mtk_dp_audio_mute(struct mtk_dp *mtk_dp, bool mute)