From: Thomas Zimmermann <tzimmermann@suse.de>
To: airlied@redhat.com, jfalempe@redhat.com,
maarten.lankhorst@linux.intel.com, mripard@kernel.org,
daniel@ffwll.ch, airlied@gmail.com
Cc: Thomas Zimmermann <tzimmermann@suse.de>, dri-devel@lists.freedesktop.org
Subject: [PATCH v2 09/10] drm/ast: Detect ast device type and config mode without ast device
Date: Thu, 16 Nov 2023 10:59:28 +0100 [thread overview]
Message-ID: <20231116100240.22975-10-tzimmermann@suse.de> (raw)
In-Reply-To: <20231116100240.22975-1-tzimmermann@suse.de>
Return the ast chip and config in the detection function's parameters
instead of storing them directly in the ast device instance.
v2:
* add break statements to switch default branches (Jocelyn)
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
---
drivers/gpu/drm/ast/ast_main.c | 106 ++++++++++++++++++---------------
1 file changed, 59 insertions(+), 47 deletions(-)
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 19c8894e391a0..ad5b758153de1 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -76,25 +76,27 @@ static void ast_open_key(void __iomem *ioregs)
__ast_write8_i(ioregs, AST_IO_VGACRI, 0x80, AST_IO_VGACR80_PASSWORD);
}
-static int ast_device_config_init(struct ast_device *ast)
+static int ast_detect_chip(struct pci_dev *pdev,
+ void __iomem *regs, void __iomem *ioregs,
+ enum ast_chip *chip_out,
+ enum ast_config_mode *config_mode_out)
{
- struct drm_device *dev = &ast->base;
- struct pci_dev *pdev = to_pci_dev(dev->dev);
- struct device_node *np = dev->dev->of_node;
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
+ enum ast_config_mode config_mode = ast_use_defaults;
uint32_t scu_rev = 0xffffffff;
+ enum ast_chip chip;
u32 data;
- u8 jregd0, jregd1;
+ u8 vgacrd0, vgacrd1;
/*
* Find configuration mode and read SCU revision
*/
- ast->config_mode = ast_use_defaults;
-
/* Check if we have device-tree properties */
if (np && !of_property_read_u32(np, "aspeed,scu-revision-id", &data)) {
/* We do, disable P2A access */
- ast->config_mode = ast_use_dt;
+ config_mode = ast_use_dt;
scu_rev = data;
} else if (pdev->device == PCI_CHIP_AST2000) { // Not all families have a P2A bridge
/*
@@ -102,9 +104,9 @@ static int ast_device_config_init(struct ast_device *ast)
* is disabled. We force using P2A if VGA only mode bit
* is set D[7]
*/
- jregd0 = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
- jregd1 = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd1, 0xff);
- if (!(jregd0 & 0x80) || !(jregd1 & 0x10)) {
+ vgacrd0 = __ast_read8_i(ioregs, AST_IO_VGACRI, 0xd0);
+ vgacrd1 = __ast_read8_i(ioregs, AST_IO_VGACRI, 0xd1);
+ if (!(vgacrd0 & 0x80) || !(vgacrd1 & 0x10)) {
/*
* We have a P2A bridge and it is enabled.
@@ -112,32 +114,32 @@ static int ast_device_config_init(struct ast_device *ast)
/* Patch AST2500/AST2510 */
if ((pdev->revision & 0xf0) == 0x40) {
- if (!(jregd0 & AST_VRAM_INIT_STATUS_MASK))
- ast_patch_ahb_2500(ast->regs);
+ if (!(vgacrd0 & AST_VRAM_INIT_STATUS_MASK))
+ ast_patch_ahb_2500(regs);
}
/* Double check that it's actually working */
- data = ast_read32(ast, 0xf004);
+ data = __ast_read32(regs, 0xf004);
if ((data != 0xffffffff) && (data != 0x00)) {
- ast->config_mode = ast_use_p2a;
+ config_mode = ast_use_p2a;
/* Read SCU7c (silicon revision register) */
- ast_write32(ast, 0xf004, 0x1e6e0000);
- ast_write32(ast, 0xf000, 0x1);
- scu_rev = ast_read32(ast, 0x1207c);
+ __ast_write32(regs, 0xf004, 0x1e6e0000);
+ __ast_write32(regs, 0xf000, 0x1);
+ scu_rev = __ast_read32(regs, 0x1207c);
}
}
}
- switch (ast->config_mode) {
+ switch (config_mode) {
case ast_use_defaults:
- drm_info(dev, "Using default configuration\n");
+ dev_info(dev, "Using default configuration\n");
break;
case ast_use_dt:
- drm_info(dev, "Using device-tree for configuration\n");
+ dev_info(dev, "Using device-tree for configuration\n");
break;
case ast_use_p2a:
- drm_info(dev, "Using P2A bridge for configuration\n");
+ dev_info(dev, "Using P2A bridge for configuration\n");
break;
}
@@ -146,63 +148,68 @@ static int ast_device_config_init(struct ast_device *ast)
*/
if (pdev->revision >= 0x50) {
- ast->chip = AST2600;
- drm_info(dev, "AST 2600 detected\n");
+ chip = AST2600;
+ dev_info(dev, "AST 2600 detected\n");
} else if (pdev->revision >= 0x40) {
switch (scu_rev & 0x300) {
case 0x0100:
- ast->chip = AST2510;
- drm_info(dev, "AST 2510 detected\n");
+ chip = AST2510;
+ dev_info(dev, "AST 2510 detected\n");
break;
default:
- ast->chip = AST2500;
- drm_info(dev, "AST 2500 detected\n");
+ chip = AST2500;
+ dev_info(dev, "AST 2500 detected\n");
+ break;
}
} else if (pdev->revision >= 0x30) {
switch (scu_rev & 0x300) {
case 0x0100:
- ast->chip = AST1400;
- drm_info(dev, "AST 1400 detected\n");
+ chip = AST1400;
+ dev_info(dev, "AST 1400 detected\n");
break;
default:
- ast->chip = AST2400;
- drm_info(dev, "AST 2400 detected\n");
+ chip = AST2400;
+ dev_info(dev, "AST 2400 detected\n");
+ break;
}
} else if (pdev->revision >= 0x20) {
switch (scu_rev & 0x300) {
case 0x0000:
- ast->chip = AST1300;
- drm_info(dev, "AST 1300 detected\n");
+ chip = AST1300;
+ dev_info(dev, "AST 1300 detected\n");
break;
default:
- ast->chip = AST2300;
- drm_info(dev, "AST 2300 detected\n");
+ chip = AST2300;
+ dev_info(dev, "AST 2300 detected\n");
break;
}
} else if (pdev->revision >= 0x10) {
switch (scu_rev & 0x0300) {
case 0x0200:
- ast->chip = AST1100;
- drm_info(dev, "AST 1100 detected\n");
+ chip = AST1100;
+ dev_info(dev, "AST 1100 detected\n");
break;
case 0x0100:
- ast->chip = AST2200;
- drm_info(dev, "AST 2200 detected\n");
+ chip = AST2200;
+ dev_info(dev, "AST 2200 detected\n");
break;
case 0x0000:
- ast->chip = AST2150;
- drm_info(dev, "AST 2150 detected\n");
+ chip = AST2150;
+ dev_info(dev, "AST 2150 detected\n");
break;
default:
- ast->chip = AST2100;
- drm_info(dev, "AST 2100 detected\n");
+ chip = AST2100;
+ dev_info(dev, "AST 2100 detected\n");
break;
}
} else {
- ast->chip = AST2000;
- drm_info(dev, "AST 2000 detected\n");
+ chip = AST2000;
+ dev_info(dev, "AST 2000 detected\n");
}
+ *chip_out = chip;
+ *config_mode_out = config_mode;
+
return 0;
}
@@ -431,6 +438,8 @@ struct ast_device *ast_device_create(const struct drm_driver *drv,
int ret = 0;
void __iomem *regs;
void __iomem *ioregs;
+ enum ast_config_mode config_mode;
+ enum ast_chip chip;
ast = devm_drm_dev_alloc(&pdev->dev, drv, struct ast_device, base);
if (IS_ERR(ast))
@@ -502,10 +511,13 @@ struct ast_device *ast_device_create(const struct drm_driver *drv,
if (ret)
return ERR_PTR(ret);
- ret = ast_device_config_init(ast);
+ ret = ast_detect_chip(pdev, regs, ioregs, &chip, &config_mode);
if (ret)
return ERR_PTR(ret);
+ ast->chip = chip;
+ ast->config_mode = config_mode;
+
ast_detect_widescreen(ast);
ast_detect_tx_chip(ast, need_post);
--
2.42.0
next prev parent reply other threads:[~2023-11-16 10:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-16 9:59 [PATCH v2 00/10] drm/ast: Detect device type before init Thomas Zimmermann
2023-11-16 9:59 ` [PATCH v2 01/10] drm/ast: Turn ioregs_lock to modeset_lock Thomas Zimmermann
2023-11-16 9:59 ` [PATCH v2 02/10] drm/ast: Rework I/O register setup Thomas Zimmermann
2023-11-16 9:59 ` [PATCH v2 03/10] drm/ast: Retrieve I/O-memory ranges without ast device Thomas Zimmermann
2023-11-16 9:59 ` [PATCH v2 04/10] drm/ast: Add I/O helpers " Thomas Zimmermann
2023-11-16 14:22 ` [v2,04/10] " Sui Jingfeng
2023-11-16 9:59 ` [PATCH v2 05/10] drm/ast: Enable VGA without ast device instance Thomas Zimmermann
2023-11-16 9:59 ` [PATCH v2 06/10] drm/ast: Enable MMIO " Thomas Zimmermann
2023-11-16 9:59 ` [PATCH v2 07/10] drm/ast: Partially implement POST " Thomas Zimmermann
2023-11-16 9:59 ` [PATCH v2 08/10] drm/ast: Add enum ast_config_mode Thomas Zimmermann
2023-11-16 9:59 ` Thomas Zimmermann [this message]
2023-11-16 9:59 ` [PATCH v2 10/10] drm/ast: Move detection code into PCI probe helper Thomas Zimmermann
2023-11-18 15:06 ` [PATCH v2 00/10] drm/ast: Detect device type before init Sui Jingfeng
2023-11-20 6:53 ` Thomas Zimmermann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231116100240.22975-10-tzimmermann@suse.de \
--to=tzimmermann@suse.de \
--cc=airlied@gmail.com \
--cc=airlied@redhat.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=jfalempe@redhat.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.