Skip to contentSkip to conversation

drm/ast: Untangle connector helpers

PATCH Superseded Thomas Zimmermann 2 participants 19 messages Jan 11, 2022 – Feb 7, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover drm/ast: Untangle connector helpers

The ast driver supports different transmitter chips to support DVI and HDMI connectors. It's al been packed into the same helpers functons and exported as VGA connector.

Introduce a separate set of connector helpers for each transmitter chip, and thus connector type. Also provide the correct encoder for each connector.

This change mostly affects the connector's get_modes helper, where VGA-, DVI- and HDMI-related code was lumped into the same function. It's now all separate. While at it, also rework and cleanup the initialization of the related data structures.

Tested on AST 2100 and AST 2300 hardware. I don't have hardware with special transmitter chips (SIL164, DP501), so I could only test the VGA code.

Thomas Zimmermann (8):
drm/ast: Fail if connector initialization fails
drm/ast: Move connector mode_valid function to CRTC drm/ast: Remove AST_TX_ITE66121 constant
drm/ast: Remove unused value dp501_maxclk
drm/ast: Rename struct ast_connector to struct ast_vga_connector drm/ast: Initialize encoder and connector for VGA in helper function drm/ast: Move DP501-based connector code into separate helpers drm/ast: Move SIL164-based connector code into separate helpers

 drivers/gpu/drm/ast/ast_dp501.c |  58 -----
 drivers/gpu/drm/ast/ast_drv.h   |  37 ++-
 drivers/gpu/drm/ast/ast_mode.c  | 413 +++++++++++++++++++++++---------
 3 files changed, 331 insertions(+), 177 deletions(-)

base-commit: fbce7b8d8df5af8d404b6aeaf63779f91bdbeb5d
prerequisite-patch-id: c2b2f08f0eccc9f5df0c0da49fa1d36267deb11d
prerequisite-patch-id: c67e5d886a47b7d0266d81100837557fda34cb24

Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/8 drm/ast: Fail if connector initialization fails

Update the connector code to fail if the connector could not be initialized. The current code just ignored the error and failed later when the connector was supposed to be used.

---
 drivers/gpu/drm/ast/ast_mode.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +8 -5
index 956c8982192b..20626c78a693 100644
@@ -1319,18 +1319,21 @@ static int ast_connector_init(struct drm_device *dev)
 	struct ast_connector *ast_connector = &ast->connector;
 	struct drm_connector *connector = &ast_connector->base;
 	struct drm_encoder *encoder = &ast->encoder;
+	int ret;
 
 	ast_connector->i2c = ast_i2c_create(dev);
 	if (!ast_connector->i2c)
 		drm_err(dev, "failed to add ddc bus for connector\n");
 
 	if (ast_connector->i2c)
-		drm_connector_init_with_ddc(dev, connector, &ast_connector_funcs,
-					    DRM_MODE_CONNECTOR_VGA,
-					    &ast_connector->i2c->adapter);
+		ret = drm_connector_init_with_ddc(dev, connector, &ast_connector_funcs,
+						  DRM_MODE_CONNECTOR_VGA,
+						  &ast_connector->i2c->adapter);
 	else
-		drm_connector_init(dev, connector, &ast_connector_funcs,
-				   DRM_MODE_CONNECTOR_VGA);
+		ret = drm_connector_init(dev, connector, &ast_connector_funcs,
+					 DRM_MODE_CONNECTOR_VGA);
+	if (ret)
+		return ret;
 
 	drm_connector_helper_add(connector, &ast_connector_helper_funcs);
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/8
#2 lore raw

Re: [PATCH 1/8] drm/ast: Fail if connector initialization fails

Hello Thomas,

Quoted 6 lines · Thomas Zimmermann

Update the connector code to fail if the connector could not be initialized. The current code just ignored the error and failed later when the connector was supposed to be used.

---

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
author maintainer
#3 lore raw

PATCH 2/8 drm/ast: Move connector mode_valid function to CRTC

In reply to Thomas Zimmermann

The tests in ast_mode_valid() verify the correct resolution for the supplied mode. This is a limitation of the CRTC, so move the function to the CRTC helpers. No functional changes.

---
 drivers/gpu/drm/ast/ast_mode.c | 129 +++++++++++++++++----------------
 1 file changed, 66 insertions(+), 63 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +66 -63
index 20626c78a693..c555960a488a 100644
@@ -1002,6 +1002,71 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
 	}
 }
 
+static enum drm_mode_status
+ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode *mode)
+{
+	struct ast_private *ast = to_ast_private(crtc->dev);
+	enum drm_mode_status status;
+	uint32_t jtemp;
+
+	if (ast->support_wide_screen) {
+		if ((mode->hdisplay == 1680) && (mode->vdisplay == 1050))
+			return MODE_OK;
+		if ((mode->hdisplay == 1280) && (mode->vdisplay == 800))
+			return MODE_OK;
+		if ((mode->hdisplay == 1440) && (mode->vdisplay == 900))
+			return MODE_OK;
+		if ((mode->hdisplay == 1360) && (mode->vdisplay == 768))
+			return MODE_OK;
+		if ((mode->hdisplay == 1600) && (mode->vdisplay == 900))
+			return MODE_OK;
+
+		if ((ast->chip == AST2100) || (ast->chip == AST2200) ||
+		    (ast->chip == AST2300) || (ast->chip == AST2400) ||
+		    (ast->chip == AST2500)) {
+			if ((mode->hdisplay == 1920) && (mode->vdisplay == 1080))
+				return MODE_OK;
+
+			if ((mode->hdisplay == 1920) && (mode->vdisplay == 1200)) {
+				jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 0xff);
+				if (jtemp & 0x01)
+					return MODE_NOMODE;
+				else
+					return MODE_OK;
+			}
+		}
+	}
+
+	status = MODE_NOMODE;
+
+	switch (mode->hdisplay) {
+	case 640:
+		if (mode->vdisplay == 480)
+			status = MODE_OK;
+		break;
+	case 800:
+		if (mode->vdisplay == 600)
+			status = MODE_OK;
+		break;
+	case 1024:
+		if (mode->vdisplay == 768)
+			status = MODE_OK;
+		break;
+	case 1280:
+		if (mode->vdisplay == 1024)
+			status = MODE_OK;
+		break;
+	case 1600:
+		if (mode->vdisplay == 1200)
+			status = MODE_OK;
+		break;
+	default:
+		break;
+	}
+
+	return status;
+}
+
 static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc,
 					struct drm_atomic_state *state)
 {
@@ -1104,6 +1169,7 @@ ast_crtc_helper_atomic_disable(struct drm_crtc *crtc,
 }
 
 static const struct drm_crtc_helper_funcs ast_crtc_helper_funcs = {
+	.mode_valid = ast_crtc_helper_mode_valid,
 	.atomic_check = ast_crtc_helper_atomic_check,
 	.atomic_flush = ast_crtc_helper_atomic_flush,
 	.atomic_enable = ast_crtc_helper_atomic_enable,
@@ -1238,71 +1304,8 @@ static int ast_get_modes(struct drm_connector *connector)
 	return 0;
 }
 
-static enum drm_mode_status ast_mode_valid(struct drm_connector *connector,
-			  struct drm_display_mode *mode)
-{
-	struct ast_private *ast = to_ast_private(connector->dev);
-	int flags = MODE_NOMODE;
-	uint32_t jtemp;
-
-	if (ast->support_wide_screen) {
-		if ((mode->hdisplay == 1680) && (mode->vdisplay == 1050))
-			return MODE_OK;
-		if ((mode->hdisplay == 1280) && (mode->vdisplay == 800))
-			return MODE_OK;
-		if ((mode->hdisplay == 1440) && (mode->vdisplay == 900))
-			return MODE_OK;
-		if ((mode->hdisplay == 1360) && (mode->vdisplay == 768))
-			return MODE_OK;
-		if ((mode->hdisplay == 1600) && (mode->vdisplay == 900))
-			return MODE_OK;
-
-		if ((ast->chip == AST2100) || (ast->chip == AST2200) ||
-		    (ast->chip == AST2300) || (ast->chip == AST2400) ||
-		    (ast->chip == AST2500)) {
-			if ((mode->hdisplay == 1920) && (mode->vdisplay == 1080))
-				return MODE_OK;
-
-			if ((mode->hdisplay == 1920) && (mode->vdisplay == 1200)) {
-				jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 0xff);
-				if (jtemp & 0x01)
-					return MODE_NOMODE;
-				else
-					return MODE_OK;
-			}
-		}
-	}
-	switch (mode->hdisplay) {
-	case 640:
-		if (mode->vdisplay == 480)
-			flags = MODE_OK;
-		break;
-	case 800:
-		if (mode->vdisplay == 600)
-			flags = MODE_OK;
-		break;
-	case 1024:
-		if (mode->vdisplay == 768)
-			flags = MODE_OK;
-		break;
-	case 1280:
-		if (mode->vdisplay == 1024)
-			flags = MODE_OK;
-		break;
-	case 1600:
-		if (mode->vdisplay == 1200)
-			flags = MODE_OK;
-		break;
-	default:
-		return flags;
-	}
-
-	return flags;
-}
-
 static const struct drm_connector_helper_funcs ast_connector_helper_funcs = {
 	.get_modes = ast_get_modes,
-	.mode_valid = ast_mode_valid,
 };
 
 static const struct drm_connector_funcs ast_connector_funcs = {
Signature · 1 line
2.34.1
Reviewed-by on v1 2/8
#4 lore raw

Re: [PATCH 2/8] drm/ast: Move connector mode_valid function to CRTC

Quoted 6 lines · Thomas Zimmermann

The tests in ast_mode_valid() verify the correct resolution for the supplied mode. This is a limitation of the CRTC, so move the function to the CRTC helpers. No functional changes.

---

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
author maintainer
#5 lore raw

PATCH 3/8 drm/ast: Remove AST_TX_ITE66121 constant

In reply to Thomas Zimmermann

The ITE66121 is an HDMI transmitter chip. There's no code for detecting or programming the chip within ast. Remove the enum constant.

---
 drivers/gpu/drm/ast/ast_drv.h | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/ast/ast_drv.h +0 -1
index 00bfa41ff7cb..6e77be1d06d3 100644
@@ -69,7 +69,6 @@ enum ast_chip {
 enum ast_tx_chip {
 	AST_TX_NONE,
 	AST_TX_SIL164,
-	AST_TX_ITE66121,
 	AST_TX_DP501,
 };
 
Signature · 1 line
2.34.1
Reviewed-by on v1 3/8
#6 lore raw

Re: [PATCH 3/8] drm/ast: Remove AST_TX_ITE66121 constant

Quoted 6 lines · Thomas Zimmermann

The ITE66121 is an HDMI transmitter chip. There's no code for detecting or programming the chip within ast. Remove the enum constant.

---

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
author maintainer
#7 lore raw

PATCH 4/8 drm/ast: Remove unused value dp501_maxclk

In reply to Thomas Zimmermann

Remove reading the link-rate. The value is maintained by the connector code but never used.

---
 drivers/gpu/drm/ast/ast_dp501.c | 58 ---------------------------------
 drivers/gpu/drm/ast/ast_drv.h   |  1 -
 drivers/gpu/drm/ast/ast_mode.c  |  7 ++--
 3 files changed, 3 insertions(+), 63 deletions(-)
drivers/gpu/drm/ast/ast_dp501.c +0 -58
index cd93c44f2662..204c926a18ea 100644
@@ -272,64 +272,6 @@ static bool ast_launch_m68k(struct drm_device *dev)
 	return true;
 }
 
-u8 ast_get_dp501_max_clk(struct drm_device *dev)
-{
-	struct ast_private *ast = to_ast_private(dev);
-	u32 boot_address, offset, data;
-	u8 linkcap[4], linkrate, linklanes, maxclk = 0xff;
-	u32 *plinkcap;
-
-	if (ast->config_mode == ast_use_p2a) {
-		boot_address = get_fw_base(ast);
-
-		/* validate FW version */
-		offset = AST_DP501_GBL_VERSION;
-		data = ast_mindwm(ast, boot_address + offset);
-		if ((data & AST_DP501_FW_VERSION_MASK) != AST_DP501_FW_VERSION_1) /* version: 1x */
-			return maxclk;
-
-		/* Read Link Capability */
-		offset  = AST_DP501_LINKRATE;
-		plinkcap = (u32 *)linkcap;
-		*plinkcap  = ast_mindwm(ast, boot_address + offset);
-		if (linkcap[2] == 0) {
-			linkrate = linkcap[0];
-			linklanes = linkcap[1];
-			data = (linkrate == 0x0a) ? (90 * linklanes) : (54 * linklanes);
-			if (data > 0xff)
-				data = 0xff;
-			maxclk = (u8)data;
-		}
-	} else {
-		if (!ast->dp501_fw_buf)
-			return AST_DP501_DEFAULT_DCLK;	/* 1024x768 as default */
-
-		/* dummy read */
-		offset = 0x0000;
-		data = readl(ast->dp501_fw_buf + offset);
-
-		/* validate FW version */
-		offset = AST_DP501_GBL_VERSION;
-		data = readl(ast->dp501_fw_buf + offset);
-		if ((data & AST_DP501_FW_VERSION_MASK) != AST_DP501_FW_VERSION_1) /* version: 1x */
-			return maxclk;
-
-		/* Read Link Capability */
-		offset = AST_DP501_LINKRATE;
-		plinkcap = (u32 *)linkcap;
-		*plinkcap = readl(ast->dp501_fw_buf + offset);
-		if (linkcap[2] == 0) {
-			linkrate = linkcap[0];
-			linklanes = linkcap[1];
-			data = (linkrate == 0x0a) ? (90 * linklanes) : (54 * linklanes);
-			if (data > 0xff)
-				data = 0xff;
-			maxclk = (u8)data;
-		}
-	}
-	return maxclk;
-}
-
 bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata)
 {
 	struct ast_private *ast = to_ast_private(dev);
drivers/gpu/drm/ast/ast_drv.h +0 -1
index 6e77be1d06d3..479bb120dd05 100644
@@ -171,7 +171,6 @@ struct ast_private {
 	} config_mode;
 
 	enum ast_tx_chip tx_chip_type;
-	u8 dp501_maxclk;
 	u8 *dp501_fw_addr;
 	const struct firmware *dp501_fw;	/* dp501 fw */
 };
drivers/gpu/drm/ast/ast_mode.c +3 -4
index c555960a488a..0a8aa6e3aa38 100644
@@ -1281,16 +1281,15 @@ static int ast_get_modes(struct drm_connector *connector)
 	int ret;
 
 	if (ast->tx_chip_type == AST_TX_DP501) {
-		ast->dp501_maxclk = 0xff;
 		edid = kmalloc(128, GFP_KERNEL);
 		if (!edid)
 			return -ENOMEM;
 
 		flags = ast_dp501_read_edid(connector->dev, (u8 *)edid);
-		if (flags)
-			ast->dp501_maxclk = ast_get_dp501_max_clk(connector->dev);
-		else
+		if (!flags) {
 			kfree(edid);
+			edid = NULL;
+		}
 	}
 	if (!flags && ast_connector->i2c)
 		edid = drm_get_edid(connector, &ast_connector->i2c->adapter);
Signature · 1 line
2.34.1
author maintainer
#9 lore raw

PATCH 5/8 drm/ast: Rename struct ast_connector to struct ast_vga_connector

In reply to Thomas Zimmermann

Prepare for introducing other connectors besides VGA. No functional changes.

---
 drivers/gpu/drm/ast/ast_drv.h  | 10 ++++----
 drivers/gpu/drm/ast/ast_mode.c | 45 +++++++++++++++++-----------------
 2 files changed, 27 insertions(+), 28 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +5 -5
index 479bb120dd05..e1cb31acdaac 100644
@@ -129,15 +129,15 @@ struct ast_i2c_chan {
 	struct i2c_algo_bit_data bit;
 };
 
-struct ast_connector {
+struct ast_vga_connector {
 	struct drm_connector base;
 	struct ast_i2c_chan *i2c;
 };
 
-static inline struct ast_connector *
-to_ast_connector(struct drm_connector *connector)
+static inline struct ast_vga_connector *
+to_ast_vga_connector(struct drm_connector *connector)
 {
-	return container_of(connector, struct ast_connector, base);
+	return container_of(connector, struct ast_vga_connector, base);
 }
 
 /*
@@ -161,7 +161,7 @@ struct ast_private {
 	struct ast_cursor_plane cursor_plane;
 	struct drm_crtc crtc;
 	struct drm_encoder encoder;
-	struct ast_connector connector;
+	struct ast_vga_connector connector;
 
 	bool support_wide_screen;
 	enum {
drivers/gpu/drm/ast/ast_mode.c +22 -23

101 lines not on this page · raw message

Signature · 1 line
2.34.1
author maintainer
#11 lore raw

PATCH 6/8 drm/ast: Initialize encoder and connector for VGA in helper function

In reply to Thomas Zimmermann

Move encoder and connector initialization into a single helper and put all related mode-setting structures into a single place. Done in preparation of moving transmitter code into separate helpers. No functional changes.

---
 drivers/gpu/drm/ast/ast_drv.h  |  8 +++--
 drivers/gpu/drm/ast/ast_mode.c | 62 ++++++++++++++++++++--------------
 2 files changed, 42 insertions(+), 28 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +6 -2
index e1cb31acdaac..cda50fb887ed 100644
@@ -160,8 +160,12 @@ struct ast_private {
 	struct drm_plane primary_plane;
 	struct ast_cursor_plane cursor_plane;
 	struct drm_crtc crtc;
-	struct drm_encoder encoder;
-	struct ast_vga_connector connector;
+	union {
+		struct {
+			struct drm_encoder encoder;
+			struct ast_vga_connector vga_connector;
+		} vga;
+	} output;
 
 	bool support_wide_screen;
 	enum {
drivers/gpu/drm/ast/ast_mode.c +36 -26

88 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v1 6/8
#12 lore raw

Re: [PATCH 6/8] drm/ast: Initialize encoder and connector for VGA in helper function

Quoted 6 lines · Thomas Zimmermann

Move encoder and connector initialization into a single helper and put all related mode-setting structures into a single place. Done in preparation of moving transmitter code into separate helpers. No functional changes.

[snip]

Quoted 1 line
drivers/gpu/drm/ast/ast_mode.c +0 -1
-	encoder->possible_crtcs = 1;

[snip]

drivers/gpu/drm/ast/ast_mode.c static int ast_vga_connector_init(struct drm_device *dev) · line 1341

Quoted 1 line
drivers/gpu/drm/ast/ast_mode.c +1 -0
+	encoder->possible_crtcs = drm_crtc_mask(crtc);

This is a somewhat unrelated change. It's OK because is fairly simple but I would probably still do the cleanups as separate patches.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
author maintainer
#13 lore raw

Re: [PATCH 6/8] drm/ast: Initialize encoder and connector for VGA in helper function

Hi

Am 03.02.22 um 18:43 schrieb Javier Martinez Canillas:

Quoted 12 lines · Thomas Zimmermann
Quoted 6 lines

Move encoder and connector initialization into a single helper and put all related mode-setting structures into a single place. Done in preparation of moving transmitter code into separate helpers. No functional changes.

[snip]

Quoted 8 lines
Quoted 1 line
drivers/gpu/drm/ast/ast_mode.c +0 -1
-	encoder->possible_crtcs = 1;

[snip]

drivers/gpu/drm/ast/ast_mode.c static int ast_vga_connector_init(struct drm_device *dev) · line 1341

Quoted 1 line
drivers/gpu/drm/ast/ast_mode.c +1 -0
+	encoder->possible_crtcs = drm_crtc_mask(crtc);

This is a somewhat unrelated change. It's OK because is fairly simple but I would probably still do the cleanups as separate patches.

I'll put this change into a separate patch.

Best regards
Thomas

Quoted 2 lines

Best regards,

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
author maintainer
#14 lore raw

PATCH 7/8 drm/ast: Move DP501-based connector code into separate helpers

In reply to Thomas Zimmermann

Add helpers for DP501-based connectors. DP501 provides output via DisplayPort. This used to be handled by the VGA connector code.

If a DP501 chip has been detected, ast will now create a DisplayPort connector instead of a VGA connector.

Remove the DP501 code from ast_vga_connector_helper_get_modes(). Also remove the call to drm_connector_update_edid_property(), which is performed by drm_get_edid().

---
 drivers/gpu/drm/ast/ast_drv.h  |   4 ++
 drivers/gpu/drm/ast/ast_mode.c | 128 +++++++++++++++++++++++++++------
 2 files changed, 109 insertions(+), 23 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +4 -0
index cda50fb887ed..420d19d8459e 100644
@@ -165,6 +165,10 @@ struct ast_private {
 			struct drm_encoder encoder;
 			struct ast_vga_connector vga_connector;
 		} vga;
+		struct {
+			struct drm_encoder encoder;
+			struct drm_connector connector;
+		} dp501;
 	} output;
 
 	bool support_wide_screen;
drivers/gpu/drm/ast/ast_mode.c +105 -23

157 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v1 7/8
#15 lore raw

Re: [PATCH 7/8] drm/ast: Move DP501-based connector code into separate helpers

Quoted 6 lines · Thomas Zimmermann

Add helpers for DP501-based connectors. DP501 provides output via DisplayPort. This used to be handled by the VGA connector code.

If a DP501 chip has been detected, ast will now create a DisplayPort connector instead of a VGA connector.

Quoted 6 lines

Remove the DP501 code from ast_vga_connector_helper_get_modes(). Also remove the call to drm_connector_update_edid_property(), which is performed by drm_get_edid().

---

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
author maintainer
#16 lore raw

PATCH 8/8 drm/ast: Move SIL164-based connector code into separate helpers

In reply to Thomas Zimmermann

Add helpers for initializing SIL164-based connectors. These used to be handled by the VGA connector code. But SIL164 provides output via DVI-I, so set the encoder and connector types accordingly.

If a SIL164 chip has been detected, ast will now create a DVI-I connector instead of a VGA connector.

---
 drivers/gpu/drm/ast/ast_drv.h  | 15 ++++++
 drivers/gpu/drm/ast/ast_mode.c | 99 +++++++++++++++++++++++++++++++++-
 2 files changed, 112 insertions(+), 2 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +15 -0
index 420d19d8459e..c3a582372649 100644
@@ -140,6 +140,17 @@ to_ast_vga_connector(struct drm_connector *connector)
 	return container_of(connector, struct ast_vga_connector, base);
 }
 
+struct ast_sil164_connector {
+	struct drm_connector base;
+	struct ast_i2c_chan *i2c;
+};
+
+static inline struct ast_sil164_connector *
+to_ast_sil164_connector(struct drm_connector *connector)
+{
+	return container_of(connector, struct ast_sil164_connector, base);
+}
+
 /*
  * Device
  */
@@ -165,6 +176,10 @@ struct ast_private {
 			struct drm_encoder encoder;
 			struct ast_vga_connector vga_connector;
 		} vga;
+		struct {
+			struct drm_encoder encoder;
+			struct ast_sil164_connector sil164_connector;
+		} sil164;
 		struct {
 			struct drm_encoder encoder;
 			struct drm_connector connector;
drivers/gpu/drm/ast/ast_mode.c +97 -2

117 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v1 8/8
#17 lore raw

Re: [PATCH 8/8] drm/ast: Move SIL164-based connector code into separate helpers

Quoted 21 lines · Thomas Zimmermann

Add helpers for initializing SIL164-based connectors. These used to be handled by the VGA connector code. But SIL164 provides output via DVI-I, so set the encoder and connector types accordingly.

If a SIL164 chip has been detected, ast will now create a DVI-I connector instead of a VGA connector.

---
 drivers/gpu/drm/ast/ast_drv.h  | 15 ++++++
 drivers/gpu/drm/ast/ast_mode.c | 99 +++++++++++++++++++++++++++++++++-
 2 files changed, 112 insertions(+), 2 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +0 -0
index 420d19d8459e..c3a582372649 100644
@@ -140,6 +140,17 @@ to_ast_vga_connector(struct drm_connector *connector)
 	return container_of(connector, struct ast_vga_connector, base);
 }
 

[snip]

Quoted 8 lines
drivers/gpu/drm/ast/ast_drv.h +8 -0
+static int ast_sil164_connector_init(struct drm_device *dev,
+				     struct ast_sil164_connector *ast_sil164_connector)
+{
+	struct drm_connector *connector = &ast_sil164_connector->base;
+	int ret;
+
+	ast_sil164_connector->i2c = ast_i2c_create(dev);
+	if (!ast_sil164_connector->i2c)

drivers/gpu/drm/ast/ast_drv.h

Quoted 10 lines
drivers/gpu/drm/ast/ast_drv.h +10 -0
+		drm_err(dev, "failed to add ddc bus for connector\n");
+
+	if (ast_sil164_connector->i2c)
+		ret = drm_connector_init_with_ddc(dev, connector, &ast_sil164_connector_funcs,
+						  DRM_MODE_CONNECTOR_DVII,
+						  &ast_sil164_connector->i2c->adapter);
+	else
+		ret = drm_connector_init(dev, connector, &ast_sil164_connector_funcs,
+					 DRM_MODE_CONNECTOR_DVII);
+	if (ret)

I think you want a kfree(i2c) here before returning.

And where is the struct ast_i2c_chan freed if the function succeeds ?

With that,

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
author maintainer
#18 lore raw

Re: [PATCH 8/8] drm/ast: Move SIL164-based connector code into separate helpers

Hi

Am 03.02.22 um 18:57 schrieb Javier Martinez Canillas:

Quoted 46 lines · Thomas Zimmermann
Quoted 21 lines

Add helpers for initializing SIL164-based connectors. These used to be handled by the VGA connector code. But SIL164 provides output via DVI-I, so set the encoder and connector types accordingly.

If a SIL164 chip has been detected, ast will now create a DVI-I connector instead of a VGA connector.

---
  drivers/gpu/drm/ast/ast_drv.h  | 15 ++++++
  drivers/gpu/drm/ast/ast_mode.c | 99 +++++++++++++++++++++++++++++++++-
  2 files changed, 112 insertions(+), 2 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +0 -0
index 420d19d8459e..c3a582372649 100644
@@ -140,6 +140,17 @@ to_ast_vga_connector(struct drm_connector *connector)
  	return container_of(connector, struct ast_vga_connector, base);
  }
 

[snip]

Quoted 8 lines
drivers/gpu/drm/ast/ast_drv.h +8 -0
+static int ast_sil164_connector_init(struct drm_device *dev,
+				     struct ast_sil164_connector *ast_sil164_connector)
+{
+	struct drm_connector *connector = &ast_sil164_connector->base;
+	int ret;
+
+	ast_sil164_connector->i2c = ast_i2c_create(dev);
+	if (!ast_sil164_connector->i2c)

drivers/gpu/drm/ast/ast_drv.h

Quoted 10 lines
drivers/gpu/drm/ast/ast_drv.h +10 -0
+		drm_err(dev, "failed to add ddc bus for connector\n");
+
+	if (ast_sil164_connector->i2c)
+		ret = drm_connector_init_with_ddc(dev, connector, &ast_sil164_connector_funcs,
+						  DRM_MODE_CONNECTOR_DVII,
+						  &ast_sil164_connector->i2c->adapter);
+	else
+		ret = drm_connector_init(dev, connector, &ast_sil164_connector_funcs,
+					 DRM_MODE_CONNECTOR_DVII);
+	if (ret)

I think you want a kfree(i2c) here before returning.

Quoted 1 line

And where is the struct ast_i2c_chan freed if the function succeeds ?

The memory and data structure is managed with drmm_add_action_or_reset(). It will be released together with the DRM driver (either on success or failure). See ast_i2c_create() for the details.

Best regards
Thomas

Quoted 6 lines

With that,

Best regards,

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev