Re: [09/14] drm/ast: Distinguish among chip generations

2023-06-19 Thread Sui Jingfeng

Hi

On 2023/6/19 16:22, Thomas Zimmermann wrote:

Hi

Am 17.06.23 um 10:35 schrieb Sui Jingfeng:

Hi,

On 2023/6/16 21:52, Thomas Zimmermann wrote:

ASpeed distinguishes among various generations of the AST graphics
chipset with various models. [1] The most-recent model AST 2600 is
of the 7th generation, the AST 2500 is of the 6th generation, and so
on.

The ast driver simply picks one of the models as representative for
the whole generation. In several places, individual models of the
same generation need to be handled differently, which then requires
additional code for detecting the model.

Introduce different generations of the Aspeed chipset. In the source
code, refer to the generation instead of the representation model where
possible. The few places that require per-model handling are now 
clearly

marked.

In the enum ast_chip, we arrange each model's value such that it
encodes the generation. This allows for an easy test. The actual values
are ordered, but not of interest to the driver.

Signed-off-by: Thomas Zimmermann 
Link: 
https://web.archive.org/web/20141007093258/http://www.aspeedtech.com/products.php?fPath=20 
# 1

---
  drivers/gpu/drm/ast/ast_dp501.c |  6 ++--
  drivers/gpu/drm/ast/ast_drv.h   | 56 
+++--

  drivers/gpu/drm/ast/ast_main.c  | 22 ++---
  drivers/gpu/drm/ast/ast_mode.c  | 35 ++---
  drivers/gpu/drm/ast/ast_post.c  | 27 +++-
  5 files changed, 89 insertions(+), 57 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_dp501.c 
b/drivers/gpu/drm/ast/ast_dp501.c

index 1bc35a992369d..a5d285850ffb1 100644
--- a/drivers/gpu/drm/ast/ast_dp501.c
+++ b/drivers/gpu/drm/ast/ast_dp501.c
@@ -350,7 +350,7 @@ static bool ast_init_dvo(struct drm_device *dev)
  data |= 0x0500;
  ast_write32(ast, 0x12008, data);
-    if (ast->chip == AST2300) {
+    if (IS_AST_GEN4(ast)) {
  data = ast_read32(ast, 0x12084);
  /* multi-pins for DVO single-edge */
  data |= 0xfffe;
@@ -366,7 +366,7 @@ static bool ast_init_dvo(struct drm_device *dev)
  data &= 0xffcf;
  data |= 0x0020;
  ast_write32(ast, 0x12090, data);
-    } else { /* AST2400 */
+    } else { /* AST GEN5+ */
  data = ast_read32(ast, 0x12088);
  /* multi-pins for DVO single-edge */
  data |= 0x3000;
@@ -437,7 +437,7 @@ void ast_init_3rdtx(struct drm_device *dev)
  struct ast_device *ast = to_ast_device(dev);
  u8 jreg;
-    if (ast->chip == AST2300 || ast->chip == AST2400) {
+    if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast)) {
  jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 
0xff);

  switch (jreg & 0x0e) {
  case 0x04:
diff --git a/drivers/gpu/drm/ast/ast_drv.h 
b/drivers/gpu/drm/ast/ast_drv.h

index c42dfb86e040d..c209d7e4e4194 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -55,18 +55,38 @@
  #define AST_PCI_OPTION_MEM_ACCESS_ENABLE    BIT(1)
  #define AST_PCI_OPTION_IO_ACCESS_ENABLE    BIT(0)
+#define __AST_CHIP(__gen, __index)    ((__gen) << 16 | (__index))
+
  enum ast_chip {
-    AST2000,
-    AST2100,
-    AST1100,
-    AST2200,
-    AST2150,
-    AST2300,
-    AST2400,
-    AST2500,
-    AST2600,
+    /* 1st gen */
+    AST1000 = __AST_CHIP(1, 0), // unused
+    AST2000 = __AST_CHIP(1, 1),
+    /* 2nd gen */
+    AST1100 = __AST_CHIP(2, 0),
+    AST2100 = __AST_CHIP(2, 1),
+    AST2050 = __AST_CHIP(2, 2), // unused
+    /* 3rd gen */
+    AST2200 = __AST_CHIP(3, 0),
+    AST2150 = __AST_CHIP(3, 1),
+    /* 4th gen */
+    AST2300 = __AST_CHIP(4, 0),
+    AST1300 = __AST_CHIP(4, 1), // unused
+    AST1050 = __AST_CHIP(4, 2), // unused
+    /* 5th gen */
+    AST2400 = __AST_CHIP(5, 0),
+    AST1400 = __AST_CHIP(5, 1), // unused
+    AST1250 = __AST_CHIP(5, 2), // unused
+    /* 6th gen */
+    AST2500 = __AST_CHIP(6, 0),
+    AST2510 = __AST_CHIP(6, 1), // unused
+    AST2520 = __AST_CHIP(6, 2), // unused
+    /* 7th gen */
+    AST2600 = __AST_CHIP(7, 0),
+    AST2620 = __AST_CHIP(7, 1), // unused
  };
+#define __AST_CHIP_GEN(__chip)    (((unsigned long)(__chip)) >> 16)
+
  enum ast_tx_chip {
  AST_TX_NONE,
  AST_TX_SIL164,
@@ -220,6 +240,24 @@ struct ast_device *ast_device_create(const 
struct drm_driver *drv,

   struct pci_dev *pdev,
   unsigned long flags);
+static inline unsigned long __ast_gen(struct ast_device *ast)
+{
+    return __AST_CHIP_GEN(ast->chip);
+}
+#define AST_GEN(__ast)    __ast_gen(__ast)
+
+static inline bool __ast_is_gen(struct ast_device *ast, unsigned 
long gen)

+{
+    return __ast_gen(ast) == gen;
+}


Changed to __ast_gen_is_equal() ?


Makes sense.





+#define IS_AST_GEN1(__ast) __ast_is_gen(__ast, 1)
+#define IS_AST_GEN2(__ast)    __ast_is_gen(__ast, 2)
+#define IS_AST_GEN3(__ast)    __ast_is_gen(__ast, 3)
+#define IS_AST_GEN4(__ast)    __ast_is_gen(__ast, 

Re: [09/14] drm/ast: Distinguish among chip generations

2023-06-19 Thread Thomas Zimmermann

Hi

Am 17.06.23 um 10:35 schrieb Sui Jingfeng:

Hi,

On 2023/6/16 21:52, Thomas Zimmermann wrote:

ASpeed distinguishes among various generations of the AST graphics
chipset with various models. [1] The most-recent model AST 2600 is
of the 7th generation, the AST 2500 is of the 6th generation, and so
on.

The ast driver simply picks one of the models as representative for
the whole generation. In several places, individual models of the
same generation need to be handled differently, which then requires
additional code for detecting the model.

Introduce different generations of the Aspeed chipset. In the source
code, refer to the generation instead of the representation model where
possible. The few places that require per-model handling are now clearly
marked.

In the enum ast_chip, we arrange each model's value such that it
encodes the generation. This allows for an easy test. The actual values
are ordered, but not of interest to the driver.

Signed-off-by: Thomas Zimmermann 
Link: 
https://web.archive.org/web/20141007093258/http://www.aspeedtech.com/products.php?fPath=20 # 1

---
  drivers/gpu/drm/ast/ast_dp501.c |  6 ++--
  drivers/gpu/drm/ast/ast_drv.h   | 56 +++--
  drivers/gpu/drm/ast/ast_main.c  | 22 ++---
  drivers/gpu/drm/ast/ast_mode.c  | 35 ++---
  drivers/gpu/drm/ast/ast_post.c  | 27 +++-
  5 files changed, 89 insertions(+), 57 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_dp501.c 
b/drivers/gpu/drm/ast/ast_dp501.c

index 1bc35a992369d..a5d285850ffb1 100644
--- a/drivers/gpu/drm/ast/ast_dp501.c
+++ b/drivers/gpu/drm/ast/ast_dp501.c
@@ -350,7 +350,7 @@ static bool ast_init_dvo(struct drm_device *dev)
  data |= 0x0500;
  ast_write32(ast, 0x12008, data);
-    if (ast->chip == AST2300) {
+    if (IS_AST_GEN4(ast)) {
  data = ast_read32(ast, 0x12084);
  /* multi-pins for DVO single-edge */
  data |= 0xfffe;
@@ -366,7 +366,7 @@ static bool ast_init_dvo(struct drm_device *dev)
  data &= 0xffcf;
  data |= 0x0020;
  ast_write32(ast, 0x12090, data);
-    } else { /* AST2400 */
+    } else { /* AST GEN5+ */
  data = ast_read32(ast, 0x12088);
  /* multi-pins for DVO single-edge */
  data |= 0x3000;
@@ -437,7 +437,7 @@ void ast_init_3rdtx(struct drm_device *dev)
  struct ast_device *ast = to_ast_device(dev);
  u8 jreg;
-    if (ast->chip == AST2300 || ast->chip == AST2400) {
+    if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast)) {
  jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 
0xff);

  switch (jreg & 0x0e) {
  case 0x04:
diff --git a/drivers/gpu/drm/ast/ast_drv.h 
b/drivers/gpu/drm/ast/ast_drv.h

index c42dfb86e040d..c209d7e4e4194 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -55,18 +55,38 @@
  #define AST_PCI_OPTION_MEM_ACCESS_ENABLE    BIT(1)
  #define AST_PCI_OPTION_IO_ACCESS_ENABLE    BIT(0)
+#define __AST_CHIP(__gen, __index)    ((__gen) << 16 | (__index))
+
  enum ast_chip {
-    AST2000,
-    AST2100,
-    AST1100,
-    AST2200,
-    AST2150,
-    AST2300,
-    AST2400,
-    AST2500,
-    AST2600,
+    /* 1st gen */
+    AST1000 = __AST_CHIP(1, 0), // unused
+    AST2000 = __AST_CHIP(1, 1),
+    /* 2nd gen */
+    AST1100 = __AST_CHIP(2, 0),
+    AST2100 = __AST_CHIP(2, 1),
+    AST2050 = __AST_CHIP(2, 2), // unused
+    /* 3rd gen */
+    AST2200 = __AST_CHIP(3, 0),
+    AST2150 = __AST_CHIP(3, 1),
+    /* 4th gen */
+    AST2300 = __AST_CHIP(4, 0),
+    AST1300 = __AST_CHIP(4, 1), // unused
+    AST1050 = __AST_CHIP(4, 2), // unused
+    /* 5th gen */
+    AST2400 = __AST_CHIP(5, 0),
+    AST1400 = __AST_CHIP(5, 1), // unused
+    AST1250 = __AST_CHIP(5, 2), // unused
+    /* 6th gen */
+    AST2500 = __AST_CHIP(6, 0),
+    AST2510 = __AST_CHIP(6, 1), // unused
+    AST2520 = __AST_CHIP(6, 2), // unused
+    /* 7th gen */
+    AST2600 = __AST_CHIP(7, 0),
+    AST2620 = __AST_CHIP(7, 1), // unused
  };
+#define __AST_CHIP_GEN(__chip)    (((unsigned long)(__chip)) >> 16)
+
  enum ast_tx_chip {
  AST_TX_NONE,
  AST_TX_SIL164,
@@ -220,6 +240,24 @@ struct ast_device *ast_device_create(const struct 
drm_driver *drv,

   struct pci_dev *pdev,
   unsigned long flags);
+static inline unsigned long __ast_gen(struct ast_device *ast)
+{
+    return __AST_CHIP_GEN(ast->chip);
+}
+#define AST_GEN(__ast)    __ast_gen(__ast)
+
+static inline bool __ast_is_gen(struct ast_device *ast, unsigned long 
gen)

+{
+    return __ast_gen(ast) == gen;
+}


Changed to __ast_gen_is_equal() ?


Makes sense.





+#define IS_AST_GEN1(__ast)    __ast_is_gen(__ast, 1)
+#define IS_AST_GEN2(__ast)    __ast_is_gen(__ast, 2)
+#define IS_AST_GEN3(__ast)    __ast_is_gen(__ast, 3)
+#define IS_AST_GEN4(__ast)    __ast_is_gen(__ast, 4)
+#define IS_AST_GEN5(__ast)    __ast_is_gen(__ast, 

Re: [09/14] drm/ast: Distinguish among chip generations

2023-06-17 Thread Sui Jingfeng

Hi,

On 2023/6/16 21:52, Thomas Zimmermann wrote:

ASpeed distinguishes among various generations of the AST graphics
chipset with various models. [1] The most-recent model AST 2600 is
of the 7th generation, the AST 2500 is of the 6th generation, and so
on.

The ast driver simply picks one of the models as representative for
the whole generation. In several places, individual models of the
same generation need to be handled differently, which then requires
additional code for detecting the model.

Introduce different generations of the Aspeed chipset. In the source
code, refer to the generation instead of the representation model where
possible. The few places that require per-model handling are now clearly
marked.

In the enum ast_chip, we arrange each model's value such that it
encodes the generation. This allows for an easy test. The actual values
are ordered, but not of interest to the driver.

Signed-off-by: Thomas Zimmermann 
Link: 
https://web.archive.org/web/20141007093258/http://www.aspeedtech.com/products.php?fPath=20
 # 1
---
  drivers/gpu/drm/ast/ast_dp501.c |  6 ++--
  drivers/gpu/drm/ast/ast_drv.h   | 56 +++--
  drivers/gpu/drm/ast/ast_main.c  | 22 ++---
  drivers/gpu/drm/ast/ast_mode.c  | 35 ++---
  drivers/gpu/drm/ast/ast_post.c  | 27 +++-
  5 files changed, 89 insertions(+), 57 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_dp501.c b/drivers/gpu/drm/ast/ast_dp501.c
index 1bc35a992369d..a5d285850ffb1 100644
--- a/drivers/gpu/drm/ast/ast_dp501.c
+++ b/drivers/gpu/drm/ast/ast_dp501.c
@@ -350,7 +350,7 @@ static bool ast_init_dvo(struct drm_device *dev)
data |= 0x0500;
ast_write32(ast, 0x12008, data);
  
-		if (ast->chip == AST2300) {

+   if (IS_AST_GEN4(ast)) {
data = ast_read32(ast, 0x12084);
/* multi-pins for DVO single-edge */
data |= 0xfffe;
@@ -366,7 +366,7 @@ static bool ast_init_dvo(struct drm_device *dev)
data &= 0xffcf;
data |= 0x0020;
ast_write32(ast, 0x12090, data);
-   } else { /* AST2400 */
+   } else { /* AST GEN5+ */
data = ast_read32(ast, 0x12088);
/* multi-pins for DVO single-edge */
data |= 0x3000;
@@ -437,7 +437,7 @@ void ast_init_3rdtx(struct drm_device *dev)
struct ast_device *ast = to_ast_device(dev);
u8 jreg;
  
-	if (ast->chip == AST2300 || ast->chip == AST2400) {

+   if (IS_AST_GEN4(ast) || IS_AST_GEN5(ast)) {
jreg = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xd1, 
0xff);
switch (jreg & 0x0e) {
case 0x04:
diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index c42dfb86e040d..c209d7e4e4194 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -55,18 +55,38 @@
  #define AST_PCI_OPTION_MEM_ACCESS_ENABLE  BIT(1)
  #define AST_PCI_OPTION_IO_ACCESS_ENABLE   BIT(0)
  
+#define __AST_CHIP(__gen, __index)	((__gen) << 16 | (__index))

+
  enum ast_chip {
-   AST2000,
-   AST2100,
-   AST1100,
-   AST2200,
-   AST2150,
-   AST2300,
-   AST2400,
-   AST2500,
-   AST2600,
+   /* 1st gen */
+   AST1000 = __AST_CHIP(1, 0), // unused
+   AST2000 = __AST_CHIP(1, 1),
+   /* 2nd gen */
+   AST1100 = __AST_CHIP(2, 0),
+   AST2100 = __AST_CHIP(2, 1),
+   AST2050 = __AST_CHIP(2, 2), // unused
+   /* 3rd gen */
+   AST2200 = __AST_CHIP(3, 0),
+   AST2150 = __AST_CHIP(3, 1),
+   /* 4th gen */
+   AST2300 = __AST_CHIP(4, 0),
+   AST1300 = __AST_CHIP(4, 1), // unused
+   AST1050 = __AST_CHIP(4, 2), // unused
+   /* 5th gen */
+   AST2400 = __AST_CHIP(5, 0),
+   AST1400 = __AST_CHIP(5, 1), // unused
+   AST1250 = __AST_CHIP(5, 2), // unused
+   /* 6th gen */
+   AST2500 = __AST_CHIP(6, 0),
+   AST2510 = __AST_CHIP(6, 1), // unused
+   AST2520 = __AST_CHIP(6, 2), // unused
+   /* 7th gen */
+   AST2600 = __AST_CHIP(7, 0),
+   AST2620 = __AST_CHIP(7, 1), // unused
  };
  
+#define __AST_CHIP_GEN(__chip)	(((unsigned long)(__chip)) >> 16)

+
  enum ast_tx_chip {
AST_TX_NONE,
AST_TX_SIL164,
@@ -220,6 +240,24 @@ struct ast_device *ast_device_create(const struct 
drm_driver *drv,
 struct pci_dev *pdev,
 unsigned long flags);
  
+static inline unsigned long __ast_gen(struct ast_device *ast)

+{
+   return __AST_CHIP_GEN(ast->chip);
+}
+#define AST_GEN(__ast) __ast_gen(__ast)
+
+static inline bool __ast_is_gen(struct ast_device *ast, unsigned long gen)
+{
+   return __ast_gen(ast) == gen;
+}


Changed to __ast_gen_is_equal() ?



+#define IS_AST_GEN1(__ast)