drm/ast: Untangle connector helpers
Subsystems (3)
Thomas Zimmermann
maintainerv2 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.
v2:
* move encoder's preferred-CRTC bitmask setup into separate patch (Javier)
Thomas Zimmermann (9):
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: Read encoder possible-CRTC mask from drm_crtc_mask() 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: 0bb81b5d6db5f689b67f9d8b35323235c45e890f
Signature · 1 line
2.34.1
Thomas Zimmermann
maintainerPATCH v2 1/9 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
@@ -1322,18 +1322,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
Thomas Zimmermann
maintainerPATCH v2 2/9 drm/ast: Move connector mode_valid function to CRTC
In reply to Thomas ZimmermannThe 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
@@ -1005,6 +1005,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) {
@@ -1107,6 +1172,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,
@@ -1241,71 +1307,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
Thomas Zimmermann
maintainerPATCH v2 3/9 drm/ast: Remove AST_TX_ITE66121 constant
In reply to Thomas ZimmermannThe 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
@@ -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
Thomas Zimmermann
maintainerPATCH v2 4/9 drm/ast: Remove unused value dp501_maxclk
In reply to Thomas ZimmermannRemove 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
@@ -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
@@ -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
@@ -1284,16 +1284,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
Thomas Zimmermann
maintainerPATCH v2 5/9 drm/ast: Rename struct ast_connector to struct ast_vga_connector
In reply to Thomas ZimmermannPrepare 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
@@ -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
Thomas Zimmermann
maintainerPATCH v2 6/9 drm/ast: Initialize encoder and connector for VGA in helper function
In reply to Thomas ZimmermannMove 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.
v2:
* move encoder CRTC bitmask fix into separate patch (Javier)
--- 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
@@ -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
Thomas Zimmermann
maintainerPATCH v2 7/9 drm/ast: Read encoder possible-CRTC mask from drm_crtc_mask()
In reply to Thomas ZimmermannRead the encoder's possible-CRTC mask from the involved CRTC instead of hard-coding it.
--- drivers/gpu/drm/ast/ast_mode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ast/ast_mode.c +1 -1
@@ -1341,7 +1341,7 @@ static int ast_vga_output_init(struct ast_private *ast) ret =drm_simple_encoder_init (dev, encoder,DRM_MODE_ENCODER_DAC );if (ret)return ret; - encoder->possible_crtcs =1 ; + encoder->possible_crtcs =drm_crtc_mask (crtc); ret =ast_vga_connector_init (dev, ast_vga_connector);if (ret)
Signature · 1 line
2.34.1
Re: [PATCH v2 7/9] drm/ast: Read encoder possible-CRTC mask from drm_crtc_mask()
Quoted 5 lines · Thomas Zimmermann
Read the encoder's possible-CRTC mask from the involved CRTC instead of hard-coding it.
Signed-off-by Thomas Zimmermann <[email protected]>---
Best regards,
Signature · 3 lines
Javier Martinez Canillas Linux Engineering Red Hat
Thomas Zimmermann
maintainerPATCH v2 8/9 drm/ast: Move DP501-based connector code into separate helpers
In reply to Thomas ZimmermannAdd 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
@@ -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
Thomas Zimmermann
maintainerPATCH v2 9/9 drm/ast: Move SIL164-based connector code into separate helpers
In reply to Thomas ZimmermannAdd 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
@@ -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