Skip to content

Commit eb104c6

Browse files
author
Thomas Zimmermann
committed
drm/ast: Handle known struct ast_dramstruct with helpers
Most of struct ast_dramstruct stores hardware state. Some index values have known or special meaning. The known values are - 0xffff - Terminal entry in the array - 0xff00 - Delays the programming for usecs - 0x0004 - Sets the type of DRAM Add constants and helper macros for these cases. Also add a helper macro for testing. Update Gen1 and Gen2+ accordingly. Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Jocelyn Falempe <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f28f15e commit eb104c6

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

drivers/gpu/drm/ast/ast_2000.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
static const struct ast_dramstruct ast2000_dram_table_data[] = {
3939
{ 0x0108, 0x00000000 },
4040
{ 0x0120, 0x00004a21 },
41-
{ 0xFF00, 0x00000043 },
41+
AST_DRAMSTRUCT_UDELAY(67u),
4242
{ 0x0000, 0xFFFFFFFF },
43-
{ 0x0004, 0x00000089 },
43+
AST_DRAMSTRUCT_INIT(DRAM_TYPE, 0x00000089),
4444
{ 0x0008, 0x22331353 },
4545
{ 0x000C, 0x0d07000b },
4646
{ 0x0010, 0x11113333 },
@@ -49,18 +49,18 @@ static const struct ast_dramstruct ast2000_dram_table_data[] = {
4949
{ 0x0024, 0x00000001 },
5050
{ 0x001C, 0x00000000 },
5151
{ 0x0014, 0x00000003 },
52-
{ 0xFF00, 0x00000043 },
52+
AST_DRAMSTRUCT_UDELAY(67u),
5353
{ 0x0018, 0x00000131 },
5454
{ 0x0014, 0x00000001 },
55-
{ 0xFF00, 0x00000043 },
55+
AST_DRAMSTRUCT_UDELAY(67u),
5656
{ 0x0018, 0x00000031 },
5757
{ 0x0014, 0x00000001 },
58-
{ 0xFF00, 0x00000043 },
58+
AST_DRAMSTRUCT_UDELAY(67u),
5959
{ 0x0028, 0x1e0828f1 },
6060
{ 0x0024, 0x00000003 },
6161
{ 0x002C, 0x1f0f28fb },
6262
{ 0x0030, 0xFFFFFE01 },
63-
{ 0xFFFF, 0xFFFFFFFF }
63+
AST_DRAMSTRUCT_INVALID,
6464
};
6565

6666
static void ast_post_chip_2000(struct ast_device *ast)
@@ -81,8 +81,8 @@ static void ast_post_chip_2000(struct ast_device *ast)
8181
;
8282
} while (ast_read32(ast, 0x10100) != 0xa8);
8383

84-
while (dram_reg_info->index != 0xffff) {
85-
if (dram_reg_info->index == 0xff00) {/* delay fn */
84+
while (!AST_DRAMSTRUCT_IS(dram_reg_info, INVALID)) {
85+
if (AST_DRAMSTRUCT_IS(dram_reg_info, UDELAY)) {
8686
for (i = 0; i < 15; i++)
8787
udelay(dram_reg_info->data);
8888
} else {

drivers/gpu/drm/ast/ast_2100.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@
3838
static const struct ast_dramstruct ast1100_dram_table_data[] = {
3939
{ 0x2000, 0x1688a8a8 },
4040
{ 0x2020, 0x000041f0 },
41-
{ 0xFF00, 0x00000043 },
41+
AST_DRAMSTRUCT_UDELAY(67u),
4242
{ 0x0000, 0xfc600309 },
4343
{ 0x006C, 0x00909090 },
4444
{ 0x0064, 0x00050000 },
45-
{ 0x0004, 0x00000585 },
45+
AST_DRAMSTRUCT_INIT(DRAM_TYPE, 0x00000585),
4646
{ 0x0008, 0x0011030f },
4747
{ 0x0010, 0x22201724 },
4848
{ 0x0018, 0x1e29011a },
@@ -68,7 +68,7 @@ static const struct ast_dramstruct ast1100_dram_table_data[] = {
6868
{ 0x0078, 0x00000000 },
6969
{ 0x007C, 0x00000000 },
7070
{ 0x0034, 0x00000001 },
71-
{ 0xFF00, 0x00000043 },
71+
AST_DRAMSTRUCT_UDELAY(67u),
7272
{ 0x002C, 0x00000732 },
7373
{ 0x0030, 0x00000040 },
7474
{ 0x0028, 0x00000005 },
@@ -85,17 +85,17 @@ static const struct ast_dramstruct ast1100_dram_table_data[] = {
8585
{ 0x000C, 0x00005a21 },
8686
{ 0x0034, 0x00007c03 },
8787
{ 0x0120, 0x00004c41 },
88-
{ 0xffff, 0xffffffff },
88+
AST_DRAMSTRUCT_INVALID,
8989
};
9090

9191
static const struct ast_dramstruct ast2100_dram_table_data[] = {
9292
{ 0x2000, 0x1688a8a8 },
9393
{ 0x2020, 0x00004120 },
94-
{ 0xFF00, 0x00000043 },
94+
AST_DRAMSTRUCT_UDELAY(67u),
9595
{ 0x0000, 0xfc600309 },
9696
{ 0x006C, 0x00909090 },
9797
{ 0x0064, 0x00070000 },
98-
{ 0x0004, 0x00000489 },
98+
AST_DRAMSTRUCT_INIT(DRAM_TYPE, 0x00000489),
9999
{ 0x0008, 0x0011030f },
100100
{ 0x0010, 0x32302926 },
101101
{ 0x0018, 0x274c0122 },
@@ -121,7 +121,7 @@ static const struct ast_dramstruct ast2100_dram_table_data[] = {
121121
{ 0x0078, 0x00000000 },
122122
{ 0x007C, 0x00000000 },
123123
{ 0x0034, 0x00000001 },
124-
{ 0xFF00, 0x00000043 },
124+
AST_DRAMSTRUCT_UDELAY(67u),
125125
{ 0x002C, 0x00000942 },
126126
{ 0x0030, 0x00000040 },
127127
{ 0x0028, 0x00000005 },
@@ -138,7 +138,7 @@ static const struct ast_dramstruct ast2100_dram_table_data[] = {
138138
{ 0x000C, 0x00005a21 },
139139
{ 0x0034, 0x00007c03 },
140140
{ 0x0120, 0x00005061 },
141-
{ 0xffff, 0xffffffff },
141+
AST_DRAMSTRUCT_INVALID,
142142
};
143143

144144
/*
@@ -287,11 +287,11 @@ static void ast_post_chip_2100(struct ast_device *ast)
287287
;
288288
} while (ast_read32(ast, 0x10000) != 0x01);
289289

290-
while (dram_reg_info->index != 0xffff) {
291-
if (dram_reg_info->index == 0xff00) {/* delay fn */
290+
while (!AST_DRAMSTRUCT_IS(dram_reg_info, INVALID)) {
291+
if (AST_DRAMSTRUCT_IS(dram_reg_info, UDELAY)) {
292292
for (i = 0; i < 15; i++)
293293
udelay(dram_reg_info->data);
294-
} else if (dram_reg_info->index == 0x4) {
294+
} else if (AST_DRAMSTRUCT_IS(dram_reg_info, DRAM_TYPE)) {
295295
data = dram_reg_info->data;
296296
if (ast->dram_type == AST_DRAM_1Gx16)
297297
data = 0x00000d89;

drivers/gpu/drm/ast/ast_post.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifndef AST_POST_H
44
#define AST_POST_H
55

6+
#include <linux/limits.h>
67
#include <linux/types.h>
78

89
struct ast_device;
@@ -13,6 +14,27 @@ struct ast_dramstruct {
1314
u32 data;
1415
};
1516

17+
/* hardware fields */
18+
#define __AST_DRAMSTRUCT_DRAM_TYPE 0x0004
19+
20+
/* control commands */
21+
#define __AST_DRAMSTRUCT_UDELAY 0xff00
22+
#define __AST_DRAMSTRUCT_INVALID 0xffff
23+
24+
#define __AST_DRAMSTRUCT_INDEX(_name) \
25+
(__AST_DRAMSTRUCT_ ## _name)
26+
27+
#define AST_DRAMSTRUCT_INIT(_name, _value) \
28+
{ __AST_DRAMSTRUCT_INDEX(_name), (_value) }
29+
30+
#define AST_DRAMSTRUCT_UDELAY(_usecs) \
31+
AST_DRAMSTRUCT_INIT(UDELAY, _usecs)
32+
#define AST_DRAMSTRUCT_INVALID \
33+
AST_DRAMSTRUCT_INIT(INVALID, U32_MAX)
34+
35+
#define AST_DRAMSTRUCT_IS(_entry, _name) \
36+
((_entry)->index == __AST_DRAMSTRUCT_INDEX(_name))
37+
1638
u32 __ast_mindwm(void __iomem *regs, u32 r);
1739
void __ast_moutdwm(void __iomem *regs, u32 r, u32 v);
1840

0 commit comments

Comments
 (0)