diff mbox

[6/9] drm/ast: Factor mmc_test code in POST code

Message ID 20170217053212.4839-6-benh@kernel.crashing.org (mailing list archive)
State New, archived
Headers show

Commit Message

Benjamin Herrenschmidt Feb. 17, 2017, 5:32 a.m. UTC
There's a lot of duplication for what's essentially N copies of
the same loop, so factor it. The upcoming AST2500 POST code adds
more of this.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 drivers/gpu/drm/ast/ast_post.c | 76 ++++++++++++------------------------------
 1 file changed, 22 insertions(+), 54 deletions(-)

Comments

Emil Velikov Feb. 18, 2017, 3:28 p.m. UTC | #1
On 17 February 2017 at 05:32, Benjamin Herrenschmidt
<benh@kernel.crashing.org> wrote:
> There's a lot of duplication for what's essentially N copies of
> the same loop, so factor it. The upcoming AST2500 POST code adds
> more of this.
>
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

Here is where things go fun:

Original code does the following data flexing only for the mmc_*test2
code, while this patch adds it to both test and test2.

       data = ast_mindwm(...);
       data = (data | (data >> 16)) & 0xffff;
//       ast_moutdwm(...);
       return data;

Afaict you have addressed that in the github branch/patch so things
are back to normal.
Tests are still a bit magical but not much you can/should do about it.

Regards,
Emil
Benjamin Herrenschmidt Feb. 18, 2017, 10:20 p.m. UTC | #2
On Sat, 2017-02-18 at 15:28 +0000, Emil Velikov wrote:
> Original code does the following data flexing only for the mmc_*test2
> code, while this patch adds it to both test and test2.
> 
>        data = ast_mindwm(...);
>        data = (data | (data >> 16)) & 0xffff;
> //       ast_moutdwm(...);
>        return data;

Actually that reading of the data isn't much of a problem from
my understanding of the spec, however it's the different exit
condition of the loop that could be.

Cheers,
Ben.
diff mbox

Patch

diff --git a/drivers/gpu/drm/ast/ast_post.c b/drivers/gpu/drm/ast/ast_post.c
index 7197635..33ea1ea 100644
--- a/drivers/gpu/drm/ast/ast_post.c
+++ b/drivers/gpu/drm/ast/ast_post.c
@@ -445,85 +445,53 @@  static const u32 pattern[8] = {
 	0x7C61D253
 };
 
-static int mmc_test_burst(struct ast_private *ast, u32 datagen)
+static int mmc_test(struct ast_private *ast, u32 datagen, u8 test_ctl)
 {
 	u32 data, timeout;
 
 	ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
-	ast_moutdwm(ast, 0x1e6e0070, 0x000000c1 | (datagen << 3));
+	ast_moutdwm(ast, 0x1e6e0070, (datagen << 3) | test_ctl);
 	timeout = 0;
 	do {
 		data = ast_mindwm(ast, 0x1e6e0070) & 0x3000;
 		if (data & 0x2000) {
-			return 0;
+			return -1;
 		}
 		if (++timeout > TIMEOUT) {
 			ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
-			return 0;
+			return -1;
 		}
 	} while (!data);
+	data = ast_mindwm(ast, 0x1e6e0078);
+	data = (data | (data >> 16)) & 0xffff;
 	ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
-	return 1;
+	return data;
 }
 
-static int mmc_test_burst2(struct ast_private *ast, u32 datagen)
+
+static int mmc_test_burst(struct ast_private *ast, u32 datagen)
 {
-	u32 data, timeout;
+	return mmc_test(ast, datagen, 0xc1);
+}
 
-	ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
-	ast_moutdwm(ast, 0x1e6e0070, 0x00000041 | (datagen << 3));
-	timeout = 0;
-	do {
-		data = ast_mindwm(ast, 0x1e6e0070) & 0x1000;
-		if (++timeout > TIMEOUT) {
-			ast_moutdwm(ast, 0x1e6e0070, 0x0);
-			return -1;
-		}
-	} while (!data);
-	data = ast_mindwm(ast, 0x1e6e0078);
-	data = (data | (data >> 16)) & 0xffff;
-	ast_moutdwm(ast, 0x1e6e0070, 0x0);
-	return data;
+static int mmc_test_burst2(struct ast_private *ast, u32 datagen)
+{
+	return mmc_test(ast, datagen, 0x41);
 }
 
 static int mmc_test_single(struct ast_private *ast, u32 datagen)
 {
-	u32 data, timeout;
-
-	ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
-	ast_moutdwm(ast, 0x1e6e0070, 0x000000c5 | (datagen << 3));
-	timeout = 0;
-	do {
-		data = ast_mindwm(ast, 0x1e6e0070) & 0x3000;
-		if (data & 0x2000)
-			return 0;
-		if (++timeout > TIMEOUT) {
-			ast_moutdwm(ast, 0x1e6e0070, 0x0);
-			return 0;
-		}
-	} while (!data);
-	ast_moutdwm(ast, 0x1e6e0070, 0x0);
-	return 1;
+	return mmc_test(ast, datagen, 0xc5);
 }
 
 static int mmc_test_single2(struct ast_private *ast, u32 datagen)
 {
-	u32 data, timeout;
+	return mmc_test(ast, datagen, 0x05);
+}
 
-	ast_moutdwm(ast, 0x1e6e0070, 0x00000000);
-	ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3));
-	timeout = 0;
-	do {
-		data = ast_mindwm(ast, 0x1e6e0070) & 0x1000;
-		if (++timeout > TIMEOUT) {
-			ast_moutdwm(ast, 0x1e6e0070, 0x0);
-			return -1;
-		}
-	} while (!data);
-	data = ast_mindwm(ast, 0x1e6e0078);
-	data = (data | (data >> 16)) & 0xffff;
-	ast_moutdwm(ast, 0x1e6e0070, 0x0);
-	return data;
+static int mmc_test_single_2500(struct ast_private *ast, u32 datagen)
+{
+	return mmc_test(ast, datagen, 0x85);
 }
 
 static int cbr_test(struct ast_private *ast)
@@ -603,9 +571,9 @@  static u32 cbr_scan2(struct ast_private *ast)
 
 static u32 cbr_test3(struct ast_private *ast)
 {
-	if (!mmc_test_burst(ast, 0))
+	if (mmc_test_burst(ast, 0) < 0)
 		return 0;
-	if (!mmc_test_single(ast, 0))
+	if (mmc_test_single(ast, 0) < 0)
 		return 0;
 	return 1;
 }