Skip to contentSkip to conversation

drm/amd/display/dc: Remove dc code repetition

PATCH In review Joao Paulo Pereira da Silva 2 participants 2 messages Jun 13, 2024 – Jul 4, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amd/display/dc: Remove dc code repetition

Code is repeated in functions optc1_enable_crtc (dc/optc/dcn10/dcn10_optc.c) and optc2_enable_crtc (dc/optc/dcn20/dcn20_optc.c).

So, remove it with the creation of a macro.

---
 .../amd/display/dc/optc/dcn10/dcn10_optc.c    | 29 ++-----------------
 .../amd/display/dc/optc/dcn10/dcn10_optc.h    | 27 +++++++++++++++++
 .../amd/display/dc/optc/dcn20/dcn20_optc.c    | 29 ++-----------------
 3 files changed, 33 insertions(+), 52 deletions(-)
drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.c +3 -26
index 5574bc628053..facdeeb41250 100644
@@ -41,6 +41,8 @@
 
 #define STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN 0x100
 
+#define OPTC_SRC_SEL_FIELD OPTC_SRC_SEL
+
 /**
  * apply_front_porch_workaround() - This is a workaround for a bug that has
  *                                  existed since R5xx and has not been fixed
@@ -517,32 +519,7 @@ void optc1_enable_optc_clock(struct timing_generator *optc, bool enable)
  */
 static bool optc1_enable_crtc(struct timing_generator *optc)
 {
-	/* TODO FPGA wait for answer
-	 * OTG_MASTER_UPDATE_MODE != CRTC_MASTER_UPDATE_MODE
-	 * OTG_MASTER_UPDATE_LOCK != CRTC_MASTER_UPDATE_LOCK
-	 */
-	struct optc *optc1 = DCN10TG_FROM_TG(optc);
-
-	/* opp instance for OTG. For DCN1.0, ODM is remoed.
-	 * OPP and OPTC should 1:1 mapping
-	 */
-	REG_UPDATE(OPTC_DATA_SOURCE_SELECT,
-			OPTC_SRC_SEL, optc->inst);
-
-	/* VTG enable first is for HW workaround */
-	REG_UPDATE(CONTROL,
-			VTG0_ENABLE, 1);
-
-	REG_SEQ_START();
-
-	/* Enable CRTC */
-	REG_UPDATE_2(OTG_CONTROL,
-			OTG_DISABLE_POINT_CNTL, 3,
-			OTG_MASTER_EN, 1);
-
-	REG_SEQ_SUBMIT();
-	REG_SEQ_WAIT_DONE();
-
+	_optc1_enable_crtc(optc);
 	return true;
 }
 
drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h +27 -0
index 2f3bd7648ba7..aea80fa6fe91 100644
@@ -604,4 +604,31 @@ struct dcn_optc_mask {
 
 void dcn10_timing_generator_init(struct optc *optc);
 
+#define _optc1_enable_crtc(optc)					\
+	do {								\
+		/* TODO FPGA wait for answer */				\
+		/* OTG_MASTER_UPDATE_MODE != CRTC_MASTER_UPDATE_MODE */	\
+		/* OTG_MASTER_UPDATE_LOCK != CRTC_MASTER_UPDATE_LOCK */	\
+		struct optc *optc1 = DCN10TG_FROM_TG(optc);		\
+									\
+		/* opp instance for OTG. For DCN1.0, ODM is remoed. */	\
+		/* OPP and OPTC should 1:1 mapping */			\
+		REG_UPDATE(OPTC_DATA_SOURCE_SELECT,			\
+				OPTC_SRC_SEL_FIELD, optc->inst);	\
+									\
+		/* VTG enable first is for HW workaround */		\
+		REG_UPDATE(CONTROL,					\
+				VTG0_ENABLE, 1);			\
+									\
+		REG_SEQ_START();					\
+									\
+		/* Enable CRTC */					\
+		REG_UPDATE_2(OTG_CONTROL,				\
+				OTG_DISABLE_POINT_CNTL, 3,		\
+				OTG_MASTER_EN, 1);			\
+									\
+		REG_SEQ_SUBMIT();					\
+		REG_SEQ_WAIT_DONE();					\
+	} while (0)
+
 #endif /* __DC_TIMING_GENERATOR_DCN10_H__ */
drivers/gpu/drm/amd/display/dc/optc/dcn20/dcn20_optc.c +3 -26
index d6f095b4555d..012e0c52aeec 100644
@@ -37,6 +37,8 @@
 #define FN(reg_name, field_name) \
 	optc1->tg_shift->field_name, optc1->tg_mask->field_name
 
+#define OPTC_SRC_SEL_FIELD OPTC_SEG0_SRC_SEL
+
 /**
  * optc2_enable_crtc() - Enable CRTC - call ASIC Control Object to enable Timing generator.
  *
@@ -47,32 +49,7 @@
  */
 bool optc2_enable_crtc(struct timing_generator *optc)
 {
-	/* TODO FPGA wait for answer
-	 * OTG_MASTER_UPDATE_MODE != CRTC_MASTER_UPDATE_MODE
-	 * OTG_MASTER_UPDATE_LOCK != CRTC_MASTER_UPDATE_LOCK
-	 */
-	struct optc *optc1 = DCN10TG_FROM_TG(optc);
-
-	/* opp instance for OTG. For DCN1.0, ODM is remoed.
-	 * OPP and OPTC should 1:1 mapping
-	 */
-	REG_UPDATE(OPTC_DATA_SOURCE_SELECT,
-			OPTC_SEG0_SRC_SEL, optc->inst);
-
-	/* VTG enable first is for HW workaround */
-	REG_UPDATE(CONTROL,
-			VTG0_ENABLE, 1);
-
-	REG_SEQ_START();
-
-	/* Enable CRTC */
-	REG_UPDATE_2(OTG_CONTROL,
-			OTG_DISABLE_POINT_CNTL, 3,
-			OTG_MASTER_EN, 1);
-
-	REG_SEQ_SUBMIT();
-	REG_SEQ_WAIT_DONE();
-
+	_optc1_enable_crtc(optc);
 	return true;
 }
 
Signature · 1 line
2.44.0
#1 lore raw

Hi Joao,

First of all, thanks for your patch. Follows some of my comments:

Quoted 1 line · Joao Paulo Pereira da Silva

You can drop the dc part in the commit title. Also, the title should highlight that you are decoupling one part of the code in a single place to avoid duplication.

Quoted 65 lines

Code is repeated in functions optc1_enable_crtc (dc/optc/dcn10/dcn10_optc.c) and optc2_enable_crtc (dc/optc/dcn20/dcn20_optc.c).

So, remove it with the creation of a macro.

---
  .../amd/display/dc/optc/dcn10/dcn10_optc.c    | 29 ++-----------------
  .../amd/display/dc/optc/dcn10/dcn10_optc.h    | 27 +++++++++++++++++
  .../amd/display/dc/optc/dcn20/dcn20_optc.c    | 29 ++-----------------
  3 files changed, 33 insertions(+), 52 deletions(-)
drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.c +3 -26
index 5574bc628053..facdeeb41250 100644
@@ -41,6 +41,8 @@
 
  #define STATIC_SCREEN_EVENT_MASK_RANGETIMING_DOUBLE_BUFFER_UPDATE_EN 0x100
 
+#define OPTC_SRC_SEL_FIELD OPTC_SRC_SEL
+
  /**
   * apply_front_porch_workaround() - This is a workaround for a bug that has
   *                                  existed since R5xx and has not been fixed
@@ -517,32 +519,7 @@ void optc1_enable_optc_clock(struct timing_generator *optc, bool enable)
   */
  static bool optc1_enable_crtc(struct timing_generator *optc)
  {
-	/* TODO FPGA wait for answer
-	 * OTG_MASTER_UPDATE_MODE != CRTC_MASTER_UPDATE_MODE
-	 * OTG_MASTER_UPDATE_LOCK != CRTC_MASTER_UPDATE_LOCK
-	 */
-	struct optc *optc1 = DCN10TG_FROM_TG(optc);
-
-	/* opp instance for OTG. For DCN1.0, ODM is remoed.
-	 * OPP and OPTC should 1:1 mapping
-	 */
-	REG_UPDATE(OPTC_DATA_SOURCE_SELECT,
-			OPTC_SRC_SEL, optc->inst);
-
-	/* VTG enable first is for HW workaround */
-	REG_UPDATE(CONTROL,
-			VTG0_ENABLE, 1);
-
-	REG_SEQ_START();
-
-	/* Enable CRTC */
-	REG_UPDATE_2(OTG_CONTROL,
-			OTG_DISABLE_POINT_CNTL, 3,
-			OTG_MASTER_EN, 1);
-
-	REG_SEQ_SUBMIT();
-	REG_SEQ_WAIT_DONE();
-
+	_optc1_enable_crtc(optc);
  	return true;
  }
 
drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h +0 -0
index 2f3bd7648ba7..aea80fa6fe91 100644

drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h struct dcn_optc_mask { · line 607

Quoted 4 lines
drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h +1 -0
@@ -604,4 +604,31 @@ struct dcn_optc_mask {
 
  void dcn10_timing_generator_init(struct optc *optc);
 
+#define _optc1_enable_crtc(optc)					\

Let's avoid the introduction of a macro. Just create a function for that.

drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h struct dcn_optc_mask { · line 609

Quoted 2 lines
drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h +2 -0
+	do {								\
+		/* TODO FPGA wait for answer */				\

You can drop this comment.

drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h struct dcn_optc_mask { · line 614

Quoted 5 lines
drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h +5 -0
+		/* OTG_MASTER_UPDATE_MODE != CRTC_MASTER_UPDATE_MODE */	\
+		/* OTG_MASTER_UPDATE_LOCK != CRTC_MASTER_UPDATE_LOCK */	\
+		struct optc *optc1 = DCN10TG_FROM_TG(optc);		\
+									\
+		/* opp instance for OTG. For DCN1.0, ODM is remoed. */	\

I think the original comment had a typo, I guess it should be "removed" instead of "remoed". Can you also fix this?

Quoted 4 lines
drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h +4 -0
+		/* OPP and OPTC should 1:1 mapping */			\
+		REG_UPDATE(OPTC_DATA_SOURCE_SELECT,			\
+				OPTC_SRC_SEL_FIELD, optc->inst);	\
+									\

drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h struct dcn_optc_mask { · line 628

Quoted 10 lines
drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h +10 -0
+		/* VTG enable first is for HW workaround */		\
+		REG_UPDATE(CONTROL,					\
+				VTG0_ENABLE, 1);			\
+									\
+		REG_SEQ_START();					\
+									\
+		/* Enable CRTC */					\
+		REG_UPDATE_2(OTG_CONTROL,				\
+				OTG_DISABLE_POINT_CNTL, 3,		\
+				OTG_MASTER_EN, 1);			\

Maybe you can convert this patch into a patchset, where the first patch moves code around, and the following patches fix typos and code style, such as the parenthesis aligment with the parameters.

drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h struct dcn_optc_mask { · line 633

Quoted 5 lines
drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h +5 -0
+									\
+		REG_SEQ_SUBMIT();					\
+		REG_SEQ_WAIT_DONE();					\
+	} while (0)
+

I was thinking... do we have more cases like this one? If so, maybe we can create a generic optc.c file. Anyway, this is just one idea to add to your radar for future patches.

Thanks
Siqueira

Quoted 48 lines
drivers/gpu/drm/amd/display/dc/optc/dcn10/dcn10_optc.h +0 -0
  #endif /* __DC_TIMING_GENERATOR_DCN10_H__ */
drivers/gpu/drm/amd/display/dc/optc/dcn20/dcn20_optc.c +3 -26
index d6f095b4555d..012e0c52aeec 100644
@@ -37,6 +37,8 @@
  #define FN(reg_name, field_name) \
  	optc1->tg_shift->field_name, optc1->tg_mask->field_name
 
+#define OPTC_SRC_SEL_FIELD OPTC_SEG0_SRC_SEL
+
  /**
   * optc2_enable_crtc() - Enable CRTC - call ASIC Control Object to enable Timing generator.
   *
@@ -47,32 +49,7 @@
   */
  bool optc2_enable_crtc(struct timing_generator *optc)
  {
-	/* TODO FPGA wait for answer
-	 * OTG_MASTER_UPDATE_MODE != CRTC_MASTER_UPDATE_MODE
-	 * OTG_MASTER_UPDATE_LOCK != CRTC_MASTER_UPDATE_LOCK
-	 */
-	struct optc *optc1 = DCN10TG_FROM_TG(optc);
-
-	/* opp instance for OTG. For DCN1.0, ODM is remoed.
-	 * OPP and OPTC should 1:1 mapping
-	 */
-	REG_UPDATE(OPTC_DATA_SOURCE_SELECT,
-			OPTC_SEG0_SRC_SEL, optc->inst);
-
-	/* VTG enable first is for HW workaround */
-	REG_UPDATE(CONTROL,
-			VTG0_ENABLE, 1);
-
-	REG_SEQ_START();
-
-	/* Enable CRTC */
-	REG_UPDATE_2(OTG_CONTROL,
-			OTG_DISABLE_POINT_CNTL, 3,
-			OTG_MASTER_EN, 1);
-
-	REG_SEQ_SUBMIT();
-	REG_SEQ_WAIT_DONE();
-
+	_optc1_enable_crtc(optc);
  	return true;
  }