The only place in the ast driver that uses the DRAM type is the
P2A DRAM initialization for Gen2 and Gen3 of the chip. Condense
the code in ast_get_dram_info() to exactly this use case and move
it into the Gen's custom source file. Remove the field dram_type
from struct ast_device.

The AST_DRAM_ constants are also used in Gen4 POST helpers, but
independently from the dram_type field. No changes there.

Signed-off-by: Thomas Zimmermann <tzimmerm...@suse.de>
---
 drivers/gpu/drm/ast/ast_2100.c | 47 +++++++++++++++++--
 drivers/gpu/drm/ast/ast_drv.h  |  2 -
 drivers/gpu/drm/ast/ast_main.c | 83 ----------------------------------
 3 files changed, 44 insertions(+), 88 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_2100.c b/drivers/gpu/drm/ast/ast_2100.c
index 477ee15eff5d..44c33dd050eb 100644
--- a/drivers/gpu/drm/ast/ast_2100.c
+++ b/drivers/gpu/drm/ast/ast_2100.c
@@ -31,6 +31,38 @@
 #include "ast_drv.h"
 #include "ast_post.h"
 
+/*
+ * DRAM type
+ */
+
+static int ast_2100_get_dram_type_p2a(struct ast_device *ast)
+{
+       u32 mcr_cfg;
+       int dram_type;
+
+       ast_write32(ast, 0xf004, 0x1e6e0000);
+       ast_write32(ast, 0xf000, 0x1);
+       mcr_cfg = ast_read32(ast, 0x10004);
+
+       switch (mcr_cfg & 0x0c) {
+       case 0:
+       case 4:
+               dram_type = AST_DRAM_512Mx16;
+               break;
+       case 8:
+               if (mcr_cfg & 0x40)
+                       dram_type = AST_DRAM_1Gx16;
+               else
+                       dram_type = AST_DRAM_512Mx32;
+               break;
+       case 0xc:
+               dram_type = AST_DRAM_1Gx32;
+               break;
+       }
+
+       return dram_type;
+}
+
 /*
  * POST
  */
@@ -266,6 +298,9 @@ static void ast_post_chip_2100(struct ast_device *ast)
        u8 j;
        u32 data, temp, i;
        const struct ast_dramstruct *dram_reg_info;
+       int dram_type;
+
+       dram_type = ast_2100_get_dram_type_p2a(ast);
 
        j = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xd0, 0xff);
 
@@ -292,11 +327,17 @@ static void ast_post_chip_2100(struct ast_device *ast)
                                for (i = 0; i < 15; i++)
                                        udelay(dram_reg_info->data);
                        } else if (AST_DRAMSTRUCT_IS(dram_reg_info, DRAM_TYPE)) 
{
-                               data = dram_reg_info->data;
-                               if (ast->dram_type == AST_DRAM_1Gx16)
+                               switch (dram_type) {
+                               case AST_DRAM_1Gx16:
                                        data = 0x00000d89;
-                               else if (ast->dram_type == AST_DRAM_1Gx32)
+                                       break;
+                               case AST_DRAM_1Gx32:
                                        data = 0x00000c8d;
+                                       break;
+                               default:
+                                       data = dram_reg_info->data;
+                                       break;
+                               };
 
                                temp = ast_read32(ast, 0x12070);
                                temp &= 0xc;
diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index c9c933b5a70d..4c29ae9fb511 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -172,8 +172,6 @@ struct ast_device {
        enum ast_config_mode config_mode;
        enum ast_chip chip;
 
-       uint32_t dram_type;
-
        void __iomem    *vram;
        unsigned long   vram_base;
        unsigned long   vram_size;
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 41ff880cfdec..3eea6a6cdacd 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -210,85 +210,6 @@ static void ast_detect_tx_chip(struct ast_device *ast, 
bool need_post)
        drm_info(dev, "Using %s\n", info_str[ast->tx_chip]);
 }
 
-static int ast_get_dram_info(struct ast_device *ast)
-{
-       struct drm_device *dev = &ast->base;
-       struct device_node *np = dev->dev->of_node;
-       uint32_t mcr_cfg;
-
-       switch (ast->config_mode) {
-       case ast_use_dt:
-               /*
-                * If some properties are missing, use reasonable
-                * defaults for GEN5
-                */
-               if (of_property_read_u32(np, "aspeed,mcr-configuration", 
&mcr_cfg))
-                       mcr_cfg = 0x00000577;
-               break;
-       case ast_use_p2a:
-               ast_write32(ast, 0xf004, 0x1e6e0000);
-               ast_write32(ast, 0xf000, 0x1);
-               mcr_cfg = ast_read32(ast, 0x10004);
-               break;
-       case ast_use_defaults:
-       default:
-               ast->dram_type = AST_DRAM_1Gx16;
-               return 0;
-       }
-
-       if (IS_AST_GEN6(ast)) {
-               switch (mcr_cfg & 0x03) {
-               case 0:
-                       ast->dram_type = AST_DRAM_1Gx16;
-                       break;
-               default:
-               case 1:
-                       ast->dram_type = AST_DRAM_2Gx16;
-                       break;
-               case 2:
-                       ast->dram_type = AST_DRAM_4Gx16;
-                       break;
-               case 3:
-                       ast->dram_type = AST_DRAM_8Gx16;
-                       break;
-               }
-       } else if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast)) {
-               switch (mcr_cfg & 0x03) {
-               case 0:
-                       ast->dram_type = AST_DRAM_512Mx16;
-                       break;
-               default:
-               case 1:
-                       ast->dram_type = AST_DRAM_1Gx16;
-                       break;
-               case 2:
-                       ast->dram_type = AST_DRAM_2Gx16;
-                       break;
-               case 3:
-                       ast->dram_type = AST_DRAM_4Gx16;
-                       break;
-               }
-       } else {
-               switch (mcr_cfg & 0x0c) {
-               case 0:
-               case 4:
-                       ast->dram_type = AST_DRAM_512Mx16;
-                       break;
-               case 8:
-                       if (mcr_cfg & 0x40)
-                               ast->dram_type = AST_DRAM_1Gx16;
-                       else
-                               ast->dram_type = AST_DRAM_512Mx32;
-                       break;
-               case 0xc:
-                       ast->dram_type = AST_DRAM_1Gx32;
-                       break;
-               }
-       }
-
-       return 0;
-}
-
 struct drm_device *ast_device_create(struct pci_dev *pdev,
                                     const struct drm_driver *drv,
                                     enum ast_chip chip,
@@ -311,10 +232,6 @@ struct drm_device *ast_device_create(struct pci_dev *pdev,
        ast->regs = regs;
        ast->ioregs = ioregs;
 
-       ret = ast_get_dram_info(ast);
-       if (ret)
-               return ERR_PTR(ret);
-
        ast_detect_tx_chip(ast, need_post);
        switch (ast->tx_chip) {
        case AST_TX_ASTDP:
-- 
2.50.1

Reply via email to