drm/ast: Clean up display-mode detection and validation
Subsystems (3)
Thomas Zimmermann
maintainerv3 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.
v3:
- clarify commit messages on astdp changes (Jocelyn) 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
prerequisite-patch-id: 0aa359f6144c4015c140c8a6750be19099c676fb
prerequisite-patch-id: c67e5d886a47b7d0266d81100837557fda34cb24
prerequisite-patch-id: cbc453ee02fae02af22fbfdce56ab732c7a88c36
prerequisite-patch-id: 3f99a9f751f2659d0fbb07e88abc3904dca961e1
prerequisite-patch-id: 838dd5f8f6a89bda83ee22ec918adf1be2fe70e5
prerequisite-patch-id: 68d3a49734dc01e652902fe59dea1a6f79ae212f
prerequisite-patch-id: 4043e36e87c74b8fc89ce9b38fd875c6c58aa591
prerequisite-patch-id: cb8fb20896035f39d61086ac0c432b15b09130c9
prerequisite-patch-id: ca36d50bffbd3adaf5bcd6419eeca3331ac1e554
prerequisite-patch-id: 0fa92030ec82bc84b12c9614c4d043c908283a02
prerequisite-patch-id: c20dacec2a612e566e0f4be254d7ced143466d60
prerequisite-patch-id: 8264e077bed425b3945e85169ed13620c54cddc7
prerequisite-patch-id: c3705fe8a5b349da66fdaa66bd33f0b78dd154ca
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerPATCH v3 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 v3 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 v3 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 v3 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
Thomas Zimmermann
maintainerPATCH v3 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 v3 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
Thomas Zimmermann
maintainerPATCH v3 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 v3 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 v3 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 v3 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
Thomas Zimmermann
maintainerPATCH v3 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 v3 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 v3 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 v3 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. In the original code, some of the indices did not contain this computation. Those cases would have been equivalent to adding 0, so they are now all subsumed in the switch's default branch.
v3:
- explain the semantics of the new switch statement (Jocelyn)
--- 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
Thomas Zimmermann
maintainerPATCH v3 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 v3 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