Skip to contentSkip to conversation

drm/ast: Remove model-specific branches from mode-setting pipeline

PATCH In review Thomas Zimmermann 2 participants 11 messages Oct 7, 2025 – Oct 9, 2025

Subsystems (3)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover drm/ast: Remove model-specific branches from mode-setting pipeline

Store additional information in struct ast_device and struct ast_device_quirk to describe each model. Replace the per-Gen branching in the mode-setting code with the new data. Makes mode setting more flexible and puts more of the per-Gen information in a single source file per model.

Tested on AST2600 hardware.

Next to address will be the remaining per-Gen cases in the POST and in the DP501 code. After that there will be a single specific source file per hardware generation.

Thomas Zimmermann (5):
drm/ast: Store DRAM clock table in struct ast_device drm/ast: Support device quirks
drm/ast: Store CRTC memory request threshold in device quirks drm/ast: Store precatch settings in struct ast_device_quirks drm/ast: Store HSync adjustment in device quirks

 drivers/gpu/drm/ast/ast_2000.c |  9 ++++++-
 drivers/gpu/drm/ast/ast_2100.c |  9 ++++++-
 drivers/gpu/drm/ast/ast_2200.c |  9 ++++++-
 drivers/gpu/drm/ast/ast_2300.c |  9 ++++++-
 drivers/gpu/drm/ast/ast_2400.c |  9 ++++++-
 drivers/gpu/drm/ast/ast_2500.c | 10 +++++++-
 drivers/gpu/drm/ast/ast_2600.c | 11 +++++++-
 drivers/gpu/drm/ast/ast_drv.c  |  4 ++-
 drivers/gpu/drm/ast/ast_drv.h  | 27 +++++++++++++++++++-
 drivers/gpu/drm/ast/ast_mode.c | 46 +++++++++++-----------------------
 10 files changed, 103 insertions(+), 40 deletions(-)
Signature · 1 line
2.51.0
author maintainer
#1 lore raw

PATCH 1/5 drm/ast: Store DRAM clock table in struct ast_device

Init the new field dclk_table in struct ast_device to the per-gen table of DRAM clock parameters. Use the field during modesetting.

The table is static, so a setup is only required once. Removes the call to IS_AST_GEN() from the atomic commit's code path.

---
 drivers/gpu/drm/ast/ast_2000.c | 2 ++
 drivers/gpu/drm/ast/ast_2100.c | 2 ++
 drivers/gpu/drm/ast/ast_2200.c | 2 ++
 drivers/gpu/drm/ast/ast_2300.c | 2 ++
 drivers/gpu/drm/ast/ast_2400.c | 2 ++
 drivers/gpu/drm/ast/ast_2500.c | 2 ++
 drivers/gpu/drm/ast/ast_2600.c | 2 ++
 drivers/gpu/drm/ast/ast_drv.h  | 2 ++
 drivers/gpu/drm/ast/ast_mode.c | 7 +------
 9 files changed, 17 insertions(+), 6 deletions(-)
drivers/gpu/drm/ast/ast_2000.c +2 -0
index 03b0dcea43d1..74a041e99061 100644
@@ -230,6 +230,8 @@ struct drm_device *ast_2000_device_create(struct pci_dev *pdev,
 
 	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2000_dclk_table;
+
 	ast_2000_detect_tx_chip(ast, need_post);
 
 	if (need_post) {
drivers/gpu/drm/ast/ast_2100.c +2 -0
index 540972daec52..eb3336c84833 100644
@@ -451,6 +451,8 @@ struct drm_device *ast_2100_device_create(struct pci_dev *pdev,
 
 	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2000_dclk_table;
+
 	ast_2000_detect_tx_chip(ast, need_post);
 
 	if (need_post) {
drivers/gpu/drm/ast/ast_2200.c +2 -0
index 4795966dc2a7..391034d5f425 100644
@@ -62,6 +62,8 @@ struct drm_device *ast_2200_device_create(struct pci_dev *pdev,
 
 	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2000_dclk_table;
+
 	ast_2000_detect_tx_chip(ast, need_post);
 
 	if (need_post) {
drivers/gpu/drm/ast/ast_2300.c +2 -0
index d1d63e58f3d6..3c9e1960b90c 100644
@@ -1426,6 +1426,8 @@ struct drm_device *ast_2300_device_create(struct pci_dev *pdev,
 
 	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2000_dclk_table;
+
 	ast_2300_detect_tx_chip(ast);
 
 	if (need_post) {
drivers/gpu/drm/ast/ast_2400.c +2 -0
index 596338ea22f4..be866d1cd06a 100644
@@ -63,6 +63,8 @@ struct drm_device *ast_2400_device_create(struct pci_dev *pdev,
 
 	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2000_dclk_table;
+
 	ast_2300_detect_tx_chip(ast);
 
 	if (need_post) {
drivers/gpu/drm/ast/ast_2500.c +2 -0
index 2c56db644f06..086c74682a55 100644
@@ -637,6 +637,8 @@ struct drm_device *ast_2500_device_create(struct pci_dev *pdev,
 
 	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2500_dclk_table;
+
 	ast_2300_detect_tx_chip(ast);
 
 	if (need_post) {
drivers/gpu/drm/ast/ast_2600.c +2 -0
index 30490c473797..1f709486f491 100644
@@ -78,6 +78,8 @@ struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
 
 	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2500_dclk_table;
+
 	ast_2300_detect_tx_chip(ast);
 
 	switch (ast->tx_chip) {
drivers/gpu/drm/ast/ast_drv.h +2 -0
index 35c476c85b9a..b2b30a0e4ffb 100644
@@ -174,6 +174,8 @@ struct ast_device {
 	enum ast_config_mode config_mode;
 	enum ast_chip chip;
 
+	const struct ast_vbios_dclk_info *dclk_table;
+
 	void __iomem	*vram;
 	unsigned long	vram_base;
 	unsigned long	vram_size;
drivers/gpu/drm/ast/ast_mode.c +1 -6
index 6b9d510c509d..a9ffda1b1dea 100644
@@ -370,12 +370,7 @@ static void ast_set_dclk_reg(struct ast_device *ast,
 			     struct drm_display_mode *mode,
 			     const struct ast_vbios_enhtable *vmode)
 {
-	const struct ast_vbios_dclk_info *clk_info;
-
-	if (IS_AST_GEN6(ast) || IS_AST_GEN7(ast))
-		clk_info = &ast_2500_dclk_table[vmode->dclk_index];
-	else
-		clk_info = &ast_2000_dclk_table[vmode->dclk_index];
+	const struct ast_vbios_dclk_info *clk_info = &ast->dclk_table[vmode->dclk_index];
 
 	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xc0, 0x00, clk_info->param1);
 	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xc1, 0x00, clk_info->param2);
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] drm/ast: Store DRAM clock table in struct ast_device

Quoted 5 lines · Thomas Zimmermann

Init the new field dclk_table in struct ast_device to the per-gen table of DRAM clock parameters. Use the field during modesetting.

The table is static, so a setup is only required once. Removes the call to IS_AST_GEN() from the atomic commit's code path.

Thanks, it looks good to me.

Quoted 136 lines
---
  drivers/gpu/drm/ast/ast_2000.c | 2 ++
  drivers/gpu/drm/ast/ast_2100.c | 2 ++
  drivers/gpu/drm/ast/ast_2200.c | 2 ++
  drivers/gpu/drm/ast/ast_2300.c | 2 ++
  drivers/gpu/drm/ast/ast_2400.c | 2 ++
  drivers/gpu/drm/ast/ast_2500.c | 2 ++
  drivers/gpu/drm/ast/ast_2600.c | 2 ++
  drivers/gpu/drm/ast/ast_drv.h  | 2 ++
  drivers/gpu/drm/ast/ast_mode.c | 7 +------
  9 files changed, 17 insertions(+), 6 deletions(-)
drivers/gpu/drm/ast/ast_2000.c +2 -0
index 03b0dcea43d1..74a041e99061 100644
@@ -230,6 +230,8 @@ struct drm_device *ast_2000_device_create(struct pci_dev *pdev,
 
  	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2000_dclk_table;
+
  	ast_2000_detect_tx_chip(ast, need_post);
 
  	if (need_post) {
drivers/gpu/drm/ast/ast_2100.c +2 -0
index 540972daec52..eb3336c84833 100644
@@ -451,6 +451,8 @@ struct drm_device *ast_2100_device_create(struct pci_dev *pdev,
 
  	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2000_dclk_table;
+
  	ast_2000_detect_tx_chip(ast, need_post);
 
  	if (need_post) {
drivers/gpu/drm/ast/ast_2200.c +2 -0
index 4795966dc2a7..391034d5f425 100644
@@ -62,6 +62,8 @@ struct drm_device *ast_2200_device_create(struct pci_dev *pdev,
 
  	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2000_dclk_table;
+
  	ast_2000_detect_tx_chip(ast, need_post);
 
  	if (need_post) {
drivers/gpu/drm/ast/ast_2300.c +2 -0
index d1d63e58f3d6..3c9e1960b90c 100644
@@ -1426,6 +1426,8 @@ struct drm_device *ast_2300_device_create(struct pci_dev *pdev,
 
  	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2000_dclk_table;
+
  	ast_2300_detect_tx_chip(ast);
 
  	if (need_post) {
drivers/gpu/drm/ast/ast_2400.c +2 -0
index 596338ea22f4..be866d1cd06a 100644
@@ -63,6 +63,8 @@ struct drm_device *ast_2400_device_create(struct pci_dev *pdev,
 
  	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2000_dclk_table;
+
  	ast_2300_detect_tx_chip(ast);
 
  	if (need_post) {
drivers/gpu/drm/ast/ast_2500.c +2 -0
index 2c56db644f06..086c74682a55 100644
@@ -637,6 +637,8 @@ struct drm_device *ast_2500_device_create(struct pci_dev *pdev,
 
  	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2500_dclk_table;
+
  	ast_2300_detect_tx_chip(ast);
 
  	if (need_post) {
drivers/gpu/drm/ast/ast_2600.c +2 -0
index 30490c473797..1f709486f491 100644
@@ -78,6 +78,8 @@ struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
 
  	ast_device_init(ast, chip, config_mode, regs, ioregs);
 
+	ast->dclk_table = ast_2500_dclk_table;
+
  	ast_2300_detect_tx_chip(ast);
 
  	switch (ast->tx_chip) {
drivers/gpu/drm/ast/ast_drv.h +2 -0
index 35c476c85b9a..b2b30a0e4ffb 100644
@@ -174,6 +174,8 @@ struct ast_device {
  	enum ast_config_mode config_mode;
  	enum ast_chip chip;
 
+	const struct ast_vbios_dclk_info *dclk_table;
+
  	void __iomem	*vram;
  	unsigned long	vram_base;
  	unsigned long	vram_size;
drivers/gpu/drm/ast/ast_mode.c +1 -6
index 6b9d510c509d..a9ffda1b1dea 100644
@@ -370,12 +370,7 @@ static void ast_set_dclk_reg(struct ast_device *ast,
  			     struct drm_display_mode *mode,
  			     const struct ast_vbios_enhtable *vmode)
  {
-	const struct ast_vbios_dclk_info *clk_info;
-
-	if (IS_AST_GEN6(ast) || IS_AST_GEN7(ast))
-		clk_info = &ast_2500_dclk_table[vmode->dclk_index];
-	else
-		clk_info = &ast_2000_dclk_table[vmode->dclk_index];
+	const struct ast_vbios_dclk_info *clk_info = &ast->dclk_table[vmode->dclk_index];
 
  	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xc0, 0x00, clk_info->param1);
  	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xc1, 0x00, clk_info->param2);
author maintainer
#3 lore raw

PATCH 2/5 drm/ast: Support device quirks

In reply to Thomas Zimmermann

Define struct ast_device_quirks and add an instance for each hardware generation. The type will provide information about per-gen constants and oddities.

---
 drivers/gpu/drm/ast/ast_2000.c | 5 ++++-
 drivers/gpu/drm/ast/ast_2100.c | 5 ++++-
 drivers/gpu/drm/ast/ast_2200.c | 5 ++++-
 drivers/gpu/drm/ast/ast_2300.c | 5 ++++-
 drivers/gpu/drm/ast/ast_2400.c | 5 ++++-
 drivers/gpu/drm/ast/ast_2500.c | 5 ++++-
 drivers/gpu/drm/ast/ast_2600.c | 5 ++++-
 drivers/gpu/drm/ast/ast_drv.c  | 4 +++-
 drivers/gpu/drm/ast/ast_drv.h  | 8 +++++++-
 9 files changed, 38 insertions(+), 9 deletions(-)
drivers/gpu/drm/ast/ast_2000.c +4 -1
index 74a041e99061..ae4d7a2a0ec8 100644
@@ -211,6 +211,9 @@ void ast_2000_detect_tx_chip(struct ast_device *ast, bool need_post)
 	__ast_device_set_tx_chip(ast, tx_chip);
 }
 
+static const struct ast_device_quirks ast_2000_device_quirks = {
+};
+
 struct drm_device *ast_2000_device_create(struct pci_dev *pdev,
 					  const struct drm_driver *drv,
 					  enum ast_chip chip,
@@ -228,7 +231,7 @@ struct drm_device *ast_2000_device_create(struct pci_dev *pdev,
 		return ERR_CAST(ast);
 	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2000_device_quirks);
 
 	ast->dclk_table = ast_2000_dclk_table;
 
drivers/gpu/drm/ast/ast_2100.c +4 -1
index eb3336c84833..01e064e67cf7 100644
@@ -432,6 +432,9 @@ static void ast_2100_detect_widescreen(struct ast_device *ast)
 		ast->support_wuxga = true;
 }
 
+static const struct ast_device_quirks ast_2100_device_quirks = {
+};
+
 struct drm_device *ast_2100_device_create(struct pci_dev *pdev,
 					  const struct drm_driver *drv,
 					  enum ast_chip chip,
@@ -449,7 +452,7 @@ struct drm_device *ast_2100_device_create(struct pci_dev *pdev,
 		return ERR_CAST(ast);
 	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2100_device_quirks);
 
 	ast->dclk_table = ast_2000_dclk_table;
 
drivers/gpu/drm/ast/ast_2200.c +4 -1
index 391034d5f425..46b6fc6cf7eb 100644
@@ -43,6 +43,9 @@ static void ast_2200_detect_widescreen(struct ast_device *ast)
 		ast->support_wuxga = true;
 }
 
+static const struct ast_device_quirks ast_2200_device_quirks = {
+};
+
 struct drm_device *ast_2200_device_create(struct pci_dev *pdev,
 					  const struct drm_driver *drv,
 					  enum ast_chip chip,
@@ -60,7 +63,7 @@ struct drm_device *ast_2200_device_create(struct pci_dev *pdev,
 		return ERR_CAST(ast);
 	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2200_device_quirks);
 
 	ast->dclk_table = ast_2000_dclk_table;
 
drivers/gpu/drm/ast/ast_2300.c +4 -1
index 3c9e1960b90c..b76a80d6aea6 100644
@@ -1407,6 +1407,9 @@ static void ast_2300_detect_widescreen(struct ast_device *ast)
 		ast->support_wuxga = true;
 }
 
+static const struct ast_device_quirks ast_2300_device_quirks = {
+};
+
 struct drm_device *ast_2300_device_create(struct pci_dev *pdev,
 					  const struct drm_driver *drv,
 					  enum ast_chip chip,
@@ -1424,7 +1427,7 @@ struct drm_device *ast_2300_device_create(struct pci_dev *pdev,
 		return ERR_CAST(ast);
 	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2300_device_quirks);
 
 	ast->dclk_table = ast_2000_dclk_table;
 
drivers/gpu/drm/ast/ast_2400.c +4 -1
index be866d1cd06a..2b41ff69ab0b 100644
@@ -44,6 +44,9 @@ static void ast_2400_detect_widescreen(struct ast_device *ast)
 		ast->support_wuxga = true;
 }
 
+static const struct ast_device_quirks ast_2400_device_quirks = {
+};
+
 struct drm_device *ast_2400_device_create(struct pci_dev *pdev,
 					  const struct drm_driver *drv,
 					  enum ast_chip chip,
@@ -61,7 +64,7 @@ struct drm_device *ast_2400_device_create(struct pci_dev *pdev,
 		return ERR_CAST(ast);
 	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2400_device_quirks);
 
 	ast->dclk_table = ast_2000_dclk_table;
 
drivers/gpu/drm/ast/ast_2500.c +4 -1
index 086c74682a55..6d305a8ccc51 100644
@@ -618,6 +618,9 @@ static void ast_2500_detect_widescreen(struct ast_device *ast)
 		ast->support_wuxga = true;
 }
 
+static const struct ast_device_quirks ast_2500_device_quirks = {
+};
+
 struct drm_device *ast_2500_device_create(struct pci_dev *pdev,
 					  const struct drm_driver *drv,
 					  enum ast_chip chip,
@@ -635,7 +638,7 @@ struct drm_device *ast_2500_device_create(struct pci_dev *pdev,
 		return ERR_CAST(ast);
 	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2500_device_quirks);
 
 	ast->dclk_table = ast_2500_dclk_table;
 
drivers/gpu/drm/ast/ast_2600.c +4 -1
index 1f709486f491..df3b429e8174 100644
@@ -59,6 +59,9 @@ static void ast_2600_detect_widescreen(struct ast_device *ast)
 		ast->support_wuxga = true;
 }
 
+static const struct ast_device_quirks ast_2600_device_quirks = {
+};
+
 struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
 					  const struct drm_driver *drv,
 					  enum ast_chip chip,
@@ -76,7 +79,7 @@ struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
 		return ERR_CAST(ast);
 	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2600_device_quirks);
 
 	ast->dclk_table = ast_2500_dclk_table;
 
drivers/gpu/drm/ast/ast_drv.c +3 -1
index a89735c6a462..b9a9b050b546 100644
@@ -51,8 +51,10 @@ void ast_device_init(struct ast_device *ast,
 		     enum ast_chip chip,
 		     enum ast_config_mode config_mode,
 		     void __iomem *regs,
-		     void __iomem *ioregs)
+		     void __iomem *ioregs,
+		     const struct ast_device_quirks *quirks)
 {
+	ast->quirks = quirks;
 	ast->chip = chip;
 	ast->config_mode = config_mode;
 	ast->regs = regs;
drivers/gpu/drm/ast/ast_drv.h +7 -1
index b2b30a0e4ffb..2a2c28693dc6 100644
@@ -164,9 +164,14 @@ to_ast_connector(struct drm_connector *connector)
  * Device
  */
 
+struct ast_device_quirks {
+};
+
 struct ast_device {
 	struct drm_device base;
 
+	const struct ast_device_quirks *quirks;
+
 	void __iomem *regs;
 	void __iomem *ioregs;
 	void __iomem *dp501_fw_buf;
@@ -414,7 +419,8 @@ void ast_device_init(struct ast_device *ast,
 		     enum ast_chip chip,
 		     enum ast_config_mode config_mode,
 		     void __iomem *regs,
-		     void __iomem *ioregs);
+		     void __iomem *ioregs,
+		     const struct ast_device_quirks *quirks);
 void __ast_device_set_tx_chip(struct ast_device *ast, enum ast_tx_chip tx_chip);
 
 /* ast_2000.c */
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] drm/ast: Support device quirks

Quoted 3 lines · Thomas Zimmermann

Define struct ast_device_quirks and add an instance for each hardware generation. The type will provide information about per-gen constants and oddities.

Thanks, it looks good to me.

Quoted 219 lines
---
  drivers/gpu/drm/ast/ast_2000.c | 5 ++++-
  drivers/gpu/drm/ast/ast_2100.c | 5 ++++-
  drivers/gpu/drm/ast/ast_2200.c | 5 ++++-
  drivers/gpu/drm/ast/ast_2300.c | 5 ++++-
  drivers/gpu/drm/ast/ast_2400.c | 5 ++++-
  drivers/gpu/drm/ast/ast_2500.c | 5 ++++-
  drivers/gpu/drm/ast/ast_2600.c | 5 ++++-
  drivers/gpu/drm/ast/ast_drv.c  | 4 +++-
  drivers/gpu/drm/ast/ast_drv.h  | 8 +++++++-
  9 files changed, 38 insertions(+), 9 deletions(-)
drivers/gpu/drm/ast/ast_2000.c +4 -1
index 74a041e99061..ae4d7a2a0ec8 100644
@@ -211,6 +211,9 @@ void ast_2000_detect_tx_chip(struct ast_device *ast, bool need_post)
  	__ast_device_set_tx_chip(ast, tx_chip);
  }
 
+static const struct ast_device_quirks ast_2000_device_quirks = {
+};
+
  struct drm_device *ast_2000_device_create(struct pci_dev *pdev,
  					  const struct drm_driver *drv,
  					  enum ast_chip chip,
@@ -228,7 +231,7 @@ struct drm_device *ast_2000_device_create(struct pci_dev *pdev,
  		return ERR_CAST(ast);
  	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2000_device_quirks);
 
  	ast->dclk_table = ast_2000_dclk_table;
 
drivers/gpu/drm/ast/ast_2100.c +4 -1
index eb3336c84833..01e064e67cf7 100644
@@ -432,6 +432,9 @@ static void ast_2100_detect_widescreen(struct ast_device *ast)
  		ast->support_wuxga = true;
  }
 
+static const struct ast_device_quirks ast_2100_device_quirks = {
+};
+
  struct drm_device *ast_2100_device_create(struct pci_dev *pdev,
  					  const struct drm_driver *drv,
  					  enum ast_chip chip,
@@ -449,7 +452,7 @@ struct drm_device *ast_2100_device_create(struct pci_dev *pdev,
  		return ERR_CAST(ast);
  	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2100_device_quirks);
 
  	ast->dclk_table = ast_2000_dclk_table;
 
drivers/gpu/drm/ast/ast_2200.c +4 -1
index 391034d5f425..46b6fc6cf7eb 100644
@@ -43,6 +43,9 @@ static void ast_2200_detect_widescreen(struct ast_device *ast)
  		ast->support_wuxga = true;
  }
 
+static const struct ast_device_quirks ast_2200_device_quirks = {
+};
+
  struct drm_device *ast_2200_device_create(struct pci_dev *pdev,
  					  const struct drm_driver *drv,
  					  enum ast_chip chip,
@@ -60,7 +63,7 @@ struct drm_device *ast_2200_device_create(struct pci_dev *pdev,
  		return ERR_CAST(ast);
  	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2200_device_quirks);
 
  	ast->dclk_table = ast_2000_dclk_table;
 
drivers/gpu/drm/ast/ast_2300.c +4 -1
index 3c9e1960b90c..b76a80d6aea6 100644
@@ -1407,6 +1407,9 @@ static void ast_2300_detect_widescreen(struct ast_device *ast)
  		ast->support_wuxga = true;
  }
 
+static const struct ast_device_quirks ast_2300_device_quirks = {
+};
+
  struct drm_device *ast_2300_device_create(struct pci_dev *pdev,
  					  const struct drm_driver *drv,
  					  enum ast_chip chip,
@@ -1424,7 +1427,7 @@ struct drm_device *ast_2300_device_create(struct pci_dev *pdev,
  		return ERR_CAST(ast);
  	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2300_device_quirks);
 
  	ast->dclk_table = ast_2000_dclk_table;
 
drivers/gpu/drm/ast/ast_2400.c +4 -1
index be866d1cd06a..2b41ff69ab0b 100644
@@ -44,6 +44,9 @@ static void ast_2400_detect_widescreen(struct ast_device *ast)
  		ast->support_wuxga = true;
  }
 
+static const struct ast_device_quirks ast_2400_device_quirks = {
+};
+
  struct drm_device *ast_2400_device_create(struct pci_dev *pdev,
  					  const struct drm_driver *drv,
  					  enum ast_chip chip,
@@ -61,7 +64,7 @@ struct drm_device *ast_2400_device_create(struct pci_dev *pdev,
  		return ERR_CAST(ast);
  	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2400_device_quirks);
 
  	ast->dclk_table = ast_2000_dclk_table;
 
drivers/gpu/drm/ast/ast_2500.c +4 -1
index 086c74682a55..6d305a8ccc51 100644
@@ -618,6 +618,9 @@ static void ast_2500_detect_widescreen(struct ast_device *ast)
  		ast->support_wuxga = true;
  }
 
+static const struct ast_device_quirks ast_2500_device_quirks = {
+};
+
  struct drm_device *ast_2500_device_create(struct pci_dev *pdev,
  					  const struct drm_driver *drv,
  					  enum ast_chip chip,
@@ -635,7 +638,7 @@ struct drm_device *ast_2500_device_create(struct pci_dev *pdev,
  		return ERR_CAST(ast);
  	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2500_device_quirks);
 
  	ast->dclk_table = ast_2500_dclk_table;
 
drivers/gpu/drm/ast/ast_2600.c +4 -1
index 1f709486f491..df3b429e8174 100644
@@ -59,6 +59,9 @@ static void ast_2600_detect_widescreen(struct ast_device *ast)
  		ast->support_wuxga = true;
  }
 
+static const struct ast_device_quirks ast_2600_device_quirks = {
+};
+
  struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
  					  const struct drm_driver *drv,
  					  enum ast_chip chip,
@@ -76,7 +79,7 @@ struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
  		return ERR_CAST(ast);
  	dev = &ast->base;
 
-	ast_device_init(ast, chip, config_mode, regs, ioregs);
+	ast_device_init(ast, chip, config_mode, regs, ioregs, &ast_2600_device_quirks);
 
  	ast->dclk_table = ast_2500_dclk_table;
 
drivers/gpu/drm/ast/ast_drv.c +3 -1
index a89735c6a462..b9a9b050b546 100644
@@ -51,8 +51,10 @@ void ast_device_init(struct ast_device *ast,
  		     enum ast_chip chip,
  		     enum ast_config_mode config_mode,
  		     void __iomem *regs,
-		     void __iomem *ioregs)
+		     void __iomem *ioregs,
+		     const struct ast_device_quirks *quirks)
  {
+	ast->quirks = quirks;
  	ast->chip = chip;
  	ast->config_mode = config_mode;
  	ast->regs = regs;
drivers/gpu/drm/ast/ast_drv.h +7 -1
index b2b30a0e4ffb..2a2c28693dc6 100644
@@ -164,9 +164,14 @@ to_ast_connector(struct drm_connector *connector)
   * Device
   */
 
+struct ast_device_quirks {
+};
+
  struct ast_device {
  	struct drm_device base;
 
+	const struct ast_device_quirks *quirks;
+
  	void __iomem *regs;
  	void __iomem *ioregs;
  	void __iomem *dp501_fw_buf;
@@ -414,7 +419,8 @@ void ast_device_init(struct ast_device *ast,
  		     enum ast_chip chip,
  		     enum ast_config_mode config_mode,
  		     void __iomem *regs,
-		     void __iomem *ioregs);
+		     void __iomem *ioregs,
+		     const struct ast_device_quirks *quirks);
  void __ast_device_set_tx_chip(struct ast_device *ast, enum ast_tx_chip tx_chip);
 
  /* ast_2000.c */
author maintainer
#5 lore raw

PATCH 3/5 drm/ast: Store CRTC memory request threshold in device quirks

In reply to Thomas Zimmermann

Store each hardware's CRTC memory threshold in the specific instance of struct ast_device_quirks. Removes the calls to IS_AST_GENn() from ast_set_crtthd_reg().

The values stored in the registers appear to be plain limits. Hence write them in the driver in decimal format instead of hexadecimal.

---
 drivers/gpu/drm/ast/ast_2000.c |  2 ++
 drivers/gpu/drm/ast/ast_2100.c |  2 ++
 drivers/gpu/drm/ast/ast_2200.c |  2 ++
 drivers/gpu/drm/ast/ast_2300.c |  2 ++
 drivers/gpu/drm/ast/ast_2400.c |  2 ++
 drivers/gpu/drm/ast/ast_2500.c |  2 ++
 drivers/gpu/drm/ast/ast_2600.c |  2 ++
 drivers/gpu/drm/ast/ast_drv.h  |  5 +++++
 drivers/gpu/drm/ast/ast_mode.c | 19 +++++--------------
 9 files changed, 24 insertions(+), 14 deletions(-)
drivers/gpu/drm/ast/ast_2000.c +2 -0
index ae4d7a2a0ec8..fa3bc23ce098 100644
@@ -212,6 +212,8 @@ void ast_2000_detect_tx_chip(struct ast_device *ast, bool need_post)
 }
 
 static const struct ast_device_quirks ast_2000_device_quirks = {
+	.crtc_mem_req_threshold_low = 31,
+	.crtc_mem_req_threshold_high = 47,
 };
 
 struct drm_device *ast_2000_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2100.c +2 -0
index 01e064e67cf7..05aeb0624d41 100644
@@ -433,6 +433,8 @@ static void ast_2100_detect_widescreen(struct ast_device *ast)
 }
 
 static const struct ast_device_quirks ast_2100_device_quirks = {
+	.crtc_mem_req_threshold_low = 47,
+	.crtc_mem_req_threshold_high = 63,
 };
 
 struct drm_device *ast_2100_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2200.c +2 -0
index 46b6fc6cf7eb..b64345d11ffa 100644
@@ -44,6 +44,8 @@ static void ast_2200_detect_widescreen(struct ast_device *ast)
 }
 
 static const struct ast_device_quirks ast_2200_device_quirks = {
+	.crtc_mem_req_threshold_low = 47,
+	.crtc_mem_req_threshold_high = 63,
 };
 
 struct drm_device *ast_2200_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2300.c +2 -0
index b76a80d6aea6..5f50d9f91ffd 100644
@@ -1408,6 +1408,8 @@ static void ast_2300_detect_widescreen(struct ast_device *ast)
 }
 
 static const struct ast_device_quirks ast_2300_device_quirks = {
+	.crtc_mem_req_threshold_low = 96,
+	.crtc_mem_req_threshold_high = 120,
 };
 
 struct drm_device *ast_2300_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2400.c +2 -0
index 2b41ff69ab0b..2e6befd24f91 100644
@@ -45,6 +45,8 @@ static void ast_2400_detect_widescreen(struct ast_device *ast)
 }
 
 static const struct ast_device_quirks ast_2400_device_quirks = {
+	.crtc_mem_req_threshold_low = 96,
+	.crtc_mem_req_threshold_high = 120,
 };
 
 struct drm_device *ast_2400_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2500.c +2 -0
index 6d305a8ccc51..416bce9ea757 100644
@@ -619,6 +619,8 @@ static void ast_2500_detect_widescreen(struct ast_device *ast)
 }
 
 static const struct ast_device_quirks ast_2500_device_quirks = {
+	.crtc_mem_req_threshold_low = 96,
+	.crtc_mem_req_threshold_high = 120,
 };
 
 struct drm_device *ast_2500_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2600.c +2 -0
index df3b429e8174..bb0a50b25766 100644
@@ -60,6 +60,8 @@ static void ast_2600_detect_widescreen(struct ast_device *ast)
 }
 
 static const struct ast_device_quirks ast_2600_device_quirks = {
+	.crtc_mem_req_threshold_low = 160,
+	.crtc_mem_req_threshold_high = 224,
 };
 
 struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_drv.h +5 -0
index 2a2c28693dc6..926e1c7de6f8 100644
@@ -165,6 +165,11 @@ to_ast_connector(struct drm_connector *connector)
  */
 
 struct ast_device_quirks {
+	/*
+	 * CRTC memory request threshold
+	 */
+	unsigned char crtc_mem_req_threshold_low;
+	unsigned char crtc_mem_req_threshold_high;
 };
 
 struct ast_device {
drivers/gpu/drm/ast/ast_mode.c +5 -14
index a9ffda1b1dea..da374af9596d 100644
@@ -410,20 +410,11 @@ static void ast_set_color_reg(struct ast_device *ast,
 
 static void ast_set_crtthd_reg(struct ast_device *ast)
 {
-	/* Set Threshold */
-	if (IS_AST_GEN7(ast)) {
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa7, 0xe0);
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa6, 0xa0);
-	} else if (IS_AST_GEN6(ast) || IS_AST_GEN5(ast) || IS_AST_GEN4(ast)) {
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa7, 0x78);
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa6, 0x60);
-	} else if (IS_AST_GEN3(ast) || IS_AST_GEN2(ast)) {
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa7, 0x3f);
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa6, 0x2f);
-	} else {
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa7, 0x2f);
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa6, 0x1f);
-	}
+	u8 vgacra6 = ast->quirks->crtc_mem_req_threshold_low;
+	u8 vgacra7 = ast->quirks->crtc_mem_req_threshold_high;
+
+	ast_set_index_reg(ast, AST_IO_VGACRI, 0xa7, vgacra7);
+	ast_set_index_reg(ast, AST_IO_VGACRI, 0xa6, vgacra6);
 }
 
 static void ast_set_sync_reg(struct ast_device *ast,
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 3/5
#6 lore raw

Re: [PATCH 3/5] drm/ast: Store CRTC memory request threshold in device quirks

Quoted 6 lines · Thomas Zimmermann

Store each hardware's CRTC memory threshold in the specific instance of struct ast_device_quirks. Removes the calls to IS_AST_GENn() from ast_set_crtthd_reg().

The values stored in the registers appear to be plain limits. Hence write them in the driver in decimal format instead of hexadecimal.

Thanks, it looks good to me.

Quoted 151 lines
---
  drivers/gpu/drm/ast/ast_2000.c |  2 ++
  drivers/gpu/drm/ast/ast_2100.c |  2 ++
  drivers/gpu/drm/ast/ast_2200.c |  2 ++
  drivers/gpu/drm/ast/ast_2300.c |  2 ++
  drivers/gpu/drm/ast/ast_2400.c |  2 ++
  drivers/gpu/drm/ast/ast_2500.c |  2 ++
  drivers/gpu/drm/ast/ast_2600.c |  2 ++
  drivers/gpu/drm/ast/ast_drv.h  |  5 +++++
  drivers/gpu/drm/ast/ast_mode.c | 19 +++++--------------
  9 files changed, 24 insertions(+), 14 deletions(-)
drivers/gpu/drm/ast/ast_2000.c +2 -0
index ae4d7a2a0ec8..fa3bc23ce098 100644
@@ -212,6 +212,8 @@ void ast_2000_detect_tx_chip(struct ast_device *ast, bool need_post)
  }
 
  static const struct ast_device_quirks ast_2000_device_quirks = {
+	.crtc_mem_req_threshold_low = 31,
+	.crtc_mem_req_threshold_high = 47,
  };
 
  struct drm_device *ast_2000_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2100.c +2 -0
index 01e064e67cf7..05aeb0624d41 100644
@@ -433,6 +433,8 @@ static void ast_2100_detect_widescreen(struct ast_device *ast)
  }
 
  static const struct ast_device_quirks ast_2100_device_quirks = {
+	.crtc_mem_req_threshold_low = 47,
+	.crtc_mem_req_threshold_high = 63,
  };
 
  struct drm_device *ast_2100_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2200.c +2 -0
index 46b6fc6cf7eb..b64345d11ffa 100644
@@ -44,6 +44,8 @@ static void ast_2200_detect_widescreen(struct ast_device *ast)
  }
 
  static const struct ast_device_quirks ast_2200_device_quirks = {
+	.crtc_mem_req_threshold_low = 47,
+	.crtc_mem_req_threshold_high = 63,
  };
 
  struct drm_device *ast_2200_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2300.c +2 -0
index b76a80d6aea6..5f50d9f91ffd 100644
@@ -1408,6 +1408,8 @@ static void ast_2300_detect_widescreen(struct ast_device *ast)
  }
 
  static const struct ast_device_quirks ast_2300_device_quirks = {
+	.crtc_mem_req_threshold_low = 96,
+	.crtc_mem_req_threshold_high = 120,
  };
 
  struct drm_device *ast_2300_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2400.c +2 -0
index 2b41ff69ab0b..2e6befd24f91 100644
@@ -45,6 +45,8 @@ static void ast_2400_detect_widescreen(struct ast_device *ast)
  }
 
  static const struct ast_device_quirks ast_2400_device_quirks = {
+	.crtc_mem_req_threshold_low = 96,
+	.crtc_mem_req_threshold_high = 120,
  };
 
  struct drm_device *ast_2400_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2500.c +2 -0
index 6d305a8ccc51..416bce9ea757 100644
@@ -619,6 +619,8 @@ static void ast_2500_detect_widescreen(struct ast_device *ast)
  }
 
  static const struct ast_device_quirks ast_2500_device_quirks = {
+	.crtc_mem_req_threshold_low = 96,
+	.crtc_mem_req_threshold_high = 120,
  };
 
  struct drm_device *ast_2500_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2600.c +2 -0
index df3b429e8174..bb0a50b25766 100644
@@ -60,6 +60,8 @@ static void ast_2600_detect_widescreen(struct ast_device *ast)
  }
 
  static const struct ast_device_quirks ast_2600_device_quirks = {
+	.crtc_mem_req_threshold_low = 160,
+	.crtc_mem_req_threshold_high = 224,
  };
 
  struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_drv.h +5 -0
index 2a2c28693dc6..926e1c7de6f8 100644
@@ -165,6 +165,11 @@ to_ast_connector(struct drm_connector *connector)
   */
 
  struct ast_device_quirks {
+	/*
+	 * CRTC memory request threshold
+	 */
+	unsigned char crtc_mem_req_threshold_low;
+	unsigned char crtc_mem_req_threshold_high;
  };
 
  struct ast_device {
drivers/gpu/drm/ast/ast_mode.c +5 -14
index a9ffda1b1dea..da374af9596d 100644
@@ -410,20 +410,11 @@ static void ast_set_color_reg(struct ast_device *ast,
 
  static void ast_set_crtthd_reg(struct ast_device *ast)
  {
-	/* Set Threshold */
-	if (IS_AST_GEN7(ast)) {
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa7, 0xe0);
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa6, 0xa0);
-	} else if (IS_AST_GEN6(ast) || IS_AST_GEN5(ast) || IS_AST_GEN4(ast)) {
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa7, 0x78);
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa6, 0x60);
-	} else if (IS_AST_GEN3(ast) || IS_AST_GEN2(ast)) {
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa7, 0x3f);
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa6, 0x2f);
-	} else {
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa7, 0x2f);
-		ast_set_index_reg(ast, AST_IO_VGACRI, 0xa6, 0x1f);
-	}
+	u8 vgacra6 = ast->quirks->crtc_mem_req_threshold_low;
+	u8 vgacra7 = ast->quirks->crtc_mem_req_threshold_high;
+
+	ast_set_index_reg(ast, AST_IO_VGACRI, 0xa7, vgacra7);
+	ast_set_index_reg(ast, AST_IO_VGACRI, 0xa6, vgacra6);
  }
 
  static void ast_set_sync_reg(struct ast_device *ast,
author maintainer
#7 lore raw

PATCH 4/5 drm/ast: Store precatch settings in struct ast_device_quirks

In reply to Thomas Zimmermann

Add a precatch flag in struct ast_device_info and set it on AST2500 and AST2600. Remove calls to IS_AST_GENn() from ast_set_crtc_reg().

Also fix the coding style in several places.

---
 drivers/gpu/drm/ast/ast_2500.c |  1 +
 drivers/gpu/drm/ast/ast_2600.c |  1 +
 drivers/gpu/drm/ast/ast_drv.h  |  6 ++++++
 drivers/gpu/drm/ast/ast_mode.c | 17 ++++++++---------
 4 files changed, 16 insertions(+), 9 deletions(-)
drivers/gpu/drm/ast/ast_2500.c +1 -0
index 416bce9ea757..2a52af0ded56 100644
@@ -621,6 +621,7 @@ static void ast_2500_detect_widescreen(struct ast_device *ast)
 static const struct ast_device_quirks ast_2500_device_quirks = {
 	.crtc_mem_req_threshold_low = 96,
 	.crtc_mem_req_threshold_high = 120,
+	.crtc_hsync_precatch_needed = true,
 };
 
 struct drm_device *ast_2500_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2600.c +1 -0
index bb0a50b25766..7cde5ce9c41f 100644
@@ -62,6 +62,7 @@ static void ast_2600_detect_widescreen(struct ast_device *ast)
 static const struct ast_device_quirks ast_2600_device_quirks = {
 	.crtc_mem_req_threshold_low = 160,
 	.crtc_mem_req_threshold_high = 224,
+	.crtc_hsync_precatch_needed = true,
 };
 
 struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_drv.h +6 -0
index 926e1c7de6f8..76969244d36f 100644
@@ -170,6 +170,12 @@ struct ast_device_quirks {
 	 */
 	unsigned char crtc_mem_req_threshold_low;
 	unsigned char crtc_mem_req_threshold_high;
+
+	/*
+	 * Adjust hsync values to load next scanline early. Signalled
+	 * by AST2500PreCatchCRT in VBIOS mode flags.
+	 */
+	bool crtc_hsync_precatch_needed;
 };
 
 struct ast_device {
drivers/gpu/drm/ast/ast_mode.c +8 -9
index da374af9596d..ebb1ec82d904 100644
@@ -241,16 +241,15 @@ static void ast_set_std_reg(struct ast_device *ast,
 		ast_set_index_reg(ast, AST_IO_VGAGRI, i, stdtable->gr[i]);
 }
 
-static void ast_set_crtc_reg(struct ast_device *ast,
-			     struct drm_display_mode *mode,
+static void ast_set_crtc_reg(struct ast_device *ast, struct drm_display_mode *mode,
 			     const struct ast_vbios_enhtable *vmode)
 {
 	u8 jreg05 = 0, jreg07 = 0, jreg09 = 0, jregAC = 0, jregAD = 0, jregAE = 0;
-	u16 temp, precache = 0;
+	u16 temp;
+	unsigned char crtc_hsync_precatch = 0;
 
-	if ((IS_AST_GEN6(ast) || IS_AST_GEN7(ast)) &&
-	    (vmode->flags & AST2500PreCatchCRT))
-		precache = 40;
+	if (ast->quirks->crtc_hsync_precatch_needed && (vmode->flags & AST2500PreCatchCRT))
+		crtc_hsync_precatch = 40;
 
 	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x11, 0x7f, 0x00);
 
@@ -276,12 +275,12 @@ static void ast_set_crtc_reg(struct ast_device *ast,
 		jregAD |= 0x01;  /* HBE D[5] */
 	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x03, 0xE0, (temp & 0x1f));
 
-	temp = ((mode->crtc_hsync_start-precache) >> 3) - 1;
+	temp = ((mode->crtc_hsync_start - crtc_hsync_precatch) >> 3) - 1;
 	if (temp & 0x100)
 		jregAC |= 0x40; /* HRS D[5] */
 	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x04, 0x00, temp);
 
-	temp = (((mode->crtc_hsync_end-precache) >> 3) - 1) & 0x3f;
+	temp = (((mode->crtc_hsync_end - crtc_hsync_precatch) >> 3) - 1) & 0x3f;
 	if (temp & 0x20)
 		jregAD |= 0x04; /* HRE D[5] */
 	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x05, 0x60, (u8)((temp & 0x1f) | jreg05));
@@ -348,7 +347,7 @@ static void ast_set_crtc_reg(struct ast_device *ast,
 	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x09, 0xdf, jreg09);
 	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xAE, 0x00, (jregAE | 0x80));
 
-	if (precache)
+	if (crtc_hsync_precatch)
 		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0x3f, 0x80);
 	else
 		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0x3f, 0x00);
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 4/5
#8 lore raw

Re: [PATCH 4/5] drm/ast: Store precatch settings in struct ast_device_quirks

Quoted 4 lines · Thomas Zimmermann

Add a precatch flag in struct ast_device_info and set it on AST2500 and AST2600. Remove calls to IS_AST_GENn() from ast_set_crtc_reg().

Also fix the coding style in several places.

Thanks, it looks good to me.

Quoted 100 lines
---
  drivers/gpu/drm/ast/ast_2500.c |  1 +
  drivers/gpu/drm/ast/ast_2600.c |  1 +
  drivers/gpu/drm/ast/ast_drv.h  |  6 ++++++
  drivers/gpu/drm/ast/ast_mode.c | 17 ++++++++---------
  4 files changed, 16 insertions(+), 9 deletions(-)
drivers/gpu/drm/ast/ast_2500.c +1 -0
index 416bce9ea757..2a52af0ded56 100644
@@ -621,6 +621,7 @@ static void ast_2500_detect_widescreen(struct ast_device *ast)
  static const struct ast_device_quirks ast_2500_device_quirks = {
  	.crtc_mem_req_threshold_low = 96,
  	.crtc_mem_req_threshold_high = 120,
+	.crtc_hsync_precatch_needed = true,
  };
 
  struct drm_device *ast_2500_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_2600.c +1 -0
index bb0a50b25766..7cde5ce9c41f 100644
@@ -62,6 +62,7 @@ static void ast_2600_detect_widescreen(struct ast_device *ast)
  static const struct ast_device_quirks ast_2600_device_quirks = {
  	.crtc_mem_req_threshold_low = 160,
  	.crtc_mem_req_threshold_high = 224,
+	.crtc_hsync_precatch_needed = true,
  };
 
  struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_drv.h +6 -0
index 926e1c7de6f8..76969244d36f 100644
@@ -170,6 +170,12 @@ struct ast_device_quirks {
  	 */
  	unsigned char crtc_mem_req_threshold_low;
  	unsigned char crtc_mem_req_threshold_high;
+
+	/*
+	 * Adjust hsync values to load next scanline early. Signalled
+	 * by AST2500PreCatchCRT in VBIOS mode flags.
+	 */
+	bool crtc_hsync_precatch_needed;
  };
 
  struct ast_device {
drivers/gpu/drm/ast/ast_mode.c +8 -9
index da374af9596d..ebb1ec82d904 100644
@@ -241,16 +241,15 @@ static void ast_set_std_reg(struct ast_device *ast,
  		ast_set_index_reg(ast, AST_IO_VGAGRI, i, stdtable->gr[i]);
  }
 
-static void ast_set_crtc_reg(struct ast_device *ast,
-			     struct drm_display_mode *mode,
+static void ast_set_crtc_reg(struct ast_device *ast, struct drm_display_mode *mode,
  			     const struct ast_vbios_enhtable *vmode)
  {
  	u8 jreg05 = 0, jreg07 = 0, jreg09 = 0, jregAC = 0, jregAD = 0, jregAE = 0;
-	u16 temp, precache = 0;
+	u16 temp;
+	unsigned char crtc_hsync_precatch = 0;
 
-	if ((IS_AST_GEN6(ast) || IS_AST_GEN7(ast)) &&
-	    (vmode->flags & AST2500PreCatchCRT))
-		precache = 40;
+	if (ast->quirks->crtc_hsync_precatch_needed && (vmode->flags & AST2500PreCatchCRT))
+		crtc_hsync_precatch = 40;
 
  	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x11, 0x7f, 0x00);
 
@@ -276,12 +275,12 @@ static void ast_set_crtc_reg(struct ast_device *ast,
  		jregAD |= 0x01;  /* HBE D[5] */
  	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x03, 0xE0, (temp & 0x1f));
 
-	temp = ((mode->crtc_hsync_start-precache) >> 3) - 1;
+	temp = ((mode->crtc_hsync_start - crtc_hsync_precatch) >> 3) - 1;
  	if (temp & 0x100)
  		jregAC |= 0x40; /* HRS D[5] */
  	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x04, 0x00, temp);
 
-	temp = (((mode->crtc_hsync_end-precache) >> 3) - 1) & 0x3f;
+	temp = (((mode->crtc_hsync_end - crtc_hsync_precatch) >> 3) - 1) & 0x3f;
  	if (temp & 0x20)
  		jregAD |= 0x04; /* HRE D[5] */
  	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x05, 0x60, (u8)((temp & 0x1f) | jreg05));
@@ -348,7 +347,7 @@ static void ast_set_crtc_reg(struct ast_device *ast,
  	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0x09, 0xdf, jreg09);
  	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xAE, 0x00, (jregAE | 0x80));
 
-	if (precache)
+	if (crtc_hsync_precatch)
  		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0x3f, 0x80);
  	else
  		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0x3f, 0x00);
author maintainer
#9 lore raw

PATCH 5/5 drm/ast: Store HSync adjustment in device quirks

In reply to Thomas Zimmermann

Add the add4 flag to struct ast_device_quirks and set it on AST2600. Replaces a call to IS_AST_GEN7() in ast_set_crtc_reg().

---
 drivers/gpu/drm/ast/ast_2600.c | 1 +
 drivers/gpu/drm/ast/ast_drv.h  | 6 ++++++
 drivers/gpu/drm/ast/ast_mode.c | 3 +--
 3 files changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/ast/ast_2600.c +1 -0
index 7cde5ce9c41f..dee78fd5b022 100644
@@ -63,6 +63,7 @@ static const struct ast_device_quirks ast_2600_device_quirks = {
 	.crtc_mem_req_threshold_low = 160,
 	.crtc_mem_req_threshold_high = 224,
 	.crtc_hsync_precatch_needed = true,
+	.crtc_hsync_add4_needed = true,
 };
 
 struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_drv.h +6 -0
index 76969244d36f..7be36a358e74 100644
@@ -176,6 +176,12 @@ struct ast_device_quirks {
 	 * by AST2500PreCatchCRT in VBIOS mode flags.
 	 */
 	bool crtc_hsync_precatch_needed;
+
+	/*
+	 * Workaround for modes with HSync Time that is not a multiple
+	 * of 8 (e.g., 1920x1080@60Hz, HSync +44 pixels).
+	 */
+	bool crtc_hsync_add4_needed;
 };
 
 struct ast_device {
drivers/gpu/drm/ast/ast_mode.c +1 -2
index ebb1ec82d904..a8917ab7028c 100644
@@ -288,8 +288,7 @@ static void ast_set_crtc_reg(struct ast_device *ast, struct drm_display_mode *mo
 	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xAC, 0x00, jregAC);
 	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xAD, 0x00, jregAD);
 
-	// Workaround for HSync Time non octave pixels (1920x1080@60Hz HSync 44 pixels);
-	if (IS_AST_GEN7(ast) && (mode->crtc_vdisplay == 1080))
+	if (ast->quirks->crtc_hsync_add4_needed && mode->crtc_vdisplay == 1080)
 		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xFC, 0xFD, 0x02);
 	else
 		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xFC, 0xFD, 0x00);
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 5/5
#10 lore raw

Re: [PATCH 5/5] drm/ast: Store HSync adjustment in device quirks

Quoted 2 lines · Thomas Zimmermann

Add the add4 flag to struct ast_device_quirks and set it on AST2600. Replaces a call to IS_AST_GEN7() in ast_set_crtc_reg().

Thanks, it looks good to me.

Quoted 50 lines
---
  drivers/gpu/drm/ast/ast_2600.c | 1 +
  drivers/gpu/drm/ast/ast_drv.h  | 6 ++++++
  drivers/gpu/drm/ast/ast_mode.c | 3 +--
  3 files changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/ast/ast_2600.c +1 -0
index 7cde5ce9c41f..dee78fd5b022 100644
@@ -63,6 +63,7 @@ static const struct ast_device_quirks ast_2600_device_quirks = {
  	.crtc_mem_req_threshold_low = 160,
  	.crtc_mem_req_threshold_high = 224,
  	.crtc_hsync_precatch_needed = true,
+	.crtc_hsync_add4_needed = true,
  };
 
  struct drm_device *ast_2600_device_create(struct pci_dev *pdev,
drivers/gpu/drm/ast/ast_drv.h +6 -0
index 76969244d36f..7be36a358e74 100644
@@ -176,6 +176,12 @@ struct ast_device_quirks {
  	 * by AST2500PreCatchCRT in VBIOS mode flags.
  	 */
  	bool crtc_hsync_precatch_needed;
+
+	/*
+	 * Workaround for modes with HSync Time that is not a multiple
+	 * of 8 (e.g., 1920x1080@60Hz, HSync +44 pixels).
+	 */
+	bool crtc_hsync_add4_needed;
  };
 
  struct ast_device {
drivers/gpu/drm/ast/ast_mode.c +1 -2
index ebb1ec82d904..a8917ab7028c 100644
@@ -288,8 +288,7 @@ static void ast_set_crtc_reg(struct ast_device *ast, struct drm_display_mode *mo
  	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xAC, 0x00, jregAC);
  	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xAD, 0x00, jregAD);
 
-	// Workaround for HSync Time non octave pixels (1920x1080@60Hz HSync 44 pixels);
-	if (IS_AST_GEN7(ast) && (mode->crtc_vdisplay == 1080))
+	if (ast->quirks->crtc_hsync_add4_needed && mode->crtc_vdisplay == 1080)
  		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xFC, 0xFD, 0x02);
  	else
  		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xFC, 0xFD, 0x00);