Skip to contentSkip to conversation

drm/ast: Clean up use of TX-chip register constants

PATCH In review Thomas Zimmermann 2 participants 7 messages Sep 16, 2024

Subsystems (3)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover drm/ast: Clean up use of TX-chip register constants

On GEN4 and later, VGACRD1 returns the device's TX chip. Clean up the use of the constants. Warn about unsupported chips.

Tested on various Aspeed devices. Really cleaning this up needs more work, but at least the TX-chip warnings can be added now.

Thomas Zimmermann (3):
drm/ast: Rename register constants for TX-chip types drm/ast: Use TX-chip register constants drm/ast: Warn about unsupported TX chips

 drivers/gpu/drm/ast/ast_dp501.c | 13 +++++++------
 drivers/gpu/drm/ast/ast_main.c  | 30 +++++++++++++++++++++++-------
 drivers/gpu/drm/ast/ast_reg.h   | 26 ++++++++++++--------------
 3 files changed, 42 insertions(+), 27 deletions(-)
Signature · 1 line
2.46.0
author maintainer
#1 lore raw

PATCH 1/3 drm/ast: Rename register constants for TX-chip types

The type of the TX chip is provided in VGACRD1. Rename the constants accordingly.

---
 drivers/gpu/drm/ast/ast_main.c |  4 ++--
 drivers/gpu/drm/ast/ast_reg.h  | 26 ++++++++++++--------------
 2 files changed, 14 insertions(+), 16 deletions(-)
drivers/gpu/drm/ast/ast_main.c +2 -2
index 3d92d9e5208f..d0e4f0dc9234 100644
@@ -120,8 +120,8 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)
 			ast->tx_chip = AST_TX_DP501;
 		}
 	} else if (IS_AST_GEN7(ast)) {
-		if (ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xD1, TX_TYPE_MASK) ==
-		    ASTDP_DPMCU_TX) {
+		if (ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, AST_IO_VGACRD1_TX_TYPE_MASK) ==
+		    AST_IO_VGACRD1_TX_ASTDP) {
 			int ret = ast_dp_launch(ast);
 
 			if (!ret)
drivers/gpu/drm/ast/ast_reg.h +12 -14
index 6a1f756650ab..daa5d3a9e6a1 100644
@@ -37,7 +37,18 @@
 #define AST_IO_VGACRCB_HWC_16BPP	BIT(0) /* set: ARGB4444, cleared: 2bpp palette */
 #define AST_IO_VGACRCB_HWC_ENABLED	BIT(1)
 
-#define AST_IO_VGACRD1_MCU_FW_EXECUTING	BIT(5)
+#define AST_IO_VGACRD1_MCU_FW_EXECUTING		BIT(5)
+/* Display Transmitter Type */
+#define AST_IO_VGACRD1_TX_TYPE_MASK		GENMASK(3, 1)
+#define AST_IO_VGACRD1_NO_TX			0x00
+#define AST_IO_VGACRD1_TX_ITE66121_VBIOS	0x02
+#define AST_IO_VGACRD1_TX_SIL164_VBIOS		0x04
+#define AST_IO_VGACRD1_TX_CH7003_VBIOS		0x06
+#define AST_IO_VGACRD1_TX_DP501_VBIOS		0x08
+#define AST_IO_VGACRD1_TX_ANX9807_VBIOS		0x0a
+#define AST_IO_VGACRD1_TX_FW_EMBEDDED_FW	0x0c
+#define AST_IO_VGACRD1_TX_ASTDP			0x0e
+
 #define AST_IO_VGACRD7_EDID_VALID_FLAG	BIT(0)
 #define AST_IO_VGACRDC_LINK_SUCCESS	BIT(0)
 #define AST_IO_VGACRDF_HPD		BIT(0)
@@ -49,19 +60,6 @@
 #define AST_IO_VGAIR1_R			(0x5A)
 #define AST_IO_VGAIR1_VREFRESH		BIT(3)
 
-/*
- * Display Transmitter Type
- */
-
-#define TX_TYPE_MASK			GENMASK(3, 1)
-#define NO_TX				(0 << 1)
-#define ITE66121_VBIOS_TX		(1 << 1)
-#define SI164_VBIOS_TX			(2 << 1)
-#define CH7003_VBIOS_TX			(3 << 1)
-#define DP501_VBIOS_TX			(4 << 1)
-#define ANX9807_VBIOS_TX		(5 << 1)
-#define TX_FW_EMBEDDED_FW_TX		(6 << 1)
-#define ASTDP_DPMCU_TX			(7 << 1)
 
 #define AST_VRAM_INIT_STATUS_MASK	GENMASK(7, 6)
 //#define AST_VRAM_INIT_BY_BMC		BIT(7)
Signature · 1 line
2.46.0
reviewer Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] drm/ast: Rename register constants for TX-chip types

Quoted 2 lines · Thomas Zimmermann

The type of the TX chip is provided in VGACRD1. Rename the constants accordingly.

Thanks, it looks good to me.

Quoted 66 lines
---
  drivers/gpu/drm/ast/ast_main.c |  4 ++--
  drivers/gpu/drm/ast/ast_reg.h  | 26 ++++++++++++--------------
  2 files changed, 14 insertions(+), 16 deletions(-)
drivers/gpu/drm/ast/ast_main.c +2 -2
index 3d92d9e5208f..d0e4f0dc9234 100644
@@ -120,8 +120,8 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)
  			ast->tx_chip = AST_TX_DP501;
  		}
  	} else if (IS_AST_GEN7(ast)) {
-		if (ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xD1, TX_TYPE_MASK) ==
-		    ASTDP_DPMCU_TX) {
+		if (ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, AST_IO_VGACRD1_TX_TYPE_MASK) ==
+		    AST_IO_VGACRD1_TX_ASTDP) {
  			int ret = ast_dp_launch(ast);
 
  			if (!ret)
drivers/gpu/drm/ast/ast_reg.h +12 -14
index 6a1f756650ab..daa5d3a9e6a1 100644
@@ -37,7 +37,18 @@
  #define AST_IO_VGACRCB_HWC_16BPP	BIT(0) /* set: ARGB4444, cleared: 2bpp palette */
  #define AST_IO_VGACRCB_HWC_ENABLED	BIT(1)
 
-#define AST_IO_VGACRD1_MCU_FW_EXECUTING	BIT(5)
+#define AST_IO_VGACRD1_MCU_FW_EXECUTING		BIT(5)
+/* Display Transmitter Type */
+#define AST_IO_VGACRD1_TX_TYPE_MASK		GENMASK(3, 1)
+#define AST_IO_VGACRD1_NO_TX			0x00
+#define AST_IO_VGACRD1_TX_ITE66121_VBIOS	0x02
+#define AST_IO_VGACRD1_TX_SIL164_VBIOS		0x04
+#define AST_IO_VGACRD1_TX_CH7003_VBIOS		0x06
+#define AST_IO_VGACRD1_TX_DP501_VBIOS		0x08
+#define AST_IO_VGACRD1_TX_ANX9807_VBIOS		0x0a
+#define AST_IO_VGACRD1_TX_FW_EMBEDDED_FW	0x0c
+#define AST_IO_VGACRD1_TX_ASTDP			0x0e
+
  #define AST_IO_VGACRD7_EDID_VALID_FLAG	BIT(0)
  #define AST_IO_VGACRDC_LINK_SUCCESS	BIT(0)
  #define AST_IO_VGACRDF_HPD		BIT(0)
@@ -49,19 +60,6 @@
  #define AST_IO_VGAIR1_R			(0x5A)
  #define AST_IO_VGAIR1_VREFRESH		BIT(3)
 
-/*
- * Display Transmitter Type
- */
-
-#define TX_TYPE_MASK			GENMASK(3, 1)
-#define NO_TX				(0 << 1)
-#define ITE66121_VBIOS_TX		(1 << 1)
-#define SI164_VBIOS_TX			(2 << 1)
-#define CH7003_VBIOS_TX			(3 << 1)
-#define DP501_VBIOS_TX			(4 << 1)
-#define ANX9807_VBIOS_TX		(5 << 1)
-#define TX_FW_EMBEDDED_FW_TX		(6 << 1)
-#define ASTDP_DPMCU_TX			(7 << 1)
 
  #define AST_VRAM_INIT_STATUS_MASK	GENMASK(7, 6)
  //#define AST_VRAM_INIT_BY_BMC		BIT(7)
author maintainer
#3 lore raw

PATCH 2/3 drm/ast: Use TX-chip register constants

In reply to Thomas Zimmermann

Replace magic values with named constants when reading the TX chip from VGACRD1.

---
 drivers/gpu/drm/ast/ast_dp501.c | 13 +++++++------
 drivers/gpu/drm/ast/ast_main.c  |  9 +++++----
 drivers/gpu/drm/ast/ast_reg.h   |  2 +-
 3 files changed, 13 insertions(+), 11 deletions(-)
drivers/gpu/drm/ast/ast_dp501.c +7 -6
index e5553334bfde..9e19d8c17730 100644
@@ -444,18 +444,19 @@ static void ast_init_analog(struct ast_device *ast)
 
 void ast_init_3rdtx(struct ast_device *ast)
 {
-	u8 jreg;
+	u8 vgacrd1;
 
 	if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast)) {
-		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, 0xff);
-		switch (jreg & 0x0e) {
-		case 0x04:
+		vgacrd1 = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1,
+						 AST_IO_VGACRD1_TX_TYPE_MASK);
+		switch (vgacrd1) {
+		case AST_IO_VGACRD1_TX_SIL164_VBIOS:
 			ast_init_dvo(ast);
 			break;
-		case 0x08:
+		case AST_IO_VGACRD1_TX_DP501_VBIOS:
 			ast_launch_m68k(ast);
 			break;
-		case 0x0c:
+		case AST_IO_VGACRD1_TX_FW_EMBEDDED_FW:
 			ast_init_dvo(ast);
 			break;
 		default:
drivers/gpu/drm/ast/ast_main.c +5 -4
index d0e4f0dc9234..7289bdc6066e 100644
@@ -101,12 +101,13 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)
 		 * the SOC scratch register #1 bits 11:8 (interestingly marked
 		 * as "reserved" in the spec)
 		 */
-		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, 0xff);
+		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1,
+					      AST_IO_VGACRD1_TX_TYPE_MASK);
 		switch (jreg) {
-		case 0x04:
+		case AST_IO_VGACRD1_TX_SIL164_VBIOS:
 			ast->tx_chip = AST_TX_SIL164;
 			break;
-		case 0x08:
+		case AST_IO_VGACRD1_TX_DP501_VBIOS:
 			ast->dp501_fw_addr = drmm_kzalloc(dev, 32*1024, GFP_KERNEL);
 			if (ast->dp501_fw_addr) {
 				/* backup firmware */
@@ -116,7 +117,7 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)
 				}
 			}
 			fallthrough;
-		case 0x0c:
+		case AST_IO_VGACRD1_TX_FW_EMBEDDED_FW:
 			ast->tx_chip = AST_TX_DP501;
 		}
 	} else if (IS_AST_GEN7(ast)) {
drivers/gpu/drm/ast/ast_reg.h +1 -1
index daa5d3a9e6a1..2aadf07d135a 100644
@@ -46,7 +46,7 @@
 #define AST_IO_VGACRD1_TX_CH7003_VBIOS		0x06
 #define AST_IO_VGACRD1_TX_DP501_VBIOS		0x08
 #define AST_IO_VGACRD1_TX_ANX9807_VBIOS		0x0a
-#define AST_IO_VGACRD1_TX_FW_EMBEDDED_FW	0x0c
+#define AST_IO_VGACRD1_TX_FW_EMBEDDED_FW	0x0c /* special case of DP501 */
 #define AST_IO_VGACRD1_TX_ASTDP			0x0e
 
 #define AST_IO_VGACRD7_EDID_VALID_FLAG	BIT(0)
Signature · 1 line
2.46.0
reviewer Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] drm/ast: Use TX-chip register constants

Quoted 3 lines · Thomas Zimmermann

Replace magic values with named constants when reading the TX chip from VGACRD1.

Thanks, it looks good to me.

Quoted 80 lines
---
  drivers/gpu/drm/ast/ast_dp501.c | 13 +++++++------
  drivers/gpu/drm/ast/ast_main.c  |  9 +++++----
  drivers/gpu/drm/ast/ast_reg.h   |  2 +-
  3 files changed, 13 insertions(+), 11 deletions(-)
drivers/gpu/drm/ast/ast_dp501.c +7 -6
index e5553334bfde..9e19d8c17730 100644
@@ -444,18 +444,19 @@ static void ast_init_analog(struct ast_device *ast)
 
  void ast_init_3rdtx(struct ast_device *ast)
  {
-	u8 jreg;
+	u8 vgacrd1;
 
  	if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast)) {
-		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, 0xff);
-		switch (jreg & 0x0e) {
-		case 0x04:
+		vgacrd1 = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1,
+						 AST_IO_VGACRD1_TX_TYPE_MASK);
+		switch (vgacrd1) {
+		case AST_IO_VGACRD1_TX_SIL164_VBIOS:
  			ast_init_dvo(ast);
  			break;
-		case 0x08:
+		case AST_IO_VGACRD1_TX_DP501_VBIOS:
  			ast_launch_m68k(ast);
  			break;
-		case 0x0c:
+		case AST_IO_VGACRD1_TX_FW_EMBEDDED_FW:
  			ast_init_dvo(ast);
  			break;
  		default:
drivers/gpu/drm/ast/ast_main.c +5 -4
index d0e4f0dc9234..7289bdc6066e 100644
@@ -101,12 +101,13 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)
  		 * the SOC scratch register #1 bits 11:8 (interestingly marked
  		 * as "reserved" in the spec)
  		 */
-		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, 0xff);
+		jreg = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1,
+					      AST_IO_VGACRD1_TX_TYPE_MASK);
  		switch (jreg) {
-		case 0x04:
+		case AST_IO_VGACRD1_TX_SIL164_VBIOS:
  			ast->tx_chip = AST_TX_SIL164;
  			break;
-		case 0x08:
+		case AST_IO_VGACRD1_TX_DP501_VBIOS:
  			ast->dp501_fw_addr = drmm_kzalloc(dev, 32*1024, GFP_KERNEL);
  			if (ast->dp501_fw_addr) {
  				/* backup firmware */
@@ -116,7 +117,7 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)
  				}
  			}
  			fallthrough;
-		case 0x0c:
+		case AST_IO_VGACRD1_TX_FW_EMBEDDED_FW:
  			ast->tx_chip = AST_TX_DP501;
  		}
  	} else if (IS_AST_GEN7(ast)) {
drivers/gpu/drm/ast/ast_reg.h +1 -1
index daa5d3a9e6a1..2aadf07d135a 100644
@@ -46,7 +46,7 @@
  #define AST_IO_VGACRD1_TX_CH7003_VBIOS		0x06
  #define AST_IO_VGACRD1_TX_DP501_VBIOS		0x08
  #define AST_IO_VGACRD1_TX_ANX9807_VBIOS		0x0a
-#define AST_IO_VGACRD1_TX_FW_EMBEDDED_FW	0x0c
+#define AST_IO_VGACRD1_TX_FW_EMBEDDED_FW	0x0c /* special case of DP501 */
  #define AST_IO_VGACRD1_TX_ASTDP			0x0e
 
  #define AST_IO_VGACRD7_EDID_VALID_FLAG	BIT(0)
author maintainer
#5 lore raw

PATCH 3/3 drm/ast: Warn about unsupported TX chips

In reply to Thomas Zimmermann

A number of TX chips are listed in VGACRD1, but not supported by the ast driver. Whether any existing product uses such a chip is unknown. Warn if the driver encounters any. We can then add support as necessary.

---
 drivers/gpu/drm/ast/ast_main.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/drm/ast/ast_main.c +16 -1
index 7289bdc6066e..bc37c65305d4 100644
@@ -76,7 +76,22 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)
 	};
 
 	struct drm_device *dev = &ast->base;
-	u8 jreg;
+	u8 jreg, vgacrd1;
+
+	/*
+	 * Several of the listed TX chips are not explicitly supported
+	 * by the ast driver. If these exist in real-world devices, they
+	 * are most likely reported as VGA or SIL164 outputs. We warn here
+	 * to get bug reports for these devices. If none come in for some
+	 * time, we can begin to fail device probing on these values.
+	 */
+	vgacrd1 = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, AST_IO_VGACRD1_TX_TYPE_MASK);
+	drm_WARN(dev, vgacrd1 == AST_IO_VGACRD1_TX_ITE66121_VBIOS,
+		 "ITE IT66121 detected, 0x%x, Gen%lu\n", vgacrd1, AST_GEN(ast));
+	drm_WARN(dev, vgacrd1 == AST_IO_VGACRD1_TX_CH7003_VBIOS,
+		 "Chrontel CH7003 detected, 0x%x, Gen%lu\n", vgacrd1, AST_GEN(ast));
+	drm_WARN(dev, vgacrd1 == AST_IO_VGACRD1_TX_ANX9807_VBIOS,
+		 "Analogix ANX9807 detected, 0x%x, Gen%lu\n", vgacrd1, AST_GEN(ast));
 
 	/* Check 3rd Tx option (digital output afaik) */
 	ast->tx_chip = AST_TX_NONE;
Signature · 1 line
2.46.0
reviewer Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] drm/ast: Warn about unsupported TX chips

Quoted 4 lines · Thomas Zimmermann

A number of TX chips are listed in VGACRD1, but not supported by the ast driver. Whether any existing product uses such a chip is unknown. Warn if the driver encounters any. We can then add support as necessary.

Thanks, it looks good to me.

Quoted 35 lines
---
  drivers/gpu/drm/ast/ast_main.c | 17 ++++++++++++++++-
  1 file changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/drm/ast/ast_main.c +16 -1
index 7289bdc6066e..bc37c65305d4 100644
@@ -76,7 +76,22 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)
  	};
 
  	struct drm_device *dev = &ast->base;
-	u8 jreg;
+	u8 jreg, vgacrd1;
+
+	/*
+	 * Several of the listed TX chips are not explicitly supported
+	 * by the ast driver. If these exist in real-world devices, they
+	 * are most likely reported as VGA or SIL164 outputs. We warn here
+	 * to get bug reports for these devices. If none come in for some
+	 * time, we can begin to fail device probing on these values.
+	 */
+	vgacrd1 = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, AST_IO_VGACRD1_TX_TYPE_MASK);
+	drm_WARN(dev, vgacrd1 == AST_IO_VGACRD1_TX_ITE66121_VBIOS,
+		 "ITE IT66121 detected, 0x%x, Gen%lu\n", vgacrd1, AST_GEN(ast));
+	drm_WARN(dev, vgacrd1 == AST_IO_VGACRD1_TX_CH7003_VBIOS,
+		 "Chrontel CH7003 detected, 0x%x, Gen%lu\n", vgacrd1, AST_GEN(ast));
+	drm_WARN(dev, vgacrd1 == AST_IO_VGACRD1_TX_ANX9807_VBIOS,
+		 "Analogix ANX9807 detected, 0x%x, Gen%lu\n", vgacrd1, AST_GEN(ast));
 
  	/* Check 3rd Tx option (digital output afaik) */
  	ast->tx_chip = AST_TX_NONE;