drm/ast: Clean up display-mode detection and validation
Subsystems (3)
Thomas Zimmermann
maintainerv2 cover drm/ast: Clean up display-mode detection and validation
The ast driver detects support for display modes from hardware features and internal mode tables. Streamline the detection code and put all validation into a single place.
Patches 1 to 6 refactor the code for detecting support for widescreen modes. Regular 4:3 modes are supported by all hardware Gens; support for widescreen modes differs among hardware Gens and individual boards. The series moves all hardware-related code into a single helper function that set state flags accordingly. Other places within the driver then refer to these flags.
Building upon this, patches 7 to 16 refactor display-mode validation. The ast driver contains a list of display modes supported by the VBIOS. The series changes the driver to validate DRM display modes against the VBIOS modes.
Tested on various hardware Gens and display modes.
v2:
- move mode detection into helper functions (Jocelyn)
- replace various large switch statements with LUTs (Jocelyn)
- set max width/height from fullhd flag
Thomas Zimmermann (16):
drm/ast: Remove 1152x864 from list of widescreen resolutions drm/ast: Align naming in widescreen detection code to manual drm/ast: Rename support_wide_screen to support_wsxga_p drm/ast: Reorganize widescreen test around hardware Gens drm/ast: Add support_fullhd flag to struct ast_device drm/ast: Add support_wuxga flag to struct ast_device drm/ast: Always validate H/V sync flags
drm/ast: Find VBIOS mode from regular display size drm/ast: Add empty initializer for VBIOS modes drm/ast: Add helpers for VBIOS mode lookup drm/ast: Validate DRM display modes against VBIOS modes drm/ast: Inline ast_get_vbios_mode_info()
drm/ast: astdp: Rework display-mode setting drm/ast: astdp: Look up mode index from table drm/ast: Remove struct ast_vbios_mode_info drm/ast: Only look up VBIOS mode on full modesets
drivers/gpu/drm/ast/Makefile | 1 + drivers/gpu/drm/ast/ast_dp.c | 168 +++++++++-------- drivers/gpu/drm/ast/ast_drv.c | 2 +- drivers/gpu/drm/ast/ast_drv.h | 30 +-- drivers/gpu/drm/ast/ast_main.c | 102 +++++++--- drivers/gpu/drm/ast/ast_mode.c | 315 +++++++++---------------------- drivers/gpu/drm/ast/ast_post.c | 2 +- drivers/gpu/drm/ast/ast_reg.h | 30 ++- drivers/gpu/drm/ast/ast_tables.h | 187 +----------------- drivers/gpu/drm/ast/ast_vbios.c | 241 +++++++++++++++++++++++ drivers/gpu/drm/ast/ast_vbios.h | 108 +++++++++++ 11 files changed, 628 insertions(+), 558 deletions(-) create mode 100644 drivers/gpu/drm/ast/ast_vbios.c create mode 100644 drivers/gpu/drm/ast/ast_vbios.h
base-commit: 9afc49c1b29a25d9efba5e29e43c9ce3986e569c
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 1/16 drm/ast: Remove 1152x864 from list of widescreen resolutions
The resolution 1152x864 has a ratio of 4:3 and is already handled as such. Remove it from the list of widescreen resolutions.
--- drivers/gpu/drm/ast/ast_mode.c | 2 -- 1 file changed, 2 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +0 -2
@@ -1035,8 +1035,6 @@ ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_modereturn MODE_OK ;if ((mode->hdisplay ==1600 ) && (mode->vdisplay ==900 ))return MODE_OK ; -if ((mode->hdisplay ==1152 ) && (mode->vdisplay ==864 )) -return MODE_OK ; if ((ast->chip == AST2100) || // GEN2, but not AST1100 (?) (ast->chip == AST2200) || // GEN3, but not AST2150 (?)
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 2/16 drm/ast: Align naming in widescreen detection code to manual
In reply to Thomas ZimmermannRename variables and register constants to align with the programming manual. Add new constants where necessary.
--- drivers/gpu/drm/ast/ast_drv.c | 2 +- drivers/gpu/drm/ast/ast_main.c | 8 ++++---- drivers/gpu/drm/ast/ast_post.c | 2 +- drivers/gpu/drm/ast/ast_reg.h | 11 ++++++----- 4 files changed, 12 insertions(+), 11 deletions(-)
drivers/gpu/drm/ast/ast_drv.c +1 -1
@@ -170,7 +170,7 @@ static int ast_detect_chip(struct pci_dev *pdev,/* Patch AST2500/AST2510 */ if ((pdev->revision &0xf0 ) ==0x40 ) { -if (!(vgacrd0 &AST_VRAM_INIT_STATUS_MASK )) +if (!(vgacrd0 &AST_IO_VGACRD0_VRAM_INIT_STATUS_MASK ))ast_patch_ahb_2500 (regs); }
drivers/gpu/drm/ast/ast_main.c +4 -4
@@ -38,7 +38,7 @@static void ast_detect_widescreen (struct ast_device *ast) { -u8 jreg; +u8 vgacrd0;/* Check if we support wide screen */ switch (AST_GEN (ast)) {
@@ -46,10 +46,10 @@ static void ast_detect_widescreen(struct ast_device *ast) ast->support_wide_screen = false;break ;default : - jreg =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xd0 ,0xff ); -if (!(jreg &0x80 )) + vgacrd0 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xd0 ); +if (!(vgacrd0 &AST_IO_VGACRD0_VRAM_INIT_BY_BMC )) ast->support_wide_screen = true; -else if (jreg &0x01 ) +else if (vgacrd0 &AST_IO_VGACRD0_IKVM_WIDESCREEN ) ast->support_wide_screen = true;else { ast->support_wide_screen = false;
drivers/gpu/drm/ast/ast_post.c +1 -1
@@ -2062,7 +2062,7 @@ void ast_post_chip_2500(struct ast_device *ast)u8 reg; reg =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xd0 ,0xff ); -if ((reg &AST_VRAM_INIT_STATUS_MASK ) ==0 ) {/* vga only */ +if ((reg &AST_IO_VGACRD0_VRAM_INIT_STATUS_MASK ) ==0 ) {/* vga only */ /* Clear bus lock condition */ ast_patch_ahb_2500 (ast->regs);
drivers/gpu/drm/ast/ast_reg.h +6 -5
@@ -38,6 +38,12 @@#define AST_IO_VGACRCB_HWC_16BPP BIT(0)/* set: ARGB4444, cleared: 2bpp palette */ #define AST_IO_VGACRCB_HWC_ENABLED BIT(1) +/* mirrors SCU100[7:0] */ +#define AST_IO_VGACRD0_VRAM_INIT_STATUS_MASK GENMASK(7, 6) +#define AST_IO_VGACRD0_VRAM_INIT_BY_BMC BIT(7) +#define AST_IO_VGACRD0_VRAM_INIT_READY BIT(6) +#define AST_IO_VGACRD0_IKVM_WIDESCREEN BIT(0) +#define AST_IO_VGACRD1_MCU_FW_EXECUTING BIT(5)/* Display Transmitter Type */ #define AST_IO_VGACRD1_TX_TYPE_MASK GENMASK(3, 1)
@@ -61,11 +67,6 @@#define AST_IO_VGAIR1_R (0x5A)#define AST_IO_VGAIR1_VREFRESH BIT(3) - -#define AST_VRAM_INIT_STATUS_MASK GENMASK(7, 6) -//#define AST_VRAM_INIT_BY_BMC BIT(7) -//#define AST_VRAM_INIT_READY BIT(6) -/* * AST DisplayPort */
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 3/16 drm/ast: Rename support_wide_screen to support_wsxga_p
In reply to Thomas ZimmermannThe flag support_wide_screen in struct ast_device selects devices that support resolutions of at least 1680x1050 (WSXGA+). Name it accordingly.
--- drivers/gpu/drm/ast/ast_drv.h | 2 +- drivers/gpu/drm/ast/ast_main.c | 16 ++++++++-------- drivers/gpu/drm/ast/ast_mode.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +1 -1
@@ -205,7 +205,7 @@ struct ast_device { } astdp; } output; -bool support_wide_screen; +bool support_wsxga_p;/* 1680x1050 */ u8 *dp501_fw_addr;const struct firmware *dp501_fw;/* dp501 fw */
drivers/gpu/drm/ast/ast_main.c +8 -8
@@ -43,24 +43,24 @@ static void ast_detect_widescreen(struct ast_device *ast)/* Check if we support wide screen */ switch (AST_GEN (ast)) {case 1 : - ast->support_wide_screen = false; + ast->support_wsxga_p = false;break ;default : vgacrd0 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xd0 );if (!(vgacrd0 &AST_IO_VGACRD0_VRAM_INIT_BY_BMC )) - ast->support_wide_screen = true; + ast->support_wsxga_p = true;else if (vgacrd0 &AST_IO_VGACRD0_IKVM_WIDESCREEN ) - ast->support_wide_screen = true; + ast->support_wsxga_p = true;else { - ast->support_wide_screen = false; + ast->support_wsxga_p = false;if (ast->chip ==AST1300 ) - ast->support_wide_screen = true; + ast->support_wsxga_p = true;if (ast->chip ==AST1400 ) - ast->support_wide_screen = true; + ast->support_wsxga_p = true;if (ast->chip ==AST2510 ) - ast->support_wide_screen = true; + ast->support_wsxga_p = true;if (IS_AST_GEN7 (ast)) - ast->support_wide_screen = true; + ast->support_wsxga_p = true; }break ; }
drivers/gpu/drm/ast/ast_mode.c +1 -1
@@ -1024,7 +1024,7 @@ ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_modeenum drm_mode_status status;uint32_t jtemp; -if (ast->support_wide_screen) { +if (ast->support_wsxga_p) {if ((mode->hdisplay ==1680 ) && (mode->vdisplay ==1050 ))return MODE_OK ;if ((mode->hdisplay ==1280 ) && (mode->vdisplay ==800 ))
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 4/16 drm/ast: Reorganize widescreen test around hardware Gens
In reply to Thomas ZimmermannTesting for support of widescreen modes mixes up various hardware Gens. First branch by hardware Gen, then do specific tests for each Gen. By default, widesscreen support is disabled.
Later patches will add more specific tests for each Gen.
v2:
- move shared detection code into helper (Jocelyn)
--- drivers/gpu/drm/ast/ast_main.c | 54 ++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 22 deletions(-)
drivers/gpu/drm/ast/ast_main.c +32 -22
@@ -36,33 +36,43 @@#include "ast_drv.h" +/* Try to detect WSXGA+ on Gen2+ */ +static bool __ast_2100_detect_wsxga_p (struct ast_device *ast) +{ +u8 vgacrd0 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xd0 ); + +if (!(vgacrd0 &AST_IO_VGACRD0_VRAM_INIT_BY_BMC )) +return true; +if (vgacrd0 &AST_IO_VGACRD0_IKVM_WIDESCREEN ) +return true; + +return false; +} +static void ast_detect_widescreen (struct ast_device *ast) { -u8 vgacrd0; + ast->support_wsxga_p = false; -/* Check if we support wide screen */ -switch (AST_GEN (ast)) { -case 1 : - ast->support_wsxga_p = false; -break ; -default : - vgacrd0 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xd0 ); -if (!(vgacrd0 &AST_IO_VGACRD0_VRAM_INIT_BY_BMC )) +if (AST_GEN (ast) >=7 ) { + ast->support_wsxga_p = true; + }else if (AST_GEN (ast) >=6 ) { +if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true; -else if (vgacrd0 &AST_IO_VGACRD0_IKVM_WIDESCREEN ) +else if (ast->chip ==AST2510 ) + ast->support_wsxga_p = true; + }else if (AST_GEN (ast) >=5 ) { +if (__ast_2100_detect_wsxga_p (ast)) + ast->support_wsxga_p = true; +else if (ast->chip ==AST1400 ) + ast->support_wsxga_p = true; + }else if (AST_GEN (ast) >=4 ) { +if (__ast_2100_detect_wsxga_p (ast)) + ast->support_wsxga_p = true; +else if (ast->chip ==AST1300 ) + ast->support_wsxga_p = true; + }else if (AST_GEN (ast) >=2 ) { +if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true; -else { - ast->support_wsxga_p = false; -if (ast->chip ==AST1300 ) - ast->support_wsxga_p = true; -if (ast->chip ==AST1400 ) - ast->support_wsxga_p = true; -if (ast->chip ==AST2510 ) - ast->support_wsxga_p = true; -if (IS_AST_GEN7 (ast)) - ast->support_wsxga_p = true; - } -break ; } }
Signature · 1 line
2.48.1
Re: [PATCH v2 04/16] drm/ast: Reorganize widescreen test around hardware Gens
Quoted 8 lines · Thomas Zimmermann
Testing for support of widescreen modes mixes up various hardware Gens. First branch by hardware Gen, then do specific tests for each Gen. By default, widesscreen support is disabled.
Later patches will add more specific tests for each Gen.
v2:
- move shared detection code into helper (Jocelyn)
Thank for the v2, it looks good to me.
Quoted 76 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_main.c | 54 ++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 22 deletions(-)drivers/gpu/drm/ast/ast_main.c +32
-22@@ -36,33 +36,43 @@#include "ast_drv.h" +/* Try to detect WSXGA+ on Gen2+ */ +static bool __ast_2100_detect_wsxga_p (struct ast_device *ast) +{ +u8 vgacrd0 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xd0 ); + +if (!(vgacrd0 &AST_IO_VGACRD0_VRAM_INIT_BY_BMC )) +return true; +if (vgacrd0 &AST_IO_VGACRD0_IKVM_WIDESCREEN ) +return true; + +return false; +} +static void ast_detect_widescreen (struct ast_device *ast) { -u8 vgacrd0; + ast->support_wsxga_p = false; -/* Check if we support wide screen */ -switch (AST_GEN (ast)) { -case 1 : - ast->support_wsxga_p = false; -break ; -default : - vgacrd0 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xd0 ); -if (!(vgacrd0 &AST_IO_VGACRD0_VRAM_INIT_BY_BMC )) +if (AST_GEN (ast) >=7 ) { + ast->support_wsxga_p = true; + }else if (AST_GEN (ast) >=6 ) { +if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true; -else if (vgacrd0 &AST_IO_VGACRD0_IKVM_WIDESCREEN ) +else if (ast->chip ==AST2510 ) + ast->support_wsxga_p = true; + }else if (AST_GEN (ast) >=5 ) { +if (__ast_2100_detect_wsxga_p (ast)) + ast->support_wsxga_p = true; +else if (ast->chip ==AST1400 ) + ast->support_wsxga_p = true; + }else if (AST_GEN (ast) >=4 ) { +if (__ast_2100_detect_wsxga_p (ast)) + ast->support_wsxga_p = true; +else if (ast->chip ==AST1300 ) + ast->support_wsxga_p = true; + }else if (AST_GEN (ast) >=2 ) { +if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true; -else { - ast->support_wsxga_p = false; -if (ast->chip ==AST1300 ) - ast->support_wsxga_p = true; -if (ast->chip ==AST1400 ) - ast->support_wsxga_p = true; -if (ast->chip ==AST2510 ) - ast->support_wsxga_p = true; -if (IS_AST_GEN7 (ast)) - ast->support_wsxga_p = true; - } -break ; } }
Thomas Zimmermann
maintainerPATCH v2 5/16 drm/ast: Add support_fullhd flag to struct ast_device
In reply to Thomas ZimmermannDetect support for 1920x1080 (FullHD) in ast_detect_widescreen(). The flag is cleared by default. The test logic has been taken from existing code in ast_crtc_helper_mode_valid(). The code in that function is being replaced by the new flag.
For Gen3, a new branch duplicates the Gen2 logic and adds a test for AST2200. Gen2 adds a test for AST2100.
v2:
- use fullhd flag for setting max width/height
--- drivers/gpu/drm/ast/ast_drv.h | 1 + drivers/gpu/drm/ast/ast_main.c | 19 +++++++++++++++++++ drivers/gpu/drm/ast/ast_mode.c | 12 ++---------- 3 files changed, 22 insertions(+), 10 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +1 -0
@@ -206,6 +206,7 @@ struct ast_device { } output;bool support_wsxga_p;/* 1680x1050 */ +bool support_fullhd;/* 1920x1080 */ u8 *dp501_fw_addr;const struct firmware *dp501_fw;/* dp501 fw */
drivers/gpu/drm/ast/ast_main.c +19 -0
@@ -52,27 +52,46 @@ static bool __ast_2100_detect_wsxga_p(struct ast_device *ast)static void ast_detect_widescreen (struct ast_device *ast) { ast->support_wsxga_p = false; + ast->support_fullhd = false;if (AST_GEN (ast) >=7 ) { ast->support_wsxga_p = true; + ast->support_fullhd = true; }else if (AST_GEN (ast) >=6 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;else if (ast->chip ==AST2510 ) ast->support_wsxga_p = true; +if (ast->support_wsxga_p) + ast->support_fullhd = true; }else if (AST_GEN (ast) >=5 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;else if (ast->chip ==AST1400 ) ast->support_wsxga_p = true; +if (ast->support_wsxga_p) + ast->support_fullhd = true; }else if (AST_GEN (ast) >=4 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;else if (ast->chip ==AST1300 ) ast->support_wsxga_p = true; +if (ast->support_wsxga_p) + ast->support_fullhd = true; + }else if (AST_GEN (ast) >=3 ) { +if (__ast_2100_detect_wsxga_p (ast)) + ast->support_wsxga_p = true; +if (ast->support_wsxga_p) { +if (ast->chip ==AST2200 ) + ast->support_fullhd = true; + } }else if (AST_GEN (ast) >=2 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true; +if (ast->support_wsxga_p) { +if (ast->chip ==AST2100 ) + ast->support_fullhd = true; + } } }
drivers/gpu/drm/ast/ast_mode.c +2 -10
@@ -1036,10 +1036,7 @@ ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_modeif ((mode->hdisplay ==1600 ) && (mode->vdisplay ==900 ))return MODE_OK ; -if ((ast->chip ==AST2100 ) ||// GEN2, but not AST1100 (?) - (ast->chip ==AST2200 ) ||// GEN3, but not AST2150 (?) -IS_AST_GEN4 (ast) ||IS_AST_GEN5 (ast) || -IS_AST_GEN6 (ast) ||IS_AST_GEN7 (ast)) { +if (ast->support_fullhd) {if ((mode->hdisplay ==1920 ) && (mode->vdisplay ==1080 ))return MODE_OK ;
@@ -1371,12 +1368,7 @@ int ast_mode_config_init(struct ast_device *ast) dev->mode_config.min_height =0 ; dev->mode_config.preferred_depth =24 ; -if (ast->chip ==AST2100 ||// GEN2, but not AST1100 (?) - ast->chip ==AST2200 ||// GEN3, but not AST2150 (?) -IS_AST_GEN7 (ast) || -IS_AST_GEN6 (ast) || -IS_AST_GEN5 (ast) || -IS_AST_GEN4 (ast)) { +if (ast->support_fullhd) { dev->mode_config.max_width =1920 ; dev->mode_config.max_height =2048 ; }else {
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 6/16 drm/ast: Add support_wuxga flag to struct ast_device
In reply to Thomas ZimmermannDetect support for 1920x1200 (WUXGA) in ast_detect_widescreen(). The flag is cleared by default. The test logic has been taken from existing code in ast_crtc_helper_mode_valid(). The code in that function is being replaced by the new flag.
v2:
- move shared detection code into helper (Jocelyn)
--- drivers/gpu/drm/ast/ast_drv.h | 1 + drivers/gpu/drm/ast/ast_main.c | 27 +++++++++++++++++++++++++++ drivers/gpu/drm/ast/ast_mode.c | 8 +++----- drivers/gpu/drm/ast/ast_reg.h | 1 + 4 files changed, 32 insertions(+), 5 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +1 -0
@@ -207,6 +207,7 @@ struct ast_device {bool support_wsxga_p;/* 1680x1050 */ bool support_fullhd;/* 1920x1080 */ +bool support_wuxga;/* 1920x1200 */ u8 *dp501_fw_addr;const struct firmware *dp501_fw;/* dp501 fw */
drivers/gpu/drm/ast/ast_main.c +27 -0
@@ -49,14 +49,31 @@ static bool __ast_2100_detect_wsxga_p(struct ast_device *ast)return false; } +/* Try to detect WUXGA on Gen2+ */ +static bool __ast_2100_detect_wuxga (struct ast_device *ast) +{ +u8 vgacrd1; + +if (ast->support_fullhd) { + vgacrd1 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xd1 ); +if (!(vgacrd1 &AST_IO_VGACRD1_SUPPORTS_WUXGA )) +return true; + } + +return false; +} +static void ast_detect_widescreen (struct ast_device *ast) { ast->support_wsxga_p = false; ast->support_fullhd = false; + ast->support_wuxga = false;if (AST_GEN (ast) >=7 ) { ast->support_wsxga_p = true; ast->support_fullhd = true; +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; }else if (AST_GEN (ast) >=6 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;
@@ -64,6 +81,8 @@ static void ast_detect_widescreen(struct ast_device *ast) ast->support_wsxga_p = true;if (ast->support_wsxga_p) ast->support_fullhd = true; +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; }else if (AST_GEN (ast) >=5 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;
@@ -71,6 +90,8 @@ static void ast_detect_widescreen(struct ast_device *ast) ast->support_wsxga_p = true;if (ast->support_wsxga_p) ast->support_fullhd = true; +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; }else if (AST_GEN (ast) >=4 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;
@@ -78,6 +99,8 @@ static void ast_detect_widescreen(struct ast_device *ast) ast->support_wsxga_p = true;if (ast->support_wsxga_p) ast->support_fullhd = true; +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; }else if (AST_GEN (ast) >=3 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;
@@ -85,6 +108,8 @@ static void ast_detect_widescreen(struct ast_device *ast)if (ast->chip ==AST2200 ) ast->support_fullhd = true; } +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; }else if (AST_GEN (ast) >=2 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;
@@ -92,6 +117,8 @@ static void ast_detect_widescreen(struct ast_device *ast)if (ast->chip ==AST2100 ) ast->support_fullhd = true; } +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; } }
drivers/gpu/drm/ast/ast_mode.c +3 -5
@@ -1022,7 +1022,6 @@ ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode {struct ast_device *ast =to_ast_device (crtc->dev);enum drm_mode_status status; -uint32_t jtemp;if (ast->support_wsxga_p) {if ((mode->hdisplay ==1680 ) && (mode->vdisplay ==1050 ))
@@ -1041,11 +1040,10 @@ ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_modereturn MODE_OK ;if ((mode->hdisplay ==1920 ) && (mode->vdisplay ==1200 )) { - jtemp =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xd1 ,0xff ); -if (jtemp &0x01 ) -return MODE_NOMODE ; -else +if (ast->support_wuxga)return MODE_OK ; +else +return MODE_NOMODE ; } } }
drivers/gpu/drm/ast/ast_reg.h +1 -0
@@ -55,6 +55,7 @@#define AST_IO_VGACRD1_TX_ANX9807_VBIOS 0x0a#define AST_IO_VGACRD1_TX_FW_EMBEDDED_FW 0x0c/* special case of DP501 */ #define AST_IO_VGACRD1_TX_ASTDP 0x0e +#define AST_IO_VGACRD1_SUPPORTS_WUXGA BIT(0)#define AST_IO_VGACRD7_EDID_VALID_FLAG BIT(0)#define AST_IO_VGACRDC_LINK_SUCCESS BIT(0)
Signature · 1 line
2.48.1
Re: [PATCH v2 06/16] drm/ast: Add support_wuxga flag to struct ast_device
Quoted 7 lines · Thomas Zimmermann
Detect support for 1920x1200 (WUXGA) in
ast_detect_widescreen(). The flag is cleared by default. The test logic has been taken from existing code inast_crtc_helper_mode_valid(). The code in that function is being replaced by the new flag.v2:
- move shared detection code into helper (Jocelyn)
Thanks, it looks good to me.
Quoted 141 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_drv.h | 1 + drivers/gpu/drm/ast/ast_main.c | 27 +++++++++++++++++++++++++++ drivers/gpu/drm/ast/ast_mode.c | 8 +++----- drivers/gpu/drm/ast/ast_reg.h | 1 + 4 files changed, 32 insertions(+), 5 deletions(-)drivers/gpu/drm/ast/ast_drv.h +1
-0@@ -207,6 +207,7 @@ struct ast_device {bool support_wsxga_p;/* 1680x1050 */ bool support_fullhd;/* 1920x1080 */ +bool support_wuxga;/* 1920x1200 */ u8 *dp501_fw_addr;const struct firmware *dp501_fw;/* dp501 fw */ drivers/gpu/drm/ast/ast_main.c +27
-0@@ -49,14 +49,31 @@ static bool __ast_2100_detect_wsxga_p(struct ast_device *ast)return false; } +/* Try to detect WUXGA on Gen2+ */ +static bool __ast_2100_detect_wuxga (struct ast_device *ast) +{ +u8 vgacrd1; + +if (ast->support_fullhd) { + vgacrd1 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xd1 ); +if (!(vgacrd1 &AST_IO_VGACRD1_SUPPORTS_WUXGA )) +return true; + } + +return false; +} +static void ast_detect_widescreen (struct ast_device *ast) { ast->support_wsxga_p = false; ast->support_fullhd = false; + ast->support_wuxga = false;if (AST_GEN (ast) >=7 ) { ast->support_wsxga_p = true; ast->support_fullhd = true; +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; }else if (AST_GEN (ast) >=6 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;@@ -64,6 +81,8 @@ static void ast_detect_widescreen(struct ast_device *ast) ast->support_wsxga_p = true;if (ast->support_wsxga_p) ast->support_fullhd = true; +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; }else if (AST_GEN (ast) >=5 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;@@ -71,6 +90,8 @@ static void ast_detect_widescreen(struct ast_device *ast) ast->support_wsxga_p = true;if (ast->support_wsxga_p) ast->support_fullhd = true; +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; }else if (AST_GEN (ast) >=4 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;@@ -78,6 +99,8 @@ static void ast_detect_widescreen(struct ast_device *ast) ast->support_wsxga_p = true;if (ast->support_wsxga_p) ast->support_fullhd = true; +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; }else if (AST_GEN (ast) >=3 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;@@ -85,6 +108,8 @@ static void ast_detect_widescreen(struct ast_device *ast)if (ast->chip ==AST2200 ) ast->support_fullhd = true; } +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; }else if (AST_GEN (ast) >=2 ) {if (__ast_2100_detect_wsxga_p (ast)) ast->support_wsxga_p = true;@@ -92,6 +117,8 @@ static void ast_detect_widescreen(struct ast_device *ast)if (ast->chip ==AST2100 ) ast->support_fullhd = true; } +if (__ast_2100_detect_wuxga (ast)) + ast->support_wuxga = true; } }drivers/gpu/drm/ast/ast_mode.c +3
-5@@ -1022,7 +1022,6 @@ ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode {struct ast_device *ast =to_ast_device (crtc->dev);enum drm_mode_status status; -uint32_t jtemp;if (ast->support_wsxga_p) {if ((mode->hdisplay ==1680 ) && (mode->vdisplay ==1050 ))@@ -1041,11 +1040,10 @@ ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_modereturn MODE_OK ;if ((mode->hdisplay ==1920 ) && (mode->vdisplay ==1200 )) { - jtemp =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xd1 ,0xff ); -if (jtemp &0x01 ) -return MODE_NOMODE ; -else +if (ast->support_wuxga)return MODE_OK ; +else +return MODE_NOMODE ; } } }drivers/gpu/drm/ast/ast_reg.h +1
-0@@ -55,6 +55,7 @@#define AST_IO_VGACRD1_TX_ANX9807_VBIOS 0x0a#define AST_IO_VGACRD1_TX_FW_EMBEDDED_FW 0x0c/* special case of DP501 */ #define AST_IO_VGACRD1_TX_ASTDP 0x0e +#define AST_IO_VGACRD1_SUPPORTS_WUXGA BIT(0)#define AST_IO_VGACRD7_EDID_VALID_FLAG BIT(0)#define AST_IO_VGACRDC_LINK_SUCCESS BIT(0)
Thomas Zimmermann
maintainerPATCH v2 7/16 drm/ast: Always validate H/V sync flags
In reply to Thomas ZimmermannThe ast driver matches DRM display modes against an internal list of modes supported by the VBIOS. Matching H/V sync flags between modes is preferred, but optional. If sync flags are not matching, the driver would program the VBIOS settings to hardware and let the display handle the difference.
DRM modes are generated from attached displays or standard mode lines. Therefore differences to the VBIOS modes are not just cosmetical, but signal possible incompatibility with the display hardware.
Hence make matching H/V sync flags mandatory. If the VBIOS does not support a certain mode, we should report it as unsupported. Note that the VBIOS mode tables all appear to refer to standard modes.
(If sync flags really make no difference to the VBIOS, the ast driver shouldn't match them in the first place.)
--- drivers/gpu/drm/ast/ast_mode.c | 45 ++++++++++++++-------------------- 1 file changed, 18 insertions(+), 27 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +18 -27
@@ -113,8 +113,8 @@ static bool ast_get_vbios_mode_info(const struct drm_format_info *format, {u32 refresh_rate_index =0 , refresh_rate;const struct ast_vbios_enhtable *best =NULL ; +const struct ast_vbios_enhtable *loop;u32 hborder, vborder; -bool check_sync;switch (format->cpp[0 ] *8 ) {case 8 :
@@ -176,36 +176,27 @@ static bool ast_get_vbios_mode_info(const struct drm_format_info *format, } refresh_rate =drm_mode_vrefresh (mode); - check_sync = vbios_mode->enh_table->flags & WideScreenMode; - -while (1 ) { -const struct ast_vbios_enhtable *loop = vbios_mode->enh_table; - -while (loop->refresh_rate !=0xff ) { -if ((check_sync) && - (((mode->flags &DRM_MODE_FLAG_NVSYNC ) && - (loop->flags & PVSync)) || - ((mode->flags &DRM_MODE_FLAG_PVSYNC ) && - (loop->flags & NVSync)) || - ((mode->flags &DRM_MODE_FLAG_NHSYNC ) && - (loop->flags & PHSync)) || - ((mode->flags &DRM_MODE_FLAG_PHSYNC ) && - (loop->flags & NHSync)))) { - loop++; -continue ; - } -if (loop->refresh_rate <= refresh_rate - && (!best || loop->refresh_rate > best->refresh_rate)) - best = loop; + + loop = vbios_mode->enh_table; + +while (loop->refresh_rate !=0xff ) { +if (((mode->flags &DRM_MODE_FLAG_NVSYNC ) && (loop->flags & PVSync)) || + ((mode->flags &DRM_MODE_FLAG_PVSYNC ) && (loop->flags & NVSync)) || + ((mode->flags &DRM_MODE_FLAG_NHSYNC ) && (loop->flags & PHSync)) || + ((mode->flags &DRM_MODE_FLAG_PHSYNC ) && (loop->flags & NHSync))) { loop++; +continue ; } -if (best || !check_sync) -break ; - check_sync =0 ; +if (loop->refresh_rate <= refresh_rate && + (!best || loop->refresh_rate > best->refresh_rate)) + best = loop; + loop++; } -if (best) - vbios_mode->enh_table = best; +if (!best) +return false; + + vbios_mode->enh_table = best; hborder = (vbios_mode->enh_table->flags & HBorder) ?8 :0 ; vborder = (vbios_mode->enh_table->flags & VBorder) ?8 :0 ;
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 8/16 drm/ast: Find VBIOS mode from regular display size
In reply to Thomas ZimmermannThe ast driver looks up supplied display modes from an internal list of display modes supported by the VBIOS.
Do not use the crtc_-prefixed display values from struct drm_display_mode for looking up the VBIOS mode. The fields contain raw values that the driver programs to hardware. They are affected by display settings like double-scan or interlace.
Instead use the regular vdisplay and hdisplay fields for lookup. As the programmed values can now differ from the values used for lookup, set struct drm_display_mode.crtc_vdisplay and .crtc_hdisplay from the VBIOS mode.
--- drivers/gpu/drm/ast/ast_mode.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +6 -4
@@ -131,7 +131,7 @@ static bool ast_get_vbios_mode_info(const struct drm_format_info *format,return false; } -switch (mode->crtc_hdisplay) { +switch (mode->hdisplay) {case 640 : vbios_mode->enh_table = &res_640x480[refresh_rate_index];break ;
@@ -145,7 +145,7 @@ static bool ast_get_vbios_mode_info(const struct drm_format_info *format, vbios_mode->enh_table = &res_1152x864[refresh_rate_index];break ;case 1280 : -if (mode->crtc_vdisplay ==800 ) +if (mode->vdisplay ==800 ) vbios_mode->enh_table = &res_1280x800[refresh_rate_index];else vbios_mode->enh_table = &res_1280x1024[refresh_rate_index];
@@ -157,7 +157,7 @@ static bool ast_get_vbios_mode_info(const struct drm_format_info *format, vbios_mode->enh_table = &res_1440x900[refresh_rate_index];break ;case 1600 : -if (mode->crtc_vdisplay ==900 ) +if (mode->vdisplay ==900 ) vbios_mode->enh_table = &res_1600x900[refresh_rate_index];else vbios_mode->enh_table = &res_1600x1200[refresh_rate_index];
@@ -166,7 +166,7 @@ static bool ast_get_vbios_mode_info(const struct drm_format_info *format, vbios_mode->enh_table = &res_1680x1050[refresh_rate_index];break ;case 1920 : -if (mode->crtc_vdisplay ==1080 ) +if (mode->vdisplay ==1080 ) vbios_mode->enh_table = &res_1920x1080[refresh_rate_index];else vbios_mode->enh_table = &res_1920x1200[refresh_rate_index];
@@ -201,6 +201,7 @@ static bool ast_get_vbios_mode_info(const struct drm_format_info *format, hborder = (vbios_mode->enh_table->flags & HBorder) ?8 :0 ; vborder = (vbios_mode->enh_table->flags & VBorder) ?8 :0 ; + adjusted_mode->crtc_hdisplay = vbios_mode->enh_table->hde; adjusted_mode->crtc_htotal = vbios_mode->enh_table->ht; adjusted_mode->crtc_hblank_start = vbios_mode->enh_table->hde + hborder; adjusted_mode->crtc_hblank_end = vbios_mode->enh_table->ht - hborder;
@@ -210,6 +211,7 @@ static bool ast_get_vbios_mode_info(const struct drm_format_info *format, vbios_mode->enh_table->hfp + vbios_mode->enh_table->hsync); + adjusted_mode->crtc_vdisplay = vbios_mode->enh_table->vde; adjusted_mode->crtc_vtotal = vbios_mode->enh_table->vt; adjusted_mode->crtc_vblank_start = vbios_mode->enh_table->vde + vborder; adjusted_mode->crtc_vblank_end = vbios_mode->enh_table->vt - vborder;
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 9/16 drm/ast: Add empty initializer for VBIOS modes
In reply to Thomas ZimmermannVBIOS mode tables are terminated by an entry with a refresh rate of 0xff. The code is hard to read and fragile to use. Therefore create an empty entry with AST_VBIOS_MODE_INVALID to terminate each mode list.
Stop at the invalid entry when searching for modes in the tables. Instead of testing for refresh == 0xff, test with a helper function if the mode's size and refresh have meaningful values.
--- drivers/gpu/drm/ast/ast_mode.c | 2 +- drivers/gpu/drm/ast/ast_tables.h | 52 ++++++++++++++------------------ 2 files changed, 24 insertions(+), 30 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +1 -1
@@ -179,7 +179,7 @@ static bool ast_get_vbios_mode_info(const struct drm_format_info *format, loop = vbios_mode->enh_table; -while (loop->refresh_rate !=0xff ) { +while (ast_vbios_mode_is_valid (loop)) { if (((mode->flags & DRM_MODE_FLAG_NVSYNC) && (loop->flags & PVSync)) || ((mode->flags & DRM_MODE_FLAG_PVSYNC) && (loop->flags & NVSync)) || ((mode->flags & DRM_MODE_FLAG_NHSYNC) && (loop->flags & PHSync)) ||
drivers/gpu/drm/ast/ast_tables.h +23 -29
140 lines not on this page · raw message
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 10/16 drm/ast: Add helpers for VBIOS mode lookup
In reply to Thomas ZimmermannMode lines are independent from hardware Gen or TX chip, so hide all VBIOS mode tables in ast_vbios.c.
Move the look-up code for VBIOS modes from ast_vbios_get_mode_info() to ast_vbios_find_mode(). The new look-up function respects the supported-mode flags in struct ast_device. For example, if a device does not have struct ast_device.support_fullhd set, the helper does not return a valid mode for 1920x1080. Taking the supported-mode flags into account allows for making the VBIOS tables the single reference for validating and setting display modes against hardware capabilities.
v2:
- replace mode switch with look-up table (Jocelyn)
--- drivers/gpu/drm/ast/Makefile | 1 + drivers/gpu/drm/ast/ast_dp.c | 1 + drivers/gpu/drm/ast/ast_drv.h | 18 +-- drivers/gpu/drm/ast/ast_mode.c | 77 +--------- drivers/gpu/drm/ast/ast_tables.h | 177 ----------------------- drivers/gpu/drm/ast/ast_vbios.c | 241 +++++++++++++++++++++++++++++++ drivers/gpu/drm/ast/ast_vbios.h | 108 ++++++++++++++ 7 files changed, 360 insertions(+), 263 deletions(-) create mode 100644 drivers/gpu/drm/ast/ast_vbios.c create mode 100644 drivers/gpu/drm/ast/ast_vbios.h
drivers/gpu/drm/ast/Makefile +1 -0
@@ -13,6 +13,7 @@ ast-y := \ ast_mode.o \ ast_post.o \ ast_sil164.o \ + ast_vbios.o \ ast_vga.o obj-$(CONFIG_DRM_AST) := ast.o
drivers/gpu/drm/ast/ast_dp.c +1 -0
@@ -12,6 +12,7 @@#include <drm/drm_probe_helper.h> #include "ast_drv.h" +#include "ast_vbios.h" static bool ast_astdp_is_connected (struct ast_device *ast) {
drivers/gpu/drm/ast/ast_drv.h +2 -16
@@ -39,6 +39,8 @@#include "ast_reg.h" +struct ast_vbios_enhtable ; +#define DRIVER_AUTHOR "Dave Airlie"#define DRIVER_NAME "ast"
@@ -350,22 +352,6 @@ struct ast_vbios_stdtable {u8 gr[9 ]; }; -struct ast_vbios_enhtable { -u32 ht; -u32 hde; -u32 hfp; -u32 hsync; -u32 vt; -u32 vde; -u32 vfp; -u32 vsync; -u32 dclk_index; -u32 flags; -u32 refresh_rate; -u32 refresh_rate_index; -u32 mode_id; -}; -struct ast_vbios_dclk_info {u8 param1;u8 param2;
drivers/gpu/drm/ast/ast_mode.c +7 -70
113 lines not on this page · raw message
drivers/gpu/drm/ast/ast_tables.h +0 -177
187 lines not on this page · raw message
drivers/gpu/drm/ast/ast_vbios.c new file +241 -0
241 lines not on this page · raw message
drivers/gpu/drm/ast/ast_vbios.h new file +108 -0
108 lines not on this page · raw message
Signature · 1 line
2.48.1
Jocelyn Falempe
reviewerRe: [PATCH v2 10/16] drm/ast: Add helpers for VBIOS mode lookup
Quoted 11 lines · Thomas Zimmermann
Mode lines are independent from hardware Gen or TX chip, so hide all VBIOS mode tables in
ast_vbios.c.Move the look-up code for VBIOS modes from
ast_vbios_get_mode_info()toast_vbios_find_mode(). The new look-up function respects the supported-mode flags in structast_device. For example, if a device does not have struct ast_device.support_fullhd set, the helper does not return a valid mode for 1920x1080. Taking the supported-mode flags into account allows for making the VBIOS tables the single reference for validating and setting display modes against hardware capabilities.
Quoted 2 lines
v2:
- replace mode switch with look-up table (Jocelyn)
Thanks for this v2, I find it much more readable than the previous big switch.
Quoted 751 lines
Signed-off-by Thomas Zimmermann <[email protected]>Reviewed-by Jocelyn Falempe <[email protected]>--- drivers/gpu/drm/ast/Makefile | 1 + drivers/gpu/drm/ast/ast_dp.c | 1 + drivers/gpu/drm/ast/ast_drv.h | 18 +-- drivers/gpu/drm/ast/ast_mode.c | 77 +--------- drivers/gpu/drm/ast/ast_tables.h | 177 ----------------------- drivers/gpu/drm/ast/ast_vbios.c | 241 +++++++++++++++++++++++++++++++ drivers/gpu/drm/ast/ast_vbios.h | 108 ++++++++++++++ 7 files changed, 360 insertions(+), 263 deletions(-)create mode 100644
drivers/gpu/drm/ast/ast_vbios.ccreate mode 100644drivers/gpu/drm/ast/ast_vbios.hdrivers/gpu/drm/ast/Makefile +1
-0@@ -13,6 +13,7 @@ ast-y := \ ast_mode.o \ ast_post.o \ ast_sil164.o \ + ast_vbios.o \ ast_vga.o obj-$(CONFIG_DRM_AST) := ast.odrivers/gpu/drm/ast/ast_dp.c +1
-0@@ -12,6 +12,7 @@#include <drm/drm_probe_helper.h> #include "ast_drv.h" +#include "ast_vbios.h" static bool ast_astdp_is_connected (struct ast_device *ast) {drivers/gpu/drm/ast/ast_drv.h +2
-16@@ -39,6 +39,8 @@#include "ast_reg.h" +struct ast_vbios_enhtable ; +#define DRIVER_AUTHOR "Dave Airlie"#define DRIVER_NAME "ast"@@ -350,22 +352,6 @@ struct ast_vbios_stdtable {u8 gr[9 ]; }; -struct ast_vbios_enhtable { -u32 ht; -u32 hde; -u32 hfp; -u32 hsync; -u32 vt; -u32 vde; -u32 vfp; -u32 vsync; -u32 dclk_index; -u32 flags; -u32 refresh_rate; -u32 refresh_rate_index; -u32 mode_id; -}; -struct ast_vbios_dclk_info {u8 param1;u8 param2;drivers/gpu/drm/ast/ast_mode.c +7
-70@@ -47,6 +47,7 @@#include "ast_drv.h" #include "ast_tables.h" +#include "ast_vbios.h" #define AST_LUT_SIZE 256@@ -106,14 +107,12 @@ static void ast_crtc_set_gamma(struct ast_device *ast, } } -static bool ast_get_vbios_mode_info (const struct drm_format_info *format, +static bool ast_get_vbios_mode_info (struct ast_device *ast, +const struct drm_format_info *format,const struct drm_display_mode *mode,struct drm_display_mode *adjusted_mode,struct ast_vbios_mode_info *vbios_mode) { -u32 refresh_rate_index =0 , refresh_rate; -const struct ast_vbios_enhtable *best =NULL ; -const struct ast_vbios_enhtable *loop;u32 hborder, vborder;switch (format->cpp[0 ] *8 ) {@@ -131,73 +130,10 @@ static bool ast_get_vbios_mode_info(const struct drm_format_info *format,return false; } -switch (mode->hdisplay) { -case 640 : - vbios_mode->enh_table = &res_640x480[refresh_rate_index]; -break ; -case 800 : - vbios_mode->enh_table = &res_800x600[refresh_rate_index]; -break ; -case 1024 : - vbios_mode->enh_table = &res_1024x768[refresh_rate_index]; -break ; -case 1152 : - vbios_mode->enh_table = &res_1152x864[refresh_rate_index]; -break ; -case 1280 : -if (mode->vdisplay ==800 ) - vbios_mode->enh_table = &res_1280x800[refresh_rate_index]; -else - vbios_mode->enh_table = &res_1280x1024[refresh_rate_index]; -break ; -case 1360 : - vbios_mode->enh_table = &res_1360x768[refresh_rate_index]; -break ; -case 1440 : - vbios_mode->enh_table = &res_1440x900[refresh_rate_index]; -break ; -case 1600 : -if (mode->vdisplay ==900 ) - vbios_mode->enh_table = &res_1600x900[refresh_rate_index]; -else - vbios_mode->enh_table = &res_1600x1200[refresh_rate_index]; -break ; -case 1680 : - vbios_mode->enh_table = &res_1680x1050[refresh_rate_index]; -break ; -case 1920 : -if (mode->vdisplay ==1080 ) - vbios_mode->enh_table = &res_1920x1080[refresh_rate_index]; -else - vbios_mode->enh_table = &res_1920x1200[refresh_rate_index]; -break ; -default : -return false; - } - - refresh_rate =drm_mode_vrefresh (mode); - - loop = vbios_mode->enh_table; - -while (ast_vbios_mode_is_valid (loop)) { -if (((mode->flags &DRM_MODE_FLAG_NVSYNC ) && (loop->flags & PVSync)) || - ((mode->flags &DRM_MODE_FLAG_PVSYNC ) && (loop->flags & NVSync)) || - ((mode->flags &DRM_MODE_FLAG_NHSYNC ) && (loop->flags & PHSync)) || - ((mode->flags &DRM_MODE_FLAG_PHSYNC ) && (loop->flags & NHSync))) { - loop++; -continue ; - } -if (loop->refresh_rate <= refresh_rate && - (!best || loop->refresh_rate > best->refresh_rate)) - best = loop; - loop++; - } - -if (!best) + vbios_mode->enh_table =ast_vbios_find_mode (ast, mode); +if (!vbios_mode->enh_table)return false; - vbios_mode->enh_table = best; - hborder = (vbios_mode->enh_table->flags & HBorder) ?8 :0 ; vborder = (vbios_mode->enh_table->flags & VBorder) ?8 :0 ;@@ -1109,6 +1045,7 @@ static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc,struct drm_crtc_state *old_crtc_state =drm_atomic_get_old_crtc_state (state, crtc);struct ast_crtc_state *old_ast_crtc_state =to_ast_crtc_state (old_crtc_state);struct drm_device *dev = crtc->dev; +struct ast_device *ast =to_ast_device (dev);struct ast_crtc_state *ast_state;const struct drm_format_info *format;bool succ;@@ -1143,7 +1080,7 @@ static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc, } } - succ =ast_get_vbios_mode_info (format, &crtc_state->mode, + succ =ast_get_vbios_mode_info (ast, format, &crtc_state->mode, &crtc_state->adjusted_mode, &ast_state->vbios_mode_info);if (!succ)drivers/gpu/drm/ast/ast_tables.h +0
-177@@ -33,54 +33,6 @@#define HiCModeIndex 3#define TrueCModeIndex 4 -#define Charx8Dot 0x00000001 -#define HalfDCLK 0x00000002 -#define DoubleScanMode 0x00000004 -#define LineCompareOff 0x00000008 -#define HBorder 0x00000020 -#define VBorder 0x00000010 -#define WideScreenMode 0x00000100 -#define NewModeInfo 0x00000200 -#define NHSync 0x00000400 -#define PHSync 0x00000800 -#define NVSync 0x00001000 -#define PVSync 0x00002000 -#define SyncPP (PVSync | PHSync) -#define SyncPN (PVSync | NHSync) -#define SyncNP (NVSync | PHSync) -#define SyncNN (NVSync | NHSync) -#define AST2500PreCatchCRT 0x00004000 - -/* DCLK Index */ -#define VCLK25_175 0x00 -#define VCLK28_322 0x01 -#define VCLK31_5 0x02 -#define VCLK36 0x03 -#define VCLK40 0x04 -#define VCLK49_5 0x05 -#define VCLK50 0x06 -#define VCLK56_25 0x07 -#define VCLK65 0x08 -#define VCLK75 0x09 -#define VCLK78_75 0x0A -#define VCLK94_5 0x0B -#define VCLK108 0x0C -#define VCLK135 0x0D -#define VCLK157_5 0x0E -#define VCLK162 0x0F -/* #define VCLK193_25 0x10 */ -#define VCLK154 0x10 -#define VCLK83_5 0x11 -#define VCLK106_5 0x12 -#define VCLK146_25 0x13 -#define VCLK148_5 0x14 -#define VCLK71 0x15 -#define VCLK88_75 0x16 -#define VCLK119 0x17 -#define VCLK85_5 0x18 -#define VCLK97_75 0x19 -#define VCLK118_25 0x1A -static const struct ast_vbios_dclk_info dclk_table[] = { {0x2C ,0xE7 ,0x03 },/* 00: VCLK25_175 */ {0x95 ,0x62 ,0x03 },/* 01: VCLK28_322 */ @@ -214,133 +166,4 @@ static const struct ast_vbios_stdtable vbios_stdtable[] = { }, }; -#define AST_VBIOS_INVALID_MODE \ - {0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u} - -static inline bool ast_vbios_mode_is_valid (const struct ast_vbios_enhtable *vmode) -{ -return vmode->ht && vmode->vt && vmode->refresh_rate; -} - -static const struct ast_vbios_enhtable res_640x480[] = { - {800 ,640 ,8 ,96 ,525 ,480 ,2 ,2 ,VCLK25_175 ,/* 60Hz */ - (SyncNN | HBorder | VBorder | Charx8Dot),60 ,1 ,0x2E }, - {832 ,640 ,16 ,40 ,520 ,480 ,1 ,3 ,VCLK31_5 ,/* 72Hz */ - (SyncNN | HBorder | VBorder | Charx8Dot),72 ,2 ,0x2E }, - {840 ,640 ,16 ,64 ,500 ,480 ,1 ,3 ,VCLK31_5 ,/* 75Hz */ - (SyncNN | Charx8Dot) ,75 ,3 ,0x2E }, - {832 ,640 ,56 ,56 ,509 ,480 ,1 ,3 ,VCLK36 ,/* 85Hz */ - (SyncNN | Charx8Dot) ,85 ,4 ,0x2E }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; - -static const struct ast_vbios_enhtable res_800x600[] = { - {1024 ,800 ,24 ,72 ,625 ,600 ,1 ,2 ,VCLK36 ,/* 56Hz */ - (SyncPP | Charx8Dot),56 ,1 ,0x30 }, - {1056 ,800 ,40 ,128 ,628 ,600 ,1 ,4 ,VCLK40 ,/* 60Hz */ - (SyncPP | Charx8Dot),60 ,2 ,0x30 }, - {1040 ,800 ,56 ,120 ,666 ,600 ,37 ,6 ,VCLK50 ,/* 72Hz */ - (SyncPP | Charx8Dot),72 ,3 ,0x30 }, - {1056 ,800 ,16 ,80 ,625 ,600 ,1 ,3 ,VCLK49_5 ,/* 75Hz */ - (SyncPP | Charx8Dot),75 ,4 ,0x30 }, - {1048 ,800 ,32 ,64 ,631 ,600 ,1 ,3 ,VCLK56_25 ,/* 85Hz */ - (SyncPP | Charx8Dot),84 ,5 ,0x30 }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; - - -static const struct ast_vbios_enhtable res_1024x768[] = { - {1344 ,1024 ,24 ,136 ,806 ,768 ,3 ,6 ,VCLK65 ,/* 60Hz */ - (SyncNN | Charx8Dot),60 ,1 ,0x31 }, - {1328 ,1024 ,24 ,136 ,806 ,768 ,3 ,6 ,VCLK75 ,/* 70Hz */ - (SyncNN | Charx8Dot),70 ,2 ,0x31 }, - {1312 ,1024 ,16 ,96 ,800 ,768 ,1 ,3 ,VCLK78_75 ,/* 75Hz */ - (SyncPP | Charx8Dot),75 ,3 ,0x31 }, - {1376 ,1024 ,48 ,96 ,808 ,768 ,1 ,3 ,VCLK94_5 ,/* 85Hz */ - (SyncPP | Charx8Dot),84 ,4 ,0x31 }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; - -static const struct ast_vbios_enhtable res_1280x1024[] = { - {1688 ,1280 ,48 ,112 ,1066 ,1024 ,1 ,3 ,VCLK108 ,/* 60Hz */ - (SyncPP | Charx8Dot),60 ,1 ,0x32 }, - {1688 ,1280 ,16 ,144 ,1066 ,1024 ,1 ,3 ,VCLK135 ,/* 75Hz */ - (SyncPP | Charx8Dot),75 ,2 ,0x32 }, - {1728 ,1280 ,64 ,160 ,1072 ,1024 ,1 ,3 ,VCLK157_5 ,/* 85Hz */ - (SyncPP | Charx8Dot),85 ,3 ,0x32 }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; - -static const struct ast_vbios_enhtable res_1600x1200[] = { - {2160 ,1600 ,64 ,192 ,1250 ,1200 ,1 ,3 ,VCLK162 ,/* 60Hz */ - (SyncPP | Charx8Dot),60 ,1 ,0x33 }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; - -static const struct ast_vbios_enhtable res_1152x864[] = { - {1600 ,1152 ,64 ,128 ,900 ,864 ,1 ,3 ,VCLK108 ,/* 75Hz */ - (SyncPP | Charx8Dot | NewModeInfo),75 ,1 ,0x3B }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; - -/* 16:9 */ -static const struct ast_vbios_enhtable res_1360x768[] = { - {1792 ,1360 ,64 ,112 ,795 ,768 ,3 ,6 ,VCLK85_5 ,/* 60Hz */ - (SyncPP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo),60 ,1 ,0x39 }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; - -static const struct ast_vbios_enhtable res_1600x900[] = { - {1760 ,1600 ,48 ,32 ,926 ,900 ,3 ,5 ,VCLK97_75 ,/* 60Hz CVT RB */ - (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | - AST2500PreCatchCRT),60 ,1 ,0x3A }, - {2112 ,1600 ,88 ,168 ,934 ,900 ,3 ,5 ,VCLK118_25 ,/* 60Hz CVT */ - (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo),60 ,2 ,0x3A }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; - -static const struct ast_vbios_enhtable res_1920x1080[] = { - {2200 ,1920 ,88 ,44 ,1125 ,1080 ,4 ,5 ,VCLK148_5 ,/* 60Hz */ - (SyncPP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | - AST2500PreCatchCRT),60 ,1 ,0x38 }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; - - -/* 16:10 */ -static const struct ast_vbios_enhtable res_1280x800[] = { - {1440 ,1280 ,48 ,32 ,823 ,800 ,3 ,6 ,VCLK71 ,/* 60Hz RB */ - (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | - AST2500PreCatchCRT),60 ,1 ,0x35 }, - {1680 ,1280 ,72 ,128 ,831 ,800 ,3 ,6 ,VCLK83_5 ,/* 60Hz */ - (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo),60 ,2 ,0x35 }, -AST_VBIOS_INVALID_MODE ,/* end */ - -}; - -static const struct ast_vbios_enhtable res_1440x900[] = { - {1600 ,1440 ,48 ,32 ,926 ,900 ,3 ,6 ,VCLK88_75 ,/* 60Hz RB */ - (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | - AST2500PreCatchCRT),60 ,1 ,0x36 }, - {1904 ,1440 ,80 ,152 ,934 ,900 ,3 ,6 ,VCLK106_5 ,/* 60Hz */ - (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo),60 ,2 ,0x36 }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; - -static const struct ast_vbios_enhtable res_1680x1050[] = { - {1840 ,1680 ,48 ,32 ,1080 ,1050 ,3 ,6 ,VCLK119 ,/* 60Hz RB */ - (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | - AST2500PreCatchCRT),60 ,1 ,0x37 }, - {2240 ,1680 ,104 ,176 ,1089 ,1050 ,3 ,6 ,VCLK146_25 ,/* 60Hz */ - (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo),60 ,2 ,0x37 }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; - -static const struct ast_vbios_enhtable res_1920x1200[] = { - {2080 ,1920 ,48 ,32 ,1235 ,1200 ,3 ,6 ,VCLK154 ,/* 60Hz RB*/ - (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | - AST2500PreCatchCRT),60 ,1 ,0x34 }, -AST_VBIOS_INVALID_MODE ,/* end */ -}; -#endif drivers/gpu/drm/ast/ast_vbios.c new file +241
-0@@ -0,0 +1,241 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright (c) 2005 ASPEED Technology Inc. +* +* Permission to use, copy, modify, distribute, and sell this software and its +* documentation for any purpose is hereby granted without fee, provided that +* the above copyright notice appear in all copies and that both that +* copyright notice and this permission notice appear in supporting +* documentation, and that the name of the authors not be used in +* advertising or publicity pertaining to distribution of the software without +* specific, written prior permission. The authors makes no representations +* about the suitability of this software for any purpose. It is provided +* "as is" without express or implied warranty. +* +* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR +* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +* PERFORMANCE OF THIS SOFTWARE. +*/ + +#include "ast_drv.h" +#include "ast_vbios.h" + +/* 4:3 */ + +static const struct ast_vbios_enhtable res_640x480[] = { + {800 ,640 ,8 ,96 ,525 ,480 ,2 ,2 ,VCLK25_175 ,/* 60 Hz */ + (SyncNN | HBorder | VBorder | Charx8Dot),60 ,1 ,0x2e }, + {832 ,640 ,16 ,40 ,520 ,480 ,1 ,3 ,VCLK31_5 ,/* 72 Hz */ + (SyncNN | HBorder | VBorder | Charx8Dot),72 ,2 ,0x2e }, + {840 ,640 ,16 ,64 ,500 ,480 ,1 ,3 ,VCLK31_5 ,/* 75 Hz */ + (SyncNN | Charx8Dot),75 ,3 ,0x2e }, + {832 ,640 ,56 ,56 ,509 ,480 ,1 ,3 ,VCLK36 ,/* 85 Hz */ + (SyncNN | Charx8Dot),85 ,4 ,0x2e }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +static const struct ast_vbios_enhtable res_800x600[] = { + {1024 ,800 ,24 ,72 ,625 ,600 ,1 ,2 ,VCLK36 ,/* 56 Hz */ + (SyncPP | Charx8Dot),56 ,1 ,0x30 }, + {1056 ,800 ,40 ,128 ,628 ,600 ,1 ,4 ,VCLK40 ,/* 60 Hz */ + (SyncPP | Charx8Dot),60 ,2 ,0x30 }, + {1040 ,800 ,56 ,120 ,666 ,600 ,37 ,6 ,VCLK50 ,/* 72 Hz */ + (SyncPP | Charx8Dot),72 ,3 ,0x30 }, + {1056 ,800 ,16 ,80 ,625 ,600 ,1 ,3 ,VCLK49_5 ,/* 75 Hz */ + (SyncPP | Charx8Dot),75 ,4 ,0x30 }, + {1048 ,800 ,32 ,64 ,631 ,600 ,1 ,3 ,VCLK56_25 ,/* 85 Hz */ + (SyncPP | Charx8Dot),84 ,5 ,0x30 }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +static const struct ast_vbios_enhtable res_1024x768[] = { + {1344 ,1024 ,24 ,136 ,806 ,768 ,3 ,6 ,VCLK65 ,/* 60 Hz */ + (SyncNN | Charx8Dot),60 ,1 ,0x31 }, + {1328 ,1024 ,24 ,136 ,806 ,768 ,3 ,6 ,VCLK75 ,/* 70 Hz */ + (SyncNN | Charx8Dot),70 ,2 ,0x31 }, + {1312 ,1024 ,16 ,96 ,800 ,768 ,1 ,3 ,VCLK78_75 ,/* 75 Hz */ + (SyncPP | Charx8Dot),75 ,3 ,0x31 }, + {1376 ,1024 ,48 ,96 ,808 ,768 ,1 ,3 ,VCLK94_5 ,/* 85 Hz */ + (SyncPP | Charx8Dot),84 ,4 ,0x31 }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +static const struct ast_vbios_enhtable res_1152x864[] = { + {1600 ,1152 ,64 ,128 ,900 ,864 ,1 ,3 ,VCLK108 ,/* 75 Hz */ + (SyncPP | Charx8Dot | NewModeInfo),75 ,1 ,0x3b }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +static const struct ast_vbios_enhtable res_1280x1024[] = { + {1688 ,1280 ,48 ,112 ,1066 ,1024 ,1 ,3 ,VCLK108 ,/* 60 Hz */ + (SyncPP | Charx8Dot),60 ,1 ,0x32 }, + {1688 ,1280 ,16 ,144 ,1066 ,1024 ,1 ,3 ,VCLK135 ,/* 75 Hz */ + (SyncPP | Charx8Dot),75 ,2 ,0x32 }, + {1728 ,1280 ,64 ,160 ,1072 ,1024 ,1 ,3 ,VCLK157_5 ,/* 85 Hz */ + (SyncPP | Charx8Dot),85 ,3 ,0x32 }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +static const struct ast_vbios_enhtable res_1600x1200[] = { + {2160 ,1600 ,64 ,192 ,1250 ,1200 ,1 ,3 ,VCLK162 ,/* 60 Hz */ + (SyncPP | Charx8Dot),60 ,1 ,0x33 }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +/* 16:9 */ + +static const struct ast_vbios_enhtable res_1360x768[] = { + {1792 ,1360 ,64 ,112 ,795 ,768 ,3 ,6 ,VCLK85_5 ,/* 60 Hz */ + (SyncPP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo),60 ,1 ,0x39 }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +static const struct ast_vbios_enhtable res_1600x900[] = { + {1760 ,1600 ,48 ,32 ,926 ,900 ,3 ,5 ,VCLK97_75 ,/* 60 Hz CVT RB */ + (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | + AST2500PreCatchCRT),60 ,1 ,0x3a }, + {2112 ,1600 ,88 ,168 ,934 ,900 ,3 ,5 ,VCLK118_25 ,/* 60 Hz CVT */ + (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo),60 ,2 ,0x3a }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +static const struct ast_vbios_enhtable res_1920x1080[] = { + {2200 ,1920 ,88 ,44 ,1125 ,1080 ,4 ,5 ,VCLK148_5 ,/* 60 Hz */ + (SyncPP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | + AST2500PreCatchCRT),60 ,1 ,0x38 }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +/* 16:10 */ + +static const struct ast_vbios_enhtable res_1280x800[] = { + {1440 ,1280 ,48 ,32 ,823 ,800 ,3 ,6 ,VCLK71 ,/* 60 Hz RB */ + (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | + AST2500PreCatchCRT),60 ,1 ,0x35 }, + {1680 ,1280 ,72 ,128 ,831 ,800 ,3 ,6 ,VCLK83_5 ,/* 60 Hz */ + (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo),60 ,2 ,0x35 }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +static const struct ast_vbios_enhtable res_1440x900[] = { + {1600 ,1440 ,48 ,32 ,926 ,900 ,3 ,6 ,VCLK88_75 ,/* 60 Hz RB */ + (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | + AST2500PreCatchCRT),60 ,1 ,0x36 }, + {1904 ,1440 ,80 ,152 ,934 ,900 ,3 ,6 ,VCLK106_5 ,/* 60 Hz */ + (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo),60 ,2 ,0x36 }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +static const struct ast_vbios_enhtable res_1680x1050[] = { + {1840 ,1680 ,48 ,32 ,1080 ,1050 ,3 ,6 ,VCLK119 ,/* 60 Hz RB */ + (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | + AST2500PreCatchCRT),60 ,1 ,0x37 }, + {2240 ,1680 ,104 ,176 ,1089 ,1050 ,3 ,6 ,VCLK146_25 ,/* 60 Hz */ + (SyncPN | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo),60 ,2 ,0x37 }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +static const struct ast_vbios_enhtable res_1920x1200[] = { + {2080 ,1920 ,48 ,32 ,1235 ,1200 ,3 ,6 ,VCLK154 ,/* 60 Hz RB*/ + (SyncNP | Charx8Dot | LineCompareOff | WideScreenMode | NewModeInfo | + AST2500PreCatchCRT),60 ,1 ,0x34 }, +AST_VBIOS_INVALID_MODE ,/* end */ +}; + +/* +* VBIOS mode tables +*/ + +static const struct ast_vbios_enhtable *res_table_wuxga[] = { + &res_1920x1200[0 ], +NULL , +}; + +static const struct ast_vbios_enhtable *res_table_fullhd[] = { + &res_1920x1080[0 ], +NULL , +}; + +static const struct ast_vbios_enhtable *res_table_wsxga_p[] = { + &res_1280x800[0 ], + &res_1360x768[0 ], + &res_1440x900[0 ], + &res_1600x900[0 ], + &res_1680x1050[0 ], +NULL , +}; + +static const struct ast_vbios_enhtable *res_table[] = { + &res_640x480[0 ], + &res_800x600[0 ], + &res_1024x768[0 ], + &res_1152x864[0 ], + &res_1280x1024[0 ], + &res_1600x1200[0 ], +NULL , +}; + +static const struct ast_vbios_enhtable * +__ast_vbios_find_mode_table (const struct ast_vbios_enhtable **vmode_tables, +unsigned int hdisplay, +unsigned int vdisplay) +{ +while (*vmode_tables) { +if ((*vmode_tables)->hde == hdisplay && (*vmode_tables)->vde == vdisplay) +return *vmode_tables; + ++vmode_tables; + } + +return NULL ; +} + +static const struct ast_vbios_enhtable *ast_vbios_find_mode_table (const struct ast_device *ast, +unsigned int hdisplay, +unsigned int vdisplay) +{ +const struct ast_vbios_enhtable *vmode_table =NULL ; + +if (ast->support_wuxga) + vmode_table =__ast_vbios_find_mode_table (res_table_wuxga, hdisplay, vdisplay); +if (!vmode_table && ast->support_fullhd) + vmode_table =__ast_vbios_find_mode_table (res_table_fullhd, hdisplay, vdisplay); +if (!vmode_table && ast->support_wsxga_p) + vmode_table =__ast_vbios_find_mode_table (res_table_wsxga_p, hdisplay, vdisplay); +if (!vmode_table) + vmode_table =__ast_vbios_find_mode_table (res_table, hdisplay, vdisplay); + +return vmode_table; +} + +const struct ast_vbios_enhtable *ast_vbios_find_mode (const struct ast_device *ast, +const struct drm_display_mode *mode) +{ +const struct ast_vbios_enhtable *best_vmode =NULL ; +const struct ast_vbios_enhtable *vmode_table; +const struct ast_vbios_enhtable *vmode; +u32 refresh_rate; + + vmode_table =ast_vbios_find_mode_table (ast, mode->hdisplay, mode->vdisplay); +if (!vmode_table) +return NULL ; + + refresh_rate =drm_mode_vrefresh (mode); + +for (vmode = vmode_table;ast_vbios_mode_is_valid (vmode); ++vmode) { +if (((mode->flags &DRM_MODE_FLAG_NVSYNC ) && (vmode->flags & PVSync)) || + ((mode->flags &DRM_MODE_FLAG_PVSYNC ) && (vmode->flags & NVSync)) || + ((mode->flags &DRM_MODE_FLAG_NHSYNC ) && (vmode->flags & PHSync)) || + ((mode->flags &DRM_MODE_FLAG_PHSYNC ) && (vmode->flags & NHSync))) { +continue ; + } +if (vmode->refresh_rate <= refresh_rate && + (!best_vmode || vmode->refresh_rate > best_vmode->refresh_rate)) + best_vmode = vmode; + } + +return best_vmode; +}drivers/gpu/drm/ast/ast_vbios.h new file +108
-0@@ -0,0 +1,108 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright (c) 2005 ASPEED Technology Inc. +* +* Permission to use, copy, modify, distribute, and sell this software and its +* documentation for any purpose is hereby granted without fee, provided that +* the above copyright notice appear in all copies and that both that +* copyright notice and this permission notice appear in supporting +* documentation, and that the name of the authors not be used in +* advertising or publicity pertaining to distribution of the software without +* specific, written prior permission. The authors makes no representations +* about the suitability of this software for any purpose. It is provided +* "as is" without express or implied warranty. +* +* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR +* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +* PERFORMANCE OF THIS SOFTWARE. +*/ +/* Ported from xf86-video-ast driver */ + +#ifndef AST_VBIOS_H +#define AST_VBIOS_H + +#include <linux/types.h> + +struct ast_device ; +struct drm_display_mode ; + +#define Charx8Dot 0x00000001 +#define HalfDCLK 0x00000002 +#define DoubleScanMode 0x00000004 +#define LineCompareOff 0x00000008 +#define HBorder 0x00000020 +#define VBorder 0x00000010 +#define WideScreenMode 0x00000100 +#define NewModeInfo 0x00000200 +#define NHSync 0x00000400 +#define PHSync 0x00000800 +#define NVSync 0x00001000 +#define PVSync 0x00002000 +#define SyncPP (PVSync | PHSync) +#define SyncPN (PVSync | NHSync) +#define SyncNP (NVSync | PHSync) +#define SyncNN (NVSync | NHSync) +#define AST2500PreCatchCRT 0x00004000 + +/* DCLK Index */ +#define VCLK25_175 0x00 +#define VCLK28_322 0x01 +#define VCLK31_5 0x02 +#define VCLK36 0x03 +#define VCLK40 0x04 +#define VCLK49_5 0x05 +#define VCLK50 0x06 +#define VCLK56_25 0x07 +#define VCLK65 0x08 +#define VCLK75 0x09 +#define VCLK78_75 0x0a +#define VCLK94_5 0x0b +#define VCLK108 0x0c +#define VCLK135 0x0d +#define VCLK157_5 0x0e +#define VCLK162 0x0f +/* #define VCLK193_25 0x10 */ +#define VCLK154 0x10 +#define VCLK83_5 0x11 +#define VCLK106_5 0x12 +#define VCLK146_25 0x13 +#define VCLK148_5 0x14 +#define VCLK71 0x15 +#define VCLK88_75 0x16 +#define VCLK119 0x17 +#define VCLK85_5 0x18 +#define VCLK97_75 0x19 +#define VCLK118_25 0x1a + +struct ast_vbios_enhtable { +u32 ht; +u32 hde; +u32 hfp; +u32 hsync; +u32 vt; +u32 vde; +u32 vfp; +u32 vsync; +u32 dclk_index; +u32 flags; +u32 refresh_rate; +u32 refresh_rate_index; +u32 mode_id; +}; + +#define AST_VBIOS_INVALID_MODE \ + {0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u} + +static inline bool ast_vbios_mode_is_valid (const struct ast_vbios_enhtable *vmode) +{ +return vmode->ht && vmode->vt && vmode->refresh_rate; +} + +const struct ast_vbios_enhtable *ast_vbios_find_mode (const struct ast_device *ast, +const struct drm_display_mode *mode); + +#endif
Thomas Zimmermann
maintainerPATCH v2 11/16 drm/ast: Validate DRM display modes against VBIOS modes
In reply to Thomas ZimmermannTest DRM display modes against the list of modes supported by the VBIOS. The helper will respect the supported-modes flags in struct ast_device. Hence only DRM display modes supported by the VBIOS will be reported; without the current duplication of this information.
--- drivers/gpu/drm/ast/ast_mode.c | 62 +++------------------------------- 1 file changed, 5 insertions(+), 57 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +5 -57
@@ -950,65 +950,13 @@ static enum drm_mode_status ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode *mode) { struct ast_device *ast = to_ast_device(crtc->dev); -enum drm_mode_status status; - -if (ast->support_wsxga_p) { -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->support_fullhd) { -if ((mode->hdisplay ==1920 ) && (mode->vdisplay ==1080 )) -return MODE_OK ; - -if ((mode->hdisplay ==1920 ) && (mode->vdisplay ==1200 )) { -if (ast->support_wuxga) -return MODE_OK ; -else -return MODE_NOMODE ; - } - } - } +const struct ast_vbios_enhtable *vmode; - status =MODE_NOMODE ; + vmode =ast_vbios_find_mode (ast, mode); +if (!vmode) +return 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 1152 : -if (mode->vdisplay ==864 ) - 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; +return MODE_OK ; }static void ast_crtc_helper_mode_set_nofb (struct drm_crtc *crtc)
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 12/16 drm/ast: Inline ast_get_vbios_mode_info()
In reply to Thomas ZimmermannThe helper ast_get_vbios_mode_info() retrieves hardware-specific format and display-mode information. Inline the function into its only caller.
While at it, also replace a use of struct drm_format_info.cpp with the correct DRM 4CC codes.
--- drivers/gpu/drm/ast/ast_mode.c | 112 ++++++++++++++++----------------- 1 file changed, 54 insertions(+), 58 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +54 -58
@@ -107,59 +107,6 @@ static void ast_crtc_set_gamma(struct ast_device *ast, } } -static bool ast_get_vbios_mode_info (struct ast_device *ast, -const struct drm_format_info *format, -const struct drm_display_mode *mode, -struct drm_display_mode *adjusted_mode, -struct ast_vbios_mode_info *vbios_mode) -{ -u32 hborder, vborder; - -switch (format->cpp[0 ] *8 ) { -case 8 : - vbios_mode->std_table = &vbios_stdtable[VGAModeIndex]; -break ; -case 16 : - vbios_mode->std_table = &vbios_stdtable[HiCModeIndex]; -break ; -case 24 : -case 32 : - vbios_mode->std_table = &vbios_stdtable[TrueCModeIndex]; -break ; -default : -return false; - } - - vbios_mode->enh_table =ast_vbios_find_mode (ast, mode); -if (!vbios_mode->enh_table) -return false; - - hborder = (vbios_mode->enh_table->flags & HBorder) ?8 :0 ; - vborder = (vbios_mode->enh_table->flags & VBorder) ?8 :0 ; - - adjusted_mode->crtc_hdisplay = vbios_mode->enh_table->hde; - adjusted_mode->crtc_htotal = vbios_mode->enh_table->ht; - adjusted_mode->crtc_hblank_start = vbios_mode->enh_table->hde + hborder; - adjusted_mode->crtc_hblank_end = vbios_mode->enh_table->ht - hborder; - adjusted_mode->crtc_hsync_start = vbios_mode->enh_table->hde + hborder + - vbios_mode->enh_table->hfp; - adjusted_mode->crtc_hsync_end = (vbios_mode->enh_table->hde + hborder + - vbios_mode->enh_table->hfp + - vbios_mode->enh_table->hsync); - - adjusted_mode->crtc_vdisplay = vbios_mode->enh_table->vde; - adjusted_mode->crtc_vtotal = vbios_mode->enh_table->vt; - adjusted_mode->crtc_vblank_start = vbios_mode->enh_table->vde + vborder; - adjusted_mode->crtc_vblank_end = vbios_mode->enh_table->vt - vborder; - adjusted_mode->crtc_vsync_start = vbios_mode->enh_table->vde + vborder + - vbios_mode->enh_table->vfp; - adjusted_mode->crtc_vsync_end = (vbios_mode->enh_table->vde + vborder + - vbios_mode->enh_table->vfp + - vbios_mode->enh_table->vsync); - -return true; -} -static void ast_set_vbios_color_reg (struct ast_device *ast,const struct drm_format_info *format,const struct ast_vbios_mode_info *vbios_mode)
@@ -990,13 +937,17 @@ static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *state) {struct drm_crtc_state *crtc_state =drm_atomic_get_new_crtc_state (state, crtc); +struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;struct drm_crtc_state *old_crtc_state =drm_atomic_get_old_crtc_state (state, crtc);struct ast_crtc_state *old_ast_crtc_state =to_ast_crtc_state (old_crtc_state);struct drm_device *dev = crtc->dev;struct ast_device *ast =to_ast_device (dev);struct ast_crtc_state *ast_state;const struct drm_format_info *format; -bool succ; +struct ast_vbios_mode_info *vbios_mode; +const struct ast_vbios_enhtable *vmode; +unsigned int hborder =0 ; +unsigned int vborder =0 ;int ret;if (!crtc_state->enable)
@@ -1028,11 +979,56 @@ static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc, } } - succ =ast_get_vbios_mode_info (ast, format, &crtc_state->mode, - &crtc_state->adjusted_mode, - &ast_state->vbios_mode_info); -if (!succ) + vbios_mode = &ast_state->vbios_mode_info; + +/* +* Set register tables. +* +* TODO: These tables mix all kinds of fields and should +* probably be resolved into various helper functions. +*/ +switch (format->format) { +case DRM_FORMAT_C8 : + vbios_mode->std_table = &vbios_stdtable[VGAModeIndex]; +break ; +case DRM_FORMAT_RGB565 : + vbios_mode->std_table = &vbios_stdtable[HiCModeIndex]; +break ; +case DRM_FORMAT_RGB888 : +case DRM_FORMAT_XRGB8888 : + vbios_mode->std_table = &vbios_stdtable[TrueCModeIndex]; +break ; +default : +return -EINVAL ; + } + +/* +* Find the VBIOS mode and adjust the DRM display mode accordingly. +*/ + + vmode =ast_vbios_find_mode (ast, &crtc_state->mode); +if (!vmode)return -EINVAL ; + ast_state->vbios_mode_info.enh_table = vmode; + +if (vmode->flags & HBorder) + hborder =8 ; +if (vmode->flags & VBorder) + vborder =8 ; + + adjusted_mode->crtc_hdisplay = vmode->hde; + adjusted_mode->crtc_hblank_start = vmode->hde + hborder; + adjusted_mode->crtc_hblank_end = vmode->ht - hborder; + adjusted_mode->crtc_hsync_start = vmode->hde + hborder + vmode->hfp; + adjusted_mode->crtc_hsync_end = vmode->hde + hborder + vmode->hfp + vmode->hsync; + adjusted_mode->crtc_htotal = vmode->ht; + + adjusted_mode->crtc_vdisplay = vmode->vde; + adjusted_mode->crtc_vblank_start = vmode->vde + vborder; + adjusted_mode->crtc_vblank_end = vmode->vt - vborder; + adjusted_mode->crtc_vsync_start = vmode->vde + vborder + vmode->vfp; + adjusted_mode->crtc_vsync_end = vmode->vde + vborder + vmode->vfp + vmode->vsync; + adjusted_mode->crtc_vtotal = vmode->vt;return 0 ; }
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 13/16 drm/ast: astdp: Rework display-mode setting
In reply to Thomas ZimmermannASTDP requires a mode index, depending on the resolution. Move the look-up code from ast_dp_set_mode() into a separate helper. Inline the rest of the function into its only caller. Rename the variable names and register constants to match the programming manual.
As before, the mode-index lookup still happens during the update's atomic commit. Right now, there's no way of doing it during the atomic check. The lookup requires the VBIOS mode, which is not available at the atomic check's invocation. At least warn now if the mode index could not be found.
--- drivers/gpu/drm/ast/ast_dp.c | 172 +++++++++++++++++++--------------- drivers/gpu/drm/ast/ast_reg.h | 18 +--- 2 files changed, 100 insertions(+), 90 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +96 -76
@@ -14,6 +14,82 @@#include "ast_drv.h" #include "ast_vbios.h" +static int ast_astdp_get_mode_index (const struct ast_vbios_enhtable *vmode) +{ +u8 refresh_rate_index; + +if (vmode->refresh_rate_index <1 || vmode->refresh_rate_index >255 ) +return -EINVAL ; + + refresh_rate_index = vmode->refresh_rate_index -1 ; + +switch (vmode->hde) { +case 320 : +if (vmode->vde ==240 ) +return ASTDP_320x240_60; +break ; +case 400 : +if (vmode->vde ==300 ) +return ASTDP_400x300_60; +break ; +case 512 : +if (vmode->vde ==384 ) +return ASTDP_512x384_60; +break ; +case 640 : +if (vmode->vde ==480 ) +return (u8)(ASTDP_640x480_60 + (u8 )refresh_rate_index); +break ; +case 800 : +if (vmode->vde ==600 ) +return (u8)(ASTDP_800x600_56 + (u8 )refresh_rate_index); +break ; +case 1024 : +if (vmode->vde ==768 ) +return (u8)(ASTDP_1024x768_60 + (u8 )refresh_rate_index); +break ; +case 1152 : +if (vmode->vde ==864 ) +return ASTDP_1152x864_75; +break ; +case 1280 : +if (vmode->vde ==800 ) +return (u8)(ASTDP_1280x800_60_RB - (u8 )refresh_rate_index); +if (vmode->vde ==1024 ) +return (u8)(ASTDP_1280x1024_60 + (u8 )refresh_rate_index); +break ; +case 1360 : +case 1366 : +if (vmode->vde ==768 ) +return ASTDP_1366x768_60; +break ; +case 1440 : +if (vmode->vde ==900 ) +return (u8)(ASTDP_1440x900_60_RB - (u8 )refresh_rate_index); +break ; +case 1600 : +if (vmode->vde ==900 ) +return (u8)(ASTDP_1600x900_60_RB - (u8 )refresh_rate_index); +if (vmode->vde ==1200 ) +return ASTDP_1600x1200_60; +break ; +case 1680 : +if (vmode->vde ==1050 ) +return (u8)(ASTDP_1680x1050_60_RB - (u8 )refresh_rate_index); +break ; +case 1920 : +if (vmode->vde ==1080 ) +return ASTDP_1920x1080_60; +if (vmode->vde ==1200 ) +return ASTDP_1920x1200_60; +break ; +default : +break ; + } + +return -EINVAL ; +} +static bool ast_astdp_is_connected (struct ast_device *ast) {if (!ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xDF ,AST_IO_VGACRDF_HPD ))
@@ -228,80 +304,6 @@ static void ast_dp_set_enable(struct ast_device *ast, bool enabled)drm_WARN_ON (dev, !__ast_dp_wait_enable (ast, enabled)); } -static void ast_dp_set_mode (struct drm_crtc *crtc,struct ast_vbios_mode_info *vbios_mode) -{ -struct ast_device *ast =to_ast_device (crtc->dev); - -u32 ulRefreshRateIndex; -u8 ModeIdx; - - ulRefreshRateIndex = vbios_mode->enh_table->refresh_rate_index -1 ; - -switch (crtc->mode.crtc_hdisplay) { -case 320 : - ModeIdx = ASTDP_320x240_60; -break ; -case 400 : - ModeIdx = ASTDP_400x300_60; -break ; -case 512 : - ModeIdx = ASTDP_512x384_60; -break ; -case 640 : - ModeIdx = (ASTDP_640x480_60 + (u8 ) ulRefreshRateIndex); -break ; -case 800 : - ModeIdx = (ASTDP_800x600_56 + (u8 ) ulRefreshRateIndex); -break ; -case 1024 : - ModeIdx = (ASTDP_1024x768_60 + (u8 ) ulRefreshRateIndex); -break ; -case 1152 : - ModeIdx = ASTDP_1152x864_75; -break ; -case 1280 : -if (crtc->mode.crtc_vdisplay ==800 ) - ModeIdx = (ASTDP_1280x800_60_RB - (u8 ) ulRefreshRateIndex); -else // 1024 - ModeIdx = (ASTDP_1280x1024_60 + (u8 ) ulRefreshRateIndex); -break ; -case 1360 : -case 1366 : - ModeIdx = ASTDP_1366x768_60; -break ; -case 1440 : - ModeIdx = (ASTDP_1440x900_60_RB - (u8 ) ulRefreshRateIndex); -break ; -case 1600 : -if (crtc->mode.crtc_vdisplay ==900 ) - ModeIdx = (ASTDP_1600x900_60_RB - (u8 ) ulRefreshRateIndex); -else //1200 - ModeIdx = ASTDP_1600x1200_60; -break ; -case 1680 : - ModeIdx = (ASTDP_1680x1050_60_RB - (u8 ) ulRefreshRateIndex); -break ; -case 1920 : -if (crtc->mode.crtc_vdisplay ==1080 ) - ModeIdx = ASTDP_1920x1080_60; -else //1200 - ModeIdx = ASTDP_1920x1200_60; -break ; -default : -return ; - } - -/* -* CRE0[7:0]: MISC0 ((0x00: 18-bpp) or (0x20: 24-bpp) -* CRE1[7:0]: MISC1 (default: 0x00) -* CRE2[7:0]: video format index (0x00 ~ 0x20 or 0x40 ~ 0x50) -*/ -ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xE0 ,ASTDP_AND_CLEAR_MASK , - ASTDP_MISC0_24bpp); -ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xE1 ,ASTDP_AND_CLEAR_MASK ,ASTDP_MISC1 ); -ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xE2 ,ASTDP_AND_CLEAR_MASK , ModeIdx); -} -static void ast_wait_for_vretrace (struct ast_device *ast) {unsigned long timeout = jiffies +HZ ;
@@ -324,11 +326,29 @@ static void ast_astdp_encoder_helper_atomic_mode_set(struct drm_encoder *encoderstruct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state) { - struct drm_crtc *crtc = crtc_state->crtc; + struct drm_device *dev = encoder->dev; +struct ast_device *ast =to_ast_device (dev);struct ast_crtc_state *ast_crtc_state =to_ast_crtc_state (crtc_state);struct ast_vbios_mode_info *vbios_mode_info = &ast_crtc_state->vbios_mode_info; +int mode_index; +u8 vgacre0, vgacre1, vgacre2; + + mode_index =ast_astdp_get_mode_index (vbios_mode_info->enh_table); +if (drm_WARN_ON (dev, mode_index <0 )) +return ; + +/* +* CRE0[7:0]: MISC0 ((0x00: 18-bpp) or (0x20: 24-bpp) +* CRE1[7:0]: MISC1 (default: 0x00) +* CRE2[7:0]: video format index (0x00 ~ 0x20 or 0x40 ~ 0x50) +*/ + vgacre0 =AST_IO_VGACRE0_24BPP ; + vgacre1 =0x00 ; + vgacre2 = mode_index &0xff ; -ast_dp_set_mode (crtc, vbios_mode_info); +ast_set_index_reg (ast,AST_IO_VGACRI ,0xe0 , vgacre0); +ast_set_index_reg (ast,AST_IO_VGACRI ,0xe1 , vgacre1); +ast_set_index_reg (ast,AST_IO_VGACRI ,0xe2 , vgacre2); } static void ast_astdp_encoder_helper_atomic_enable(struct drm_encoder *encoder,
drivers/gpu/drm/ast/ast_reg.h +4 -14
@@ -57,10 +57,14 @@#define AST_IO_VGACRD1_TX_ASTDP 0x0e#define AST_IO_VGACRD1_SUPPORTS_WUXGA BIT(0) +/* +* AST DisplayPort +*/ #define AST_IO_VGACRD7_EDID_VALID_FLAG BIT(0)#define AST_IO_VGACRDC_LINK_SUCCESS BIT(0)#define AST_IO_VGACRDF_HPD BIT(0)#define AST_IO_VGACRDF_DP_VIDEO_ENABLE BIT(4)/* mirrors AST_IO_VGACRE3_DP_VIDEO_ENABLE */ +#define AST_IO_VGACRE0_24BPP BIT(5)/* 18 bpp, if unset */ #define AST_IO_VGACRE3_DP_VIDEO_ENABLE BIT(0)#define AST_IO_VGACRE3_DP_PHY_SLEEP BIT(4)#define AST_IO_VGACRE5_EDID_READ_DONE BIT(0)
@@ -68,18 +72,4 @@#define AST_IO_VGAIR1_R (0x5A)#define AST_IO_VGAIR1_VREFRESH BIT(3) -/* -* AST DisplayPort -*/ - -/* -* ASTDP setmode registers: -* CRE0[7:0]: MISC0 ((0x00: 18-bpp) or (0x20: 24-bpp) -* CRE1[7:0]: MISC1 (default: 0x00) -* CRE2[7:0]: video format index (0x00 ~ 0x20 or 0x40 ~ 0x50) -*/ -#define ASTDP_MISC0_24bpp BIT(5) -#define ASTDP_MISC1 0 -#define ASTDP_AND_CLEAR_MASK 0x00 -#endif
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 14/16 drm/ast: astdp: Look up mode index from table
In reply to Thomas ZimmermannReplace the large switch statement with a look-up table when selecting the mode index. Makes the code easier to read. The table is sorted by resolutions; if run-time overhead from traversal becomes significant, binary search would be a possible optimization.
The mode index requires a refresh-rate index to be added or subtracted, which still requires a minimal switch.
--- drivers/gpu/drm/ast/ast_dp.c | 116 +++++++++++++++++------------------ 1 file changed, 55 insertions(+), 61 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +55 -61
@@ -14,80 +14,74 @@#include "ast_drv.h" #include "ast_vbios.h" +struct ast_astdp_mode_index_table_entry { +unsigned int hdisplay; +unsigned int vdisplay; +unsigned int mode_index; +}; + +/* FIXME: Do refresh rate and flags actually matter? */ +static const struct ast_astdp_mode_index_table_entry ast_astdp_mode_index_table[] = { + {320 ,240 , ASTDP_320x240_60 }, + {400 ,300 , ASTDP_400x300_60 }, + {512 ,384 , ASTDP_512x384_60 }, + {640 ,480 , ASTDP_640x480_60 }, + {800 ,600 , ASTDP_800x600_56 }, + {1024 ,768 , ASTDP_1024x768_60 }, + {1152 ,864 , ASTDP_1152x864_75 }, + {1280 ,800 , ASTDP_1280x800_60_RB }, + {1280 ,1024 , ASTDP_1280x1024_60 }, + {1360 ,768 , ASTDP_1366x768_60 },// same as 1366x786 + {1366 ,768 , ASTDP_1366x768_60 }, + {1440 ,900 , ASTDP_1440x900_60_RB }, + {1600 ,900 , ASTDP_1600x900_60_RB }, + {1600 ,1200 , ASTDP_1600x1200_60 }, + {1680 ,1050 , ASTDP_1680x1050_60_RB }, + {1920 ,1080 , ASTDP_1920x1080_60 }, + {1920 ,1200 , ASTDP_1920x1200_60 }, + {0 } +}; + +static int __ast_astdp_get_mode_index (unsigned int hdisplay,unsigned int vdisplay) +{ +const struct ast_astdp_mode_index_table_entry *entry = ast_astdp_mode_index_table; + +while (entry->hdisplay && entry->vdisplay) { +if (entry->hdisplay == hdisplay && entry->vdisplay == vdisplay) +return entry->mode_index; + ++entry; + } + +return -EINVAL ; +} +static int ast_astdp_get_mode_index (const struct ast_vbios_enhtable *vmode) { +int mode_index;u8 refresh_rate_index; + mode_index =__ast_astdp_get_mode_index (vmode->hde, vmode->vde); +if (mode_index <0 ) +return mode_index; +if (vmode->refresh_rate_index <1 || vmode->refresh_rate_index >255 )return -EINVAL ; - refresh_rate_index = vmode->refresh_rate_index -1 ; -switch (vmode->hde) { -case 320 : -if (vmode->vde ==240 ) -return ASTDP_320x240_60; -break ; -case 400 : -if (vmode->vde ==300 ) -return ASTDP_400x300_60; -break ; -case 512 : -if (vmode->vde ==384 ) -return ASTDP_512x384_60; -break ; -case 640 : -if (vmode->vde ==480 ) -return (u8)(ASTDP_640x480_60 + (u8 )refresh_rate_index); -break ; -case 800 : -if (vmode->vde ==600 ) -return (u8)(ASTDP_800x600_56 + (u8 )refresh_rate_index); -break ; -case 1024 : -if (vmode->vde ==768 ) -return (u8)(ASTDP_1024x768_60 + (u8 )refresh_rate_index); -break ; -case 1152 : -if (vmode->vde ==864 ) -return ASTDP_1152x864_75; -break ; -case 1280 : -if (vmode->vde ==800 ) -return (u8)(ASTDP_1280x800_60_RB - (u8 )refresh_rate_index); -if (vmode->vde ==1024 ) -return (u8)(ASTDP_1280x1024_60 + (u8 )refresh_rate_index); -break ; -case 1360 : -case 1366 : -if (vmode->vde ==768 ) -return ASTDP_1366x768_60; -break ; -case 1440 : -if (vmode->vde ==900 ) -return (u8)(ASTDP_1440x900_60_RB - (u8 )refresh_rate_index); -break ; -case 1600 : -if (vmode->vde ==900 ) -return (u8)(ASTDP_1600x900_60_RB - (u8 )refresh_rate_index); -if (vmode->vde ==1200 ) -return ASTDP_1600x1200_60; -break ; -case 1680 : -if (vmode->vde ==1050 ) -return (u8)(ASTDP_1680x1050_60_RB - (u8 )refresh_rate_index); -break ; -case 1920 : -if (vmode->vde ==1080 ) -return ASTDP_1920x1080_60; -if (vmode->vde ==1200 ) -return ASTDP_1920x1200_60; +/* FIXME: Why are we doing this? */ +switch (mode_index) { +case ASTDP_1280x800_60_RB: +case ASTDP_1440x900_60_RB: +case ASTDP_1600x900_60_RB: +case ASTDP_1680x1050_60_RB: + mode_index = (u8)(mode_index - (u8 )refresh_rate_index);break ;default : + mode_index = (u8)(mode_index + (u8 )refresh_rate_index);break ; } -return -EINVAL ; +return mode_index; }static bool ast_astdp_is_connected (struct ast_device *ast)
Signature · 1 line
2.48.1
Jocelyn Falempe
reviewerRe: [PATCH v2 14/16] drm/ast: astdp: Look up mode index from table
Quoted 8 lines · Thomas Zimmermann
Replace the large switch statement with a look-up table when selecting the mode index. Makes the code easier to read. The table is sorted by resolutions; if run-time overhead from traversal becomes significant, binary search would be a possible optimization.
The mode index requires a refresh-rate index to be added or subtracted, which still requires a minimal switch.
I think there is a problem in the mode_index/refresh_index calculation, see below:
Quoted 126 lines
Signed-off-by Thomas Zimmermann <[email protected]>Suggested-by Jocelyn Falempe <[email protected]>--- drivers/gpu/drm/ast/ast_dp.c | 116 +++++++++++++++++------------------ 1 file changed, 55 insertions(+), 61 deletions(-)drivers/gpu/drm/ast/ast_dp.c +46
-57@@ -14,80 +14,74 @@#include "ast_drv.h" #include "ast_vbios.h" +struct ast_astdp_mode_index_table_entry { +unsigned int hdisplay; +unsigned int vdisplay; +unsigned int mode_index; +}; + +/* FIXME: Do refresh rate and flags actually matter? */ +static const struct ast_astdp_mode_index_table_entry ast_astdp_mode_index_table[] = { + {320 ,240 , ASTDP_320x240_60 }, + {400 ,300 , ASTDP_400x300_60 }, + {512 ,384 , ASTDP_512x384_60 }, + {640 ,480 , ASTDP_640x480_60 }, + {800 ,600 , ASTDP_800x600_56 }, + {1024 ,768 , ASTDP_1024x768_60 }, + {1152 ,864 , ASTDP_1152x864_75 }, + {1280 ,800 , ASTDP_1280x800_60_RB }, + {1280 ,1024 , ASTDP_1280x1024_60 }, + {1360 ,768 , ASTDP_1366x768_60 },// same as 1366x786 + {1366 ,768 , ASTDP_1366x768_60 }, + {1440 ,900 , ASTDP_1440x900_60_RB }, + {1600 ,900 , ASTDP_1600x900_60_RB }, + {1600 ,1200 , ASTDP_1600x1200_60 }, + {1680 ,1050 , ASTDP_1680x1050_60_RB }, + {1920 ,1080 , ASTDP_1920x1080_60 }, + {1920 ,1200 , ASTDP_1920x1200_60 }, + {0 } +}; + +static int __ast_astdp_get_mode_index (unsigned int hdisplay,unsigned int vdisplay) +{ +const struct ast_astdp_mode_index_table_entry *entry = ast_astdp_mode_index_table; + +while (entry->hdisplay && entry->vdisplay) { +if (entry->hdisplay == hdisplay && entry->vdisplay == vdisplay) +return entry->mode_index; + ++entry; + } + +return -EINVAL ; +} +static int ast_astdp_get_mode_index (const struct ast_vbios_enhtable *vmode) { +int mode_index;u8 refresh_rate_index; + mode_index =__ast_astdp_get_mode_index (vmode->hde, vmode->vde); +if (mode_index <0 ) +return mode_index; +if (vmode->refresh_rate_index <1 || vmode->refresh_rate_index >255 )return -EINVAL ; - refresh_rate_index = vmode->refresh_rate_index -1 ; -switch (vmode->hde) { -case 320 : -if (vmode->vde ==240 ) -return ASTDP_320x240_60; -break ; -case 400 : -if (vmode->vde ==300 ) -return ASTDP_400x300_60; -break ; -case 512 : -if (vmode->vde ==384 ) -return ASTDP_512x384_60; -break ; -case 640 : -if (vmode->vde ==480 ) -return (u8)(ASTDP_640x480_60 + (u8 )refresh_rate_index); -break ; -case 800 : -if (vmode->vde ==600 ) -return (u8)(ASTDP_800x600_56 + (u8 )refresh_rate_index); -break ; -case 1024 : -if (vmode->vde ==768 ) -return (u8)(ASTDP_1024x768_60 + (u8 )refresh_rate_index); -break ; -case 1152 : -if (vmode->vde ==864 ) -return ASTDP_1152x864_75; -break ; -case 1280 : -if (vmode->vde ==800 ) -return (u8)(ASTDP_1280x800_60_RB - (u8 )refresh_rate_index); -if (vmode->vde ==1024 ) -return (u8)(ASTDP_1280x1024_60 + (u8 )refresh_rate_index); -break ; -case 1360 : -case 1366 : -if (vmode->vde ==768 ) -return ASTDP_1366x768_60; -break ; -case 1440 : -if (vmode->vde ==900 ) -return (u8)(ASTDP_1440x900_60_RB - (u8 )refresh_rate_index); -break ; -case 1600 : -if (vmode->vde ==900 ) -return (u8)(ASTDP_1600x900_60_RB - (u8 )refresh_rate_index); -if (vmode->vde ==1200 ) -break ; -case 1680 : -if (vmode->vde ==1050 ) -return (u8)(ASTDP_1680x1050_60_RB - (u8 )refresh_rate_index); -break ; -case 1920 : -if (vmode->vde ==1080 ) -return ASTDP_1920x1080_60;
drivers/gpu/drm/ast/ast_dp.c line 79
Quoted 10 lines
drivers/gpu/drm/ast/ast_dp.c +7
-2-if (vmode->vde ==1200 ) -return ASTDP_1920x1200_60; +/* FIXME: Why are we doing this? */ +switch (mode_index) { +case ASTDP_1280x800_60_RB: +case ASTDP_1440x900_60_RB: +case ASTDP_1600x900_60_RB: +case ASTDP_1680x1050_60_RB: + mode_index = (u8)(mode_index - (u8 )refresh_rate_index);break ;
I think you should add this to do the same as before:
case ASTDP_640x480_60: case ASTDP_800x600_56: case ASTDP_1024x768_60: case ASTDP_1280x1024_60: mode_index = (u8)(mode_index + (u8)refresh_rate_index); break; default: break;
Quoted 10 lines
drivers/gpu/drm/ast/ast_dp.c +2
-1default : + mode_index = (u8)(mode_index + (u8 )refresh_rate_index);break ; } -return -EINVAL ; +return mode_index; }static bool ast_astdp_is_connected (struct ast_device *ast)
Thomas Zimmermann
maintainerRe: [PATCH v2 14/16] drm/ast: astdp: Look up mode index from table
Hi
Am 29.01.25 um 12:27 schrieb Jocelyn Falempe:
Quoted 150 lines · Thomas Zimmermann
Quoted 8 lines
Replace the large switch statement with a look-up table when selecting the mode index. Makes the code easier to read. The table is sorted by resolutions; if run-time overhead from traversal becomes significant, binary search would be a possible optimization.
The mode index requires a refresh-rate index to be added or subtracted, which still requires a minimal switch.
I think there is a problem in the mode_index/refresh_index calculation, see below:
Quoted 130 lines
Signed-off-by Thomas Zimmermann <[email protected]>Suggested-by Jocelyn Falempe <[email protected]>---
drivers/gpu/drm/ast/ast_dp.c| 116 +++++++++++++++++------------------1 file changed, 55 insertions(+), 61 deletions(-)drivers/gpu/drm/ast/ast_dp.c +44
-0@@ -14,80 +14,74 @@ #include "ast_drv.h" #include "ast_vbios.h" +struct ast_astdp_mode_index_table_entry { + unsigned int hdisplay; + unsigned int vdisplay; + unsigned int mode_index; +}; + +/* FIXME: Do refresh rate and flags actually matter? */ +static const struct ast_astdp_mode_index_table_entry ast_astdp_mode_index_table[] = { + { 320, 240, ASTDP_320x240_60 }, + { 400, 300, ASTDP_400x300_60 }, + { 512, 384, ASTDP_512x384_60 }, + { 640, 480, ASTDP_640x480_60 }, + { 800, 600, ASTDP_800x600_56 }, + { 1024, 768, ASTDP_1024x768_60 }, + { 1152, 864, ASTDP_1152x864_75 }, + { 1280, 800, ASTDP_1280x800_60_RB }, + { 1280, 1024, ASTDP_1280x1024_60 }, + { 1360, 768, ASTDP_1366x768_60 }, // same as 1366x786 + { 1366, 768, ASTDP_1366x768_60 }, + { 1440, 900, ASTDP_1440x900_60_RB }, + { 1600, 900, ASTDP_1600x900_60_RB }, + { 1600, 1200, ASTDP_1600x1200_60 }, + { 1680, 1050, ASTDP_1680x1050_60_RB }, + { 1920, 1080, ASTDP_1920x1080_60 }, + { 1920, 1200, ASTDP_1920x1200_60 }, + { 0 } +}; + +static int __ast_astdp_get_mode_index (unsigned int hdisplay,unsigned int vdisplay) +{ + const struct ast_astdp_mode_index_table_entry *entry = ast_astdp_mode_index_table; + + while (entry->hdisplay && entry->vdisplay) { + if (entry->hdisplay == hdisplay && entry->vdisplay == vdisplay) + return entry->mode_index; + ++entry; + } + + return -EINVAL; +} + static int ast_astdp_get_mode_index(const struct ast_vbios_enhtable *vmode) { + int mode_index; u8 refresh_rate_index; + mode_index = __ast_astdp_get_mode_index(vmode->hde, vmode->vde); + if (mode_index < 0) + return mode_index; +if (
vmode->refresh_rate_index< 1 ||vmode->refresh_rate_indexQuoted 1 line
255)
return
-EINVAL;
-
refresh_rate_index=vmode->refresh_rate_index- 1;
- switch (vmode->hde) {
- case 320:
- if (vmode->vde== 240)
- returnASTDP_320x240_60;
- break;
- case 400:
- if (vmode->vde== 300)
- returnASTDP_400x300_60;
- break;
- case 512:
- if (vmode->vde== 384)
- returnASTDP_512x384_60;
- break;
- case 640:
- if (vmode->vde== 480)
- return (u8)(ASTDP_640x480_60 + (u8)refresh_rate_index); - break;
- case 800:
- if (vmode->vde== 600)
- return (u8)(ASTDP_800x600_56 + (u8)refresh_rate_index); - break;
- case 1024:
- if (vmode->vde== 768)
- return (u8)(ASTDP_1024x768_60 + (u8)refresh_rate_index); - break;
- case 1152:
- if (vmode->vde== 864)
- returnASTDP_1152x864_75;
- break;
- case 1280:
- if (vmode->vde== 800)
- return (u8)(ASTDP_1280x800_60_RB - (u8)refresh_rate_index); - if (vmode->vde== 1024)
- return (u8)(ASTDP_1280x1024_60 + (u8)refresh_rate_index); - break;
- case 1360:
- case 1366:
- if (vmode->vde== 768)
- returnASTDP_1366x768_60;
- break;
- case 1440:
- if (vmode->vde== 900)
- return (u8)(ASTDP_1440x900_60_RB - (u8)refresh_rate_index); - break;
- case 1600:
- if (vmode->vde== 900)
- return (u8)(ASTDP_1600x900_60_RB - (u8)refresh_rate_index); - if (vmode->vde== 1200)- break;
- case 1680:
- if (vmode->vde== 1050)
- return (u8)(ASTDP_1680x1050_60_RB -
(u8)refresh_rate_index);
- break;
- case 1920:
- if (vmode->vde== 1080)
- returnASTDP_1920x1080_60;
- if (vmode->vde== 1200)
- returnASTDP_1920x1200_60;Quoted 8 lines
+ /* FIXME: Why are we doing this? */
+ switch (mode_index) {
+ caseASTDP_1280x800_60_RB:
+ caseASTDP_1440x900_60_RB:
+ caseASTDP_1600x900_60_RB:
+ caseASTDP_1680x1050_60_RB:
+mode_index= (u8)(mode_index - (u8)refresh_rate_index); break;
Quoted 1 line
I think you should add this to do the same as before:
It's intentional. The refresh-rate index stored in vmode->refresh_rate_index is at least one. The function then subtracts 1 to compute refresh_rate_index, so we have 0 by default. And that's what we always used for cases that did not explicitly add refresh_rate_index before. I guess I should add this to the commit message's second paragraph.
Apart from that, I honestly don't understand the purpose of this computation.
Best regards
Thomas
Quoted 19 lines
case
ASTDP_640x480_60:
caseASTDP_800x600_56:
caseASTDP_1024x768_60:
caseASTDP_1280x1024_60:
mode_index= (u8)(mode_index + (u8)refresh_rate_index); break;
default:
break;Quoted 8 lines
default:
+mode_index= (u8)(mode_index + (u8)refresh_rate_index); break;
}
- return-EINVAL;
+ returnmode_index;
}
static boolast_astdp_is_connected(struct ast_device *ast)
Signature · 7 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
Jocelyn Falempe
reviewerRe: [PATCH v2 14/16] drm/ast: astdp: Look up mode index from table
Quoted 154 lines · Thomas Zimmermann
Hi
Am 29.01.25 um 12:27 schrieb Jocelyn Falempe:
Quoted 150 lines · Thomas Zimmermann
Quoted 8 lines
Replace the large switch statement with a look-up table when selecting the mode index. Makes the code easier to read. The table is sorted by resolutions; if run-time overhead from traversal becomes significant, binary search would be a possible optimization.
The mode index requires a refresh-rate index to be added or subtracted, which still requires a minimal switch.
I think there is a problem in the mode_index/refresh_index calculation, see below:
Quoted 138 lines
Signed-off-by Thomas Zimmermann <[email protected]>Suggested-by Jocelyn Falempe <[email protected]>---
drivers/gpu/drm/ast/ast_dp.c| 116 +++++++++++++++++------------------1 file changed, 55 insertions(+), 61 deletions(-)drivers/gpu/drm/ast/ast_dp.c +44
-0@@ -14,80 +14,74 @@ #include "ast_drv.h" #include "ast_vbios.h" +struct ast_astdp_mode_index_table_entry { + unsigned int hdisplay; + unsigned int vdisplay; + unsigned int mode_index; +}; + +/* FIXME: Do refresh rate and flags actually matter? */ +static const struct ast_astdp_mode_index_table_entry ast_astdp_mode_index_table[] = { + { 320, 240, ASTDP_320x240_60 }, + { 400, 300, ASTDP_400x300_60 }, + { 512, 384, ASTDP_512x384_60 }, + { 640, 480, ASTDP_640x480_60 }, + { 800, 600, ASTDP_800x600_56 }, + { 1024, 768, ASTDP_1024x768_60 }, + { 1152, 864, ASTDP_1152x864_75 }, + { 1280, 800, ASTDP_1280x800_60_RB }, + { 1280, 1024, ASTDP_1280x1024_60 }, + { 1360, 768, ASTDP_1366x768_60 }, // same as 1366x786 + { 1366, 768, ASTDP_1366x768_60 }, + { 1440, 900, ASTDP_1440x900_60_RB }, + { 1600, 900, ASTDP_1600x900_60_RB }, + { 1600, 1200, ASTDP_1600x1200_60 }, + { 1680, 1050, ASTDP_1680x1050_60_RB }, + { 1920, 1080, ASTDP_1920x1080_60 }, + { 1920, 1200, ASTDP_1920x1200_60 }, + { 0 } +}; + +static int __ast_astdp_get_mode_index (unsigned int hdisplay,unsigned int vdisplay) +{ + const struct ast_astdp_mode_index_table_entry *entry = ast_astdp_mode_index_table; + + while (entry->hdisplay && entry->vdisplay) { + if (entry->hdisplay == hdisplay && entry->vdisplay == vdisplay) + return entry->mode_index; + ++entry; + } + + return -EINVAL; +} + static int ast_astdp_get_mode_index(const struct ast_vbios_enhtable *vmode) { + int mode_index; u8 refresh_rate_index; + mode_index = __ast_astdp_get_mode_index(vmode->hde, vmode->vde); + if (mode_index < 0) + return mode_index; +if (
vmode->refresh_rate_index< 1 ||vmode->refresh_rate_indexQuoted 1 line
255)
return
-EINVAL;
-
refresh_rate_index=vmode->refresh_rate_index- 1;
- switch (vmode->hde) {
- case 320:
- if (vmode->vde== 240)
- returnASTDP_320x240_60;
- break;
- case 400:
- if (vmode->vde== 300)
- returnASTDP_400x300_60;
- break;
- case 512:
- if (vmode->vde== 384)
- returnASTDP_512x384_60;
- break;
- case 640:
- if (vmode->vde== 480)
- return (u8)(ASTDP_640x480_60 + (u8)refresh_rate_index); - break;
- case 800:
- if (vmode->vde== 600)
- return (u8)(ASTDP_800x600_56 + (u8)refresh_rate_index); - break;
- case 1024:
- if (vmode->vde== 768)
- return (u8)(ASTDP_1024x768_60 + (u8)refresh_rate_index); - break;
- case 1152:
- if (vmode->vde== 864)
- returnASTDP_1152x864_75;
- break;
- case 1280:
- if (vmode->vde== 800)
- return (u8)(ASTDP_1280x800_60_RB - (u8)refresh_rate_index); - if (vmode->vde== 1024)
- return (u8)(ASTDP_1280x1024_60 + (u8)refresh_rate_index); - break;
- case 1360:
- case 1366:
- if (vmode->vde== 768)
- returnASTDP_1366x768_60;
- break;
- case 1440:
- if (vmode->vde== 900)
- return (u8)(ASTDP_1440x900_60_RB - (u8)refresh_rate_index); - break;
- case 1600:
- if (vmode->vde== 900)
- return (u8)(ASTDP_1600x900_60_RB - (u8)refresh_rate_index); - if (vmode->vde== 1200)- break;
- case 1680:
- if (vmode->vde== 1050)
- return (u8)(ASTDP_1680x1050_60_RB - (u8)refresh_rate_index);
- break;
- case 1920:
- if (vmode->vde== 1080)
- returnASTDP_1920x1080_60;
- if (vmode->vde== 1200)
- returnASTDP_1920x1200_60;
+ /* FIXME: Why are we doing this? */
+ switch (mode_index) {
+ caseASTDP_1280x800_60_RB:
+ caseASTDP_1440x900_60_RB:
+ caseASTDP_1600x900_60_RB:
+ caseASTDP_1680x1050_60_RB:
+mode_index= (u8)(mode_index - (u8)refresh_rate_index); break;
Quoted 7 lines
Quoted 1 line
I think you should add this to do the same as before:
It's intentional. The refresh-rate index stored in vmode-
Quoted 1 line
refresh_rate_indexis at least one. The function then subtracts 1 tocompute
refresh_rate_index, so we have 0 by default. And that's what we always used for cases that did not explicitly addrefresh_rate_indexbefore. I guess I should add this to the commit message's second paragraph.Apart from that, I honestly don't understand the purpose of this computation.
Yes, I have no clue either. Thanks for the clarification.> Best regards
Quoted 22 lines
Thomas
Quoted 19 lines
case
ASTDP_640x480_60:
caseASTDP_800x600_56:
caseASTDP_1024x768_60:
caseASTDP_1280x1024_60:
mode_index= (u8)(mode_index + (u8)refresh_rate_index); break;
default:
break;Quoted 8 lines
default:
+mode_index= (u8)(mode_index + (u8)refresh_rate_index); break;
}
- return-EINVAL;
+ returnmode_index;
}
static boolast_astdp_is_connected(struct ast_device *ast)
Re: [PATCH v2 14/16] drm/ast: astdp: Look up mode index from table
Quoted 11 lines · Jocelyn Falempe
Quoted 10 lines · Thomas Zimmermann
Hi
Am 29.01.25 um 12:27 schrieb Jocelyn Falempe:
Quoted 6 lines · Thomas Zimmermann
Quoted 5 lines
Replace the large switch statement with a look-up table when selecting the mode index. Makes the code easier to read. The table is sorted by resolutions; if run-time overhead from traversal becomes significant, binary search would be a possible optimization.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
The mode index requires a refresh-rate index to be added or subtracted, which still requires a minimal switch.
I think there is a problem in the mode_index/refresh_index calculation, see below:
Sorry, I though I already reviewed it. With the added explanations, it looks good to me.
Quoted 175 lines
Quoted 145 lines
Quoted 145 lines
Quoted 145 lines
Signed-off-by Thomas Zimmermann <[email protected]>Suggested-by Jocelyn Falempe <[email protected]>---
drivers/gpu/drm/ast/ast_dp.c| 116 ++++++++++++++++
+------------------1 file changed, 55 insertions(+), 61 deletions(-)drivers/gpu/drm/ast/ast_dp.c +44
-0@@ -14,80 +14,74 @@ #include "ast_drv.h" #include "ast_vbios.h" +struct ast_astdp_mode_index_table_entry { + unsigned int hdisplay; + unsigned int vdisplay; + unsigned int mode_index; +}; + +/* FIXME: Do refresh rate and flags actually matter? */ +static const struct ast_astdp_mode_index_table_entry ast_astdp_mode_index_table[] = { + { 320, 240, ASTDP_320x240_60 }, + { 400, 300, ASTDP_400x300_60 }, + { 512, 384, ASTDP_512x384_60 }, + { 640, 480, ASTDP_640x480_60 }, + { 800, 600, ASTDP_800x600_56 }, + { 1024, 768, ASTDP_1024x768_60 }, + { 1152, 864, ASTDP_1152x864_75 }, + { 1280, 800, ASTDP_1280x800_60_RB }, + { 1280, 1024, ASTDP_1280x1024_60 }, + { 1360, 768, ASTDP_1366x768_60 }, // same as 1366x786 + { 1366, 768, ASTDP_1366x768_60 }, + { 1440, 900, ASTDP_1440x900_60_RB }, + { 1600, 900, ASTDP_1600x900_60_RB }, + { 1600, 1200, ASTDP_1600x1200_60 }, + { 1680, 1050, ASTDP_1680x1050_60_RB }, + { 1920, 1080, ASTDP_1920x1080_60 }, + { 1920, 1200, ASTDP_1920x1200_60 }, + { 0 } +}; + +static int __ast_astdp_get_mode_index (unsigned int hdisplay,unsigned int vdisplay) +{ + const struct ast_astdp_mode_index_table_entry *entry = ast_astdp_mode_index_table; + + while (entry->hdisplay && entry->vdisplay) { + if (entry->hdisplay == hdisplay && entry->vdisplay == vdisplay) + return entry->mode_index; + ++entry; + } + + return -EINVAL; +} + static int ast_astdp_get_mode_index(const struct ast_vbios_enhtable *vmode) { + int mode_index; u8 refresh_rate_index; + mode_index = __ast_astdp_get_mode_index(vmode->hde, vmode->vde); + if (mode_index < 0) + return mode_index; +if (
vmode->refresh_rate_index< 1 ||vmode->refresh_rate_indexQuoted 1 line
255)
return
-EINVAL;
-
refresh_rate_index=vmode->refresh_rate_index- 1;
- switch (vmode->hde) {
- case 320:
- if (vmode->vde== 240)
- returnASTDP_320x240_60;
- break;
- case 400:
- if (vmode->vde== 300)
- returnASTDP_400x300_60;
- break;
- case 512:
- if (vmode->vde== 384)
- returnASTDP_512x384_60;
- break;
- case 640:
- if (vmode->vde== 480)
- return (u8)(ASTDP_640x480_60 + (u8)refresh_rate_index); - break;
- case 800:
- if (vmode->vde== 600)
- return (u8)(ASTDP_800x600_56 + (u8)refresh_rate_index); - break;
- case 1024:
- if (vmode->vde== 768)
- return (u8)(ASTDP_1024x768_60 + (u8)refresh_rate_index); - break;
- case 1152:
- if (vmode->vde== 864)
- returnASTDP_1152x864_75;
- break;
- case 1280:
- if (vmode->vde== 800)
- return (u8)(ASTDP_1280x800_60_RB - (u8)refresh_rate_index);
- if (vmode->vde== 1024)
- return (u8)(ASTDP_1280x1024_60 + (u8)refresh_rate_index); - break;
- case 1360:
- case 1366:
- if (vmode->vde== 768)
- returnASTDP_1366x768_60;
- break;
- case 1440:
- if (vmode->vde== 900)
- return (u8)(ASTDP_1440x900_60_RB - (u8)refresh_rate_index);
- break;
- case 1600:
- if (vmode->vde== 900)
- return (u8)(ASTDP_1600x900_60_RB - (u8)refresh_rate_index);
- if (vmode->vde== 1200)- break;
- case 1680:
- if (vmode->vde== 1050)
- return (u8)(ASTDP_1680x1050_60_RB - (u8)refresh_rate_index);
- break;
- case 1920:
- if (vmode->vde== 1080)
- returnASTDP_1920x1080_60;
- if (vmode->vde== 1200)
- returnASTDP_1920x1200_60;
+ /* FIXME: Why are we doing this? */
+ switch (mode_index) {
+ caseASTDP_1280x800_60_RB:
+ caseASTDP_1440x900_60_RB:
+ caseASTDP_1600x900_60_RB:
+ caseASTDP_1680x1050_60_RB:
+mode_index= (u8)(mode_index - (u8)refresh_rate_index); break;Quoted 5 lines
Quoted 1 line
I think you should add this to do the same as before:
It's intentional. The refresh-rate index stored in vmode- >refresh_rate_index is at least one. The function then subtracts 1 to compute
refresh_rate_index, so we have 0 by default. And that's what we always used for cases that did not explicitly addrefresh_rate_indexbefore. I guess I should add this to the commit message's second paragraph.Apart from that, I honestly don't understand the purpose of this computation.
Yes, I have no clue either. Thanks for the clarification.> Best regards
Quoted 22 lines
Thomas
Quoted 19 lines
case
ASTDP_640x480_60:
caseASTDP_800x600_56:
caseASTDP_1024x768_60:
caseASTDP_1280x1024_60:
mode_index= (u8)(mode_index + (u8)refresh_rate_index); break;
default:
break;Quoted 8 lines
default:
+mode_index= (u8)(mode_index + (u8)refresh_rate_index); break;
}
- return-EINVAL;
+ returnmode_index;
}
static boolast_astdp_is_connected(struct ast_device *ast)
Thomas Zimmermann
maintainerPATCH v2 15/16 drm/ast: Remove struct ast_vbios_mode_info
In reply to Thomas ZimmermannThe type struct ast_vbios_mode_info used to store information about the color format and display mode. It has outlived its purpose. Inline its fields into struct ast_crtc_state and replace all instances.
--- drivers/gpu/drm/ast/ast_dp.c | 3 +- drivers/gpu/drm/ast/ast_drv.h | 8 ++--- drivers/gpu/drm/ast/ast_mode.c | 65 +++++++++++++++------------------- 3 files changed, 32 insertions(+), 44 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +1 -2
@@ -323,11 +323,10 @@ static void ast_astdp_encoder_helper_atomic_mode_set(struct drm_encoder *encoderstruct drm_device *dev = encoder->dev;struct ast_device *ast =to_ast_device (dev);struct ast_crtc_state *ast_crtc_state =to_ast_crtc_state (crtc_state); -struct ast_vbios_mode_info *vbios_mode_info = &ast_crtc_state->vbios_mode_info;int mode_index;u8 vgacre0, vgacre1, vgacre2; - mode_index =ast_astdp_get_mode_index (vbios_mode_info->enh_table); + mode_index =ast_astdp_get_mode_index (ast_crtc_state->vmode);if (drm_WARN_ON (dev, mode_index <0 ))return ;
drivers/gpu/drm/ast/ast_drv.h +2 -6
@@ -358,18 +358,14 @@ struct ast_vbios_dclk_info {u8 param3; }; -struct ast_vbios_mode_info { -const struct ast_vbios_stdtable *std_table; -const struct ast_vbios_enhtable *enh_table; -}; -struct ast_crtc_state {struct drm_crtc_state base;/* Last known format of primary plane */ const struct drm_format_info *format; -struct ast_vbios_mode_info vbios_mode_info; +const struct ast_vbios_stdtable *std_table; +const struct ast_vbios_enhtable *vmode; };#define to_ast_crtc_state (state) container_of(state, struct ast_crtc_state, base)
drivers/gpu/drm/ast/ast_mode.c +29 -36
193 lines not on this page · raw message
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v2 16/16 drm/ast: Only look up VBIOS mode on full modesets
In reply to Thomas ZimmermannOnly look up the VBIOS mode during atomic_check if the display mode changes. For page flips, the previous settings still apply. Avoids the runtime overhead of looking up the VBIOS mode on each page flip.
--- drivers/gpu/drm/ast/ast_mode.c | 52 ++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 25 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +27 -25
@@ -996,32 +996,34 @@ static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc, }/* -* Find the VBIOS mode and adjust the DRM display mode accordingly. +* Find the VBIOS mode and adjust the DRM display mode accordingly +* if a full modeset is required. Otherwise keep the existing values. */ - - vmode =ast_vbios_find_mode (ast, &crtc_state->mode); -if (!vmode) -return -EINVAL ; - ast_state->vmode = vmode; - -if (vmode->flags & HBorder) - hborder =8 ; -if (vmode->flags & VBorder) - vborder =8 ; - - adjusted_mode->crtc_hdisplay = vmode->hde; - adjusted_mode->crtc_hblank_start = vmode->hde + hborder; - adjusted_mode->crtc_hblank_end = vmode->ht - hborder; - adjusted_mode->crtc_hsync_start = vmode->hde + hborder + vmode->hfp; - adjusted_mode->crtc_hsync_end = vmode->hde + hborder + vmode->hfp + vmode->hsync; - adjusted_mode->crtc_htotal = vmode->ht; - - adjusted_mode->crtc_vdisplay = vmode->vde; - adjusted_mode->crtc_vblank_start = vmode->vde + vborder; - adjusted_mode->crtc_vblank_end = vmode->vt - vborder; - adjusted_mode->crtc_vsync_start = vmode->vde + vborder + vmode->vfp; - adjusted_mode->crtc_vsync_end = vmode->vde + vborder + vmode->vfp + vmode->vsync; - adjusted_mode->crtc_vtotal = vmode->vt; +if (drm_atomic_crtc_needs_modeset (crtc_state)) { + vmode =ast_vbios_find_mode (ast, &crtc_state->mode); +if (!vmode) +return -EINVAL ; + ast_state->vmode = vmode; + +if (vmode->flags & HBorder) + hborder =8 ; +if (vmode->flags & VBorder) + vborder =8 ; + + adjusted_mode->crtc_hdisplay = vmode->hde; + adjusted_mode->crtc_hblank_start = vmode->hde + hborder; + adjusted_mode->crtc_hblank_end = vmode->ht - hborder; + adjusted_mode->crtc_hsync_start = vmode->hde + hborder + vmode->hfp; + adjusted_mode->crtc_hsync_end = vmode->hde + hborder + vmode->hfp + vmode->hsync; + adjusted_mode->crtc_htotal = vmode->ht; + + adjusted_mode->crtc_vdisplay = vmode->vde; + adjusted_mode->crtc_vblank_start = vmode->vde + vborder; + adjusted_mode->crtc_vblank_end = vmode->vt - vborder; + adjusted_mode->crtc_vsync_start = vmode->vde + vborder + vmode->vfp; + adjusted_mode->crtc_vsync_end = vmode->vde + vborder + vmode->vfp + vmode->vsync; + adjusted_mode->crtc_vtotal = vmode->vt; + }return 0 ; }
Signature · 1 line
2.48.1