1 From 924770877b5ec2917e3e3bcce1d3a8a1c20238b3 Mon Sep 17 00:00:00 2001
2 From: "Y.C. Chen" <yc_chen@aspeedtech.com>
3 Date: Thu, 22 Nov 2018 11:56:28 +0800
4 Subject: drm/ast: fixed reading monitor EDID not stable issue
6 [ Upstream commit 300625620314194d9e6d4f6dda71f2dc9cf62d9f ]
8 v1: over-sample data to increase the stability with some specific monitors
9 v2: refine to avoid infinite loop
10 v3: remove un-necessary "volatile" declaration
12 [airlied: fix two checkpatch warnings]
14 Signed-off-by: Y.C. Chen <yc_chen@aspeedtech.com>
15 Signed-off-by: Dave Airlie <airlied@redhat.com>
16 Link: https://patchwork.freedesktop.org/patch/msgid/1542858988-1127-1-git-send-email-yc_chen@aspeedtech.com
17 Signed-off-by: Sasha Levin <sashal@kernel.org>
19 drivers/gpu/drm/ast/ast_mode.c | 36 ++++++++++++++++++++++++++++------
20 1 file changed, 30 insertions(+), 6 deletions(-)
22 diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
23 index 57205016b04a..201874b96dd6 100644
24 --- a/drivers/gpu/drm/ast/ast_mode.c
25 +++ b/drivers/gpu/drm/ast/ast_mode.c
26 @@ -954,9 +954,21 @@ static int get_clock(void *i2c_priv)
28 struct ast_i2c_chan *i2c = i2c_priv;
29 struct ast_private *ast = i2c->dev->dev_private;
31 + uint32_t val, val2, count, pass;
35 + val = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4) & 0x01;
37 + val2 = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4) & 0x01;
42 + val = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4) & 0x01;
44 + } while ((pass < 5) && (count++ < 0x10000));
46 - val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4;
47 return val & 1 ? 1 : 0;
50 @@ -964,9 +976,21 @@ static int get_data(void *i2c_priv)
52 struct ast_i2c_chan *i2c = i2c_priv;
53 struct ast_private *ast = i2c->dev->dev_private;
55 + uint32_t val, val2, count, pass;
59 + val = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5) & 0x01;
61 + val2 = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5) & 0x01;
66 + val = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5) & 0x01;
68 + } while ((pass < 5) && (count++ < 0x10000));
70 - val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5;
71 return val & 1 ? 1 : 0;
74 @@ -979,7 +1003,7 @@ static void set_clock(void *i2c_priv, int clock)
76 for (i = 0; i < 0x10000; i++) {
77 ujcrb7 = ((clock & 0x01) ? 0 : 1);
78 - ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfe, ujcrb7);
79 + ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xf4, ujcrb7);
80 jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x01);
83 @@ -995,7 +1019,7 @@ static void set_data(void *i2c_priv, int data)
85 for (i = 0; i < 0x10000; i++) {
86 ujcrb7 = ((data & 0x01) ? 0 : 1) << 2;
87 - ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfb, ujcrb7);
88 + ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xf1, ujcrb7);
89 jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x04);