@@ -17,54 +17,55 @@ bool ast_astdp_is_connected(struct ast_device *ast)
1717int 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}
0 commit comments