Skip to content

Commit 2000dda

Browse files
committed
drm/ast: astdp: Clean up EDID reading
Simplify ast_astdp_read_edid(). Rename register constants. Drop unnecessary error handling. On success, the helper returns 0; an error code otherwise. Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Jocelyn Falempe <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 2281475 commit 2000dda

File tree

2 files changed

+44
-61
lines changed

2 files changed

+44
-61
lines changed

drivers/gpu/drm/ast/ast_dp.c

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,55 @@ bool ast_astdp_is_connected(struct ast_device *ast)
1717
int ast_astdp_read_edid(struct drm_device *dev, u8 *ediddata)
1818
{
1919
struct ast_device *ast = to_ast_device(dev);
20-
u8 i = 0, j = 0;
20+
int ret = 0;
21+
u8 i;
2122

22-
/*
23-
* CRE5[b0]: Host reading EDID process is done
24-
*/
25-
if (!(ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xE5, ASTDP_HOST_EDID_READ_DONE_MASK)))
26-
goto err_astdp_edid_not_ready;
27-
28-
ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xE5, (u8) ~ASTDP_HOST_EDID_READ_DONE_MASK,
29-
0x00);
23+
/* Start reading EDID data */
24+
ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xe5, (u8)~AST_IO_VGACRE5_EDID_READ_DONE, 0x00);
3025

3126
for (i = 0; i < 32; i++) {
27+
unsigned int j;
28+
3229
/*
3330
* CRE4[7:0]: Read-Pointer for EDID (Unit: 4bytes); valid range: 0~64
3431
*/
35-
ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xE4,
36-
ASTDP_AND_CLEAR_MASK, (u8)i);
37-
j = 0;
32+
ast_set_index_reg(ast, AST_IO_VGACRI, 0xe4, i);
3833

3934
/*
4035
* CRD7[b0]: valid flag for EDID
4136
* CRD6[b0]: mirror read pointer for EDID
4237
*/
43-
while ((ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xD7,
44-
ASTDP_EDID_VALID_FLAG_MASK) != 0x01) ||
45-
(ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xD6,
46-
ASTDP_EDID_READ_POINTER_MASK) != i)) {
38+
for (j = 0; j < 200; ++j) {
39+
u8 vgacrd7, vgacrd6;
40+
4741
/*
4842
* Delay are getting longer with each retry.
49-
* 1. The Delays are often 2 loops when users request "Display Settings"
43+
*
44+
* 1. No delay on first try
45+
* 2. The Delays are often 2 loops when users request "Display Settings"
5046
* of right-click of mouse.
51-
* 2. The Delays are often longer a lot when system resume from S3/S4.
47+
* 3. The Delays are often longer a lot when system resume from S3/S4.
5248
*/
53-
mdelay(j+1);
54-
55-
j++;
56-
if (j > 200)
57-
goto err_astdp_jump_out_loop_of_edid;
49+
if (j)
50+
mdelay(j + 1);
51+
52+
/* Wait for EDID offset to show up in mirror register */
53+
vgacrd7 = ast_get_index_reg(ast, AST_IO_VGACRI, 0xd7);
54+
if (vgacrd7 & AST_IO_VGACRD7_EDID_VALID_FLAG) {
55+
vgacrd6 = ast_get_index_reg(ast, AST_IO_VGACRI, 0xd6);
56+
if (vgacrd6 == i)
57+
break;
58+
}
59+
}
60+
if (j == 200) {
61+
ret = -EBUSY;
62+
goto out;
5863
}
5964

60-
*(ediddata) = ast_get_index_reg_mask(ast, AST_IO_VGACRI,
61-
0xD8, ASTDP_EDID_READ_DATA_MASK);
62-
*(ediddata + 1) = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xD9,
63-
ASTDP_EDID_READ_DATA_MASK);
64-
*(ediddata + 2) = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xDA,
65-
ASTDP_EDID_READ_DATA_MASK);
66-
*(ediddata + 3) = ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xDB,
67-
ASTDP_EDID_READ_DATA_MASK);
65+
ediddata[0] = ast_get_index_reg(ast, AST_IO_VGACRI, 0xd8);
66+
ediddata[1] = ast_get_index_reg(ast, AST_IO_VGACRI, 0xd9);
67+
ediddata[2] = ast_get_index_reg(ast, AST_IO_VGACRI, 0xda);
68+
ediddata[3] = ast_get_index_reg(ast, AST_IO_VGACRI, 0xdb);
6869

6970
if (i == 31) {
7071
/*
@@ -76,29 +77,19 @@ int ast_astdp_read_edid(struct drm_device *dev, u8 *ediddata)
7677
* The Bytes-126 indicates the Number of extensions to
7778
* follow. 0 represents noextensions.
7879
*/
79-
*(ediddata + 3) = *(ediddata + 3) + *(ediddata + 2);
80-
*(ediddata + 2) = 0;
80+
ediddata[3] = ediddata[3] + ediddata[2];
81+
ediddata[2] = 0;
8182
}
8283

8384
ediddata += 4;
8485
}
8586

86-
ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xE5, (u8) ~ASTDP_HOST_EDID_READ_DONE_MASK,
87-
ASTDP_HOST_EDID_READ_DONE);
88-
89-
return 0;
90-
91-
err_astdp_jump_out_loop_of_edid:
92-
ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xE5,
93-
(u8) ~ASTDP_HOST_EDID_READ_DONE_MASK,
94-
ASTDP_HOST_EDID_READ_DONE);
95-
return (~(j+256) + 1);
96-
97-
err_astdp_edid_not_ready:
98-
if (!(ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xE5, ASTDP_HOST_EDID_READ_DONE_MASK)))
99-
return (~0xE5 + 1);
87+
out:
88+
/* Signal end of reading */
89+
ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xe5, (u8)~AST_IO_VGACRE5_EDID_READ_DONE,
90+
AST_IO_VGACRE5_EDID_READ_DONE);
10091

101-
return 0;
92+
return ret;
10293
}
10394

10495
/*
@@ -122,9 +113,9 @@ int ast_dp_launch(struct ast_device *ast)
122113
return -ENODEV;
123114
}
124115

125-
ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xE5,
126-
(u8) ~ASTDP_HOST_EDID_READ_DONE_MASK,
127-
ASTDP_HOST_EDID_READ_DONE);
116+
ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xe5,
117+
(u8) ~AST_IO_VGACRE5_EDID_READ_DONE,
118+
AST_IO_VGACRE5_EDID_READ_DONE);
128119

129120
return 0;
130121
}

drivers/gpu/drm/ast/ast_reg.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
#define AST_IO_VGACRCB_HWC_ENABLED BIT(1)
3939

4040
#define AST_IO_VGACRD1_MCU_FW_EXECUTING BIT(5)
41+
#define AST_IO_VGACRD7_EDID_VALID_FLAG BIT(0)
4142
#define AST_IO_VGACRDC_LINK_SUCCESS BIT(0)
4243
#define AST_IO_VGACRDF_HPD BIT(0)
44+
#define AST_IO_VGACRE5_EDID_READ_DONE BIT(0)
4345

4446
#define AST_IO_VGAIR1_R (0x5A)
4547
#define AST_IO_VGAIR1_VREFRESH BIT(3)
@@ -70,12 +72,6 @@
7072
#define AST_DP_PHY_SLEEP BIT(4)
7173
#define AST_DP_VIDEO_ENABLE BIT(0)
7274

73-
/*
74-
* CRE5[b0]: Host reading EDID process is done
75-
*/
76-
#define ASTDP_HOST_EDID_READ_DONE BIT(0)
77-
#define ASTDP_HOST_EDID_READ_DONE_MASK GENMASK(0, 0)
78-
7975
/*
8076
* CRDF[b4]: Mirror of AST_DP_VIDEO_ENABLE
8177
* Precondition: A. ~AST_DP_PHY_SLEEP &&
@@ -84,10 +80,6 @@
8480
*/
8581
#define ASTDP_MIRROR_VIDEO_ENABLE BIT(4)
8682

87-
#define ASTDP_EDID_READ_POINTER_MASK GENMASK(7, 0)
88-
#define ASTDP_EDID_VALID_FLAG_MASK GENMASK(0, 0)
89-
#define ASTDP_EDID_READ_DATA_MASK GENMASK(7, 0)
90-
9183
/*
9284
* ASTDP setmode registers:
9385
* CRE0[7:0]: MISC0 ((0x00: 18-bpp) or (0x20: 24-bpp)

0 commit comments

Comments
 (0)