Joel Stanley | e50183f | 2017-02-28 12:17:46 +1030 | [diff] [blame] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Benjamin Herrenschmidt <benh@kernel.crashing.org> |
| 3 | Date: Sat, 18 Feb 2017 14:19:10 +1100 |
Joel Stanley | 8d5acef | 2017-03-15 16:24:09 +1030 | [diff] [blame] | 4 | Subject: [PATCH 08/12] drm/ast: Factor mmc_test code in POST code |
Joel Stanley | e50183f | 2017-02-28 12:17:46 +1030 | [diff] [blame] | 5 | |
| 6 | There's a some duplication for what's essentially copies of |
| 7 | two loops, so factor it. The upcoming AST2500 POST code adds |
| 8 | more of them. Also cleanup return types for the test functions, |
| 9 | most of them return a boolean, some return a u32. |
| 10 | |
| 11 | Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> |
| 12 | -- |
| 13 | |
| 14 | v2. - Keep the split between the "test" and "test2" functions |
| 15 | as they have a different exit condition in the loop and |
| 16 | a different return type. |
| 17 | - Fix the return types accross the call chain |
| 18 | |
| 19 | Signed-off-by: Joel Stanley <joel@jms.id.au> |
| 20 | --- |
| 21 | drivers/gpu/drm/ast/ast_post.c | 82 ++++++++++++++++-------------------------- |
| 22 | 1 file changed, 31 insertions(+), 51 deletions(-) |
| 23 | |
| 24 | diff --git a/drivers/gpu/drm/ast/ast_post.c b/drivers/gpu/drm/ast/ast_post.c |
Joel Stanley | 8d5acef | 2017-03-15 16:24:09 +1030 | [diff] [blame] | 25 | index 5b7db846a2c1..89b09d60b2be 100644 |
Joel Stanley | e50183f | 2017-02-28 12:17:46 +1030 | [diff] [blame] | 26 | --- a/drivers/gpu/drm/ast/ast_post.c |
| 27 | +++ b/drivers/gpu/drm/ast/ast_post.c |
Joel Stanley | 8d5acef | 2017-03-15 16:24:09 +1030 | [diff] [blame] | 28 | @@ -441,85 +441,65 @@ static const u32 pattern[8] = { |
Joel Stanley | e50183f | 2017-02-28 12:17:46 +1030 | [diff] [blame] | 29 | 0x7C61D253 |
| 30 | }; |
| 31 | |
| 32 | -static int mmc_test_burst(struct ast_private *ast, u32 datagen) |
| 33 | +static bool mmc_test(struct ast_private *ast, u32 datagen, u8 test_ctl) |
| 34 | { |
| 35 | u32 data, timeout; |
| 36 | |
| 37 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 38 | - ast_moutdwm(ast, 0x1e6e0070, 0x000000c1 | (datagen << 3)); |
| 39 | + ast_moutdwm(ast, 0x1e6e0070, (datagen << 3) | test_ctl); |
| 40 | timeout = 0; |
| 41 | do { |
| 42 | data = ast_mindwm(ast, 0x1e6e0070) & 0x3000; |
| 43 | - if (data & 0x2000) { |
| 44 | - return 0; |
| 45 | - } |
| 46 | + if (data & 0x2000) |
| 47 | + return false; |
| 48 | if (++timeout > TIMEOUT) { |
| 49 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 50 | - return 0; |
| 51 | + return false; |
| 52 | } |
| 53 | } while (!data); |
| 54 | - ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 55 | - return 1; |
| 56 | + ast_moutdwm(ast, 0x1e6e0070, 0x0); |
| 57 | + return true; |
| 58 | } |
| 59 | |
| 60 | -static int mmc_test_burst2(struct ast_private *ast, u32 datagen) |
| 61 | +static u32 mmc_test2(struct ast_private *ast, u32 datagen, u8 test_ctl) |
| 62 | { |
| 63 | u32 data, timeout; |
| 64 | |
| 65 | ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 66 | - ast_moutdwm(ast, 0x1e6e0070, 0x00000041 | (datagen << 3)); |
| 67 | + ast_moutdwm(ast, 0x1e6e0070, (datagen << 3) | test_ctl); |
| 68 | timeout = 0; |
| 69 | do { |
| 70 | data = ast_mindwm(ast, 0x1e6e0070) & 0x1000; |
| 71 | if (++timeout > TIMEOUT) { |
| 72 | ast_moutdwm(ast, 0x1e6e0070, 0x0); |
| 73 | - return -1; |
| 74 | + return 0xffffffff; |
| 75 | } |
| 76 | } while (!data); |
| 77 | data = ast_mindwm(ast, 0x1e6e0078); |
| 78 | data = (data | (data >> 16)) & 0xffff; |
| 79 | - ast_moutdwm(ast, 0x1e6e0070, 0x0); |
| 80 | + ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 81 | return data; |
| 82 | } |
| 83 | |
| 84 | -static int mmc_test_single(struct ast_private *ast, u32 datagen) |
| 85 | + |
| 86 | +static bool mmc_test_burst(struct ast_private *ast, u32 datagen) |
| 87 | { |
| 88 | - u32 data, timeout; |
| 89 | + return mmc_test(ast, datagen, 0xc1); |
| 90 | +} |
| 91 | |
| 92 | - ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 93 | - ast_moutdwm(ast, 0x1e6e0070, 0x000000c5 | (datagen << 3)); |
| 94 | - timeout = 0; |
| 95 | - do { |
| 96 | - data = ast_mindwm(ast, 0x1e6e0070) & 0x3000; |
| 97 | - if (data & 0x2000) |
| 98 | - return 0; |
| 99 | - if (++timeout > TIMEOUT) { |
| 100 | - ast_moutdwm(ast, 0x1e6e0070, 0x0); |
| 101 | - return 0; |
| 102 | - } |
| 103 | - } while (!data); |
| 104 | - ast_moutdwm(ast, 0x1e6e0070, 0x0); |
| 105 | - return 1; |
| 106 | +static u32 mmc_test_burst2(struct ast_private *ast, u32 datagen) |
| 107 | +{ |
| 108 | + return mmc_test2(ast, datagen, 0x41); |
| 109 | } |
| 110 | |
| 111 | -static int mmc_test_single2(struct ast_private *ast, u32 datagen) |
| 112 | +static bool mmc_test_single(struct ast_private *ast, u32 datagen) |
| 113 | { |
| 114 | - u32 data, timeout; |
| 115 | + return mmc_test(ast, datagen, 0xc5); |
| 116 | +} |
| 117 | |
| 118 | - ast_moutdwm(ast, 0x1e6e0070, 0x00000000); |
| 119 | - ast_moutdwm(ast, 0x1e6e0070, 0x00000005 | (datagen << 3)); |
| 120 | - timeout = 0; |
| 121 | - do { |
| 122 | - data = ast_mindwm(ast, 0x1e6e0070) & 0x1000; |
| 123 | - if (++timeout > TIMEOUT) { |
| 124 | - ast_moutdwm(ast, 0x1e6e0070, 0x0); |
| 125 | - return -1; |
| 126 | - } |
| 127 | - } while (!data); |
| 128 | - data = ast_mindwm(ast, 0x1e6e0078); |
| 129 | - data = (data | (data >> 16)) & 0xffff; |
| 130 | - ast_moutdwm(ast, 0x1e6e0070, 0x0); |
| 131 | - return data; |
| 132 | +static u32 mmc_test_single2(struct ast_private *ast, u32 datagen) |
| 133 | +{ |
| 134 | + return mmc_test2(ast, datagen, 0x05); |
| 135 | } |
| 136 | |
| 137 | static int cbr_test(struct ast_private *ast) |
Joel Stanley | 8d5acef | 2017-03-15 16:24:09 +1030 | [diff] [blame] | 138 | @@ -597,16 +577,16 @@ static u32 cbr_scan2(struct ast_private *ast) |
Joel Stanley | e50183f | 2017-02-28 12:17:46 +1030 | [diff] [blame] | 139 | return data2; |
| 140 | } |
| 141 | |
| 142 | -static u32 cbr_test3(struct ast_private *ast) |
| 143 | +static bool cbr_test3(struct ast_private *ast) |
| 144 | { |
| 145 | if (!mmc_test_burst(ast, 0)) |
| 146 | - return 0; |
| 147 | + return false; |
| 148 | if (!mmc_test_single(ast, 0)) |
| 149 | - return 0; |
| 150 | - return 1; |
| 151 | + return false; |
| 152 | + return true; |
| 153 | } |
| 154 | |
| 155 | -static u32 cbr_scan3(struct ast_private *ast) |
| 156 | +static bool cbr_scan3(struct ast_private *ast) |
| 157 | { |
| 158 | u32 patcnt, loop; |
| 159 | |
Joel Stanley | 8d5acef | 2017-03-15 16:24:09 +1030 | [diff] [blame] | 160 | @@ -617,9 +597,9 @@ static u32 cbr_scan3(struct ast_private *ast) |
Joel Stanley | e50183f | 2017-02-28 12:17:46 +1030 | [diff] [blame] | 161 | break; |
| 162 | } |
| 163 | if (loop == 2) |
| 164 | - return 0; |
| 165 | + return false; |
| 166 | } |
| 167 | - return 1; |
| 168 | + return true; |
| 169 | } |
| 170 | |
| 171 | static bool finetuneDQI_L(struct ast_private *ast, struct ast2300_dram_param *param) |
| 172 | -- |
| 173 | 2.11.0 |
| 174 | |