diff options
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spi-loopback-test.c | 55 | ||||
-rw-r--r-- | drivers/spi/spi-test.h | 19 |
2 files changed, 26 insertions, 48 deletions
diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c index 85c0c4e391d9..6df6dddc2890 100644 --- a/drivers/spi/spi-loopback-test.c +++ b/drivers/spi/spi-loopback-test.c | |||
@@ -63,9 +63,9 @@ static struct spi_test spi_tests[] = { | |||
63 | .iterate_len = { ITERATE_MAX_LEN }, | 63 | .iterate_len = { ITERATE_MAX_LEN }, |
64 | .iterate_tx_align = ITERATE_ALIGN, | 64 | .iterate_tx_align = ITERATE_ALIGN, |
65 | .iterate_rx_align = ITERATE_ALIGN, | 65 | .iterate_rx_align = ITERATE_ALIGN, |
66 | .transfer_count = 1, | ||
66 | .transfers = { | 67 | .transfers = { |
67 | { | 68 | { |
68 | .len = 1, | ||
69 | .tx_buf = TX(0), | 69 | .tx_buf = TX(0), |
70 | .rx_buf = RX(0), | 70 | .rx_buf = RX(0), |
71 | }, | 71 | }, |
@@ -77,9 +77,9 @@ static struct spi_test spi_tests[] = { | |||
77 | .iterate_len = { ITERATE_MAX_LEN }, | 77 | .iterate_len = { ITERATE_MAX_LEN }, |
78 | .iterate_tx_align = ITERATE_ALIGN, | 78 | .iterate_tx_align = ITERATE_ALIGN, |
79 | .iterate_rx_align = ITERATE_ALIGN, | 79 | .iterate_rx_align = ITERATE_ALIGN, |
80 | .transfer_count = 1, | ||
80 | .transfers = { | 81 | .transfers = { |
81 | { | 82 | { |
82 | .len = 1, | ||
83 | .tx_buf = TX(PAGE_SIZE - 4), | 83 | .tx_buf = TX(PAGE_SIZE - 4), |
84 | .rx_buf = RX(PAGE_SIZE - 4), | 84 | .rx_buf = RX(PAGE_SIZE - 4), |
85 | }, | 85 | }, |
@@ -90,9 +90,9 @@ static struct spi_test spi_tests[] = { | |||
90 | .fill_option = FILL_COUNT_8, | 90 | .fill_option = FILL_COUNT_8, |
91 | .iterate_len = { ITERATE_MAX_LEN }, | 91 | .iterate_len = { ITERATE_MAX_LEN }, |
92 | .iterate_tx_align = ITERATE_ALIGN, | 92 | .iterate_tx_align = ITERATE_ALIGN, |
93 | .transfer_count = 1, | ||
93 | .transfers = { | 94 | .transfers = { |
94 | { | 95 | { |
95 | .len = 1, | ||
96 | .tx_buf = TX(0), | 96 | .tx_buf = TX(0), |
97 | }, | 97 | }, |
98 | }, | 98 | }, |
@@ -102,9 +102,9 @@ static struct spi_test spi_tests[] = { | |||
102 | .fill_option = FILL_COUNT_8, | 102 | .fill_option = FILL_COUNT_8, |
103 | .iterate_len = { ITERATE_MAX_LEN }, | 103 | .iterate_len = { ITERATE_MAX_LEN }, |
104 | .iterate_rx_align = ITERATE_ALIGN, | 104 | .iterate_rx_align = ITERATE_ALIGN, |
105 | .transfer_count = 1, | ||
105 | .transfers = { | 106 | .transfers = { |
106 | { | 107 | { |
107 | .len = 1, | ||
108 | .rx_buf = RX(0), | 108 | .rx_buf = RX(0), |
109 | }, | 109 | }, |
110 | }, | 110 | }, |
@@ -115,13 +115,12 @@ static struct spi_test spi_tests[] = { | |||
115 | .iterate_len = { ITERATE_LEN }, | 115 | .iterate_len = { ITERATE_LEN }, |
116 | .iterate_tx_align = ITERATE_ALIGN, | 116 | .iterate_tx_align = ITERATE_ALIGN, |
117 | .iterate_transfer_mask = BIT(0) | BIT(1), | 117 | .iterate_transfer_mask = BIT(0) | BIT(1), |
118 | .transfer_count = 2, | ||
118 | .transfers = { | 119 | .transfers = { |
119 | { | 120 | { |
120 | .len = 1, | ||
121 | .tx_buf = TX(0), | 121 | .tx_buf = TX(0), |
122 | }, | 122 | }, |
123 | { | 123 | { |
124 | .len = 1, | ||
125 | /* this is why we cant use ITERATE_MAX_LEN */ | 124 | /* this is why we cant use ITERATE_MAX_LEN */ |
126 | .tx_buf = TX(SPI_TEST_MAX_SIZE_HALF), | 125 | .tx_buf = TX(SPI_TEST_MAX_SIZE_HALF), |
127 | }, | 126 | }, |
@@ -133,9 +132,9 @@ static struct spi_test spi_tests[] = { | |||
133 | .iterate_len = { ITERATE_MAX_LEN }, | 132 | .iterate_len = { ITERATE_MAX_LEN }, |
134 | .iterate_tx_align = ITERATE_ALIGN, | 133 | .iterate_tx_align = ITERATE_ALIGN, |
135 | .iterate_transfer_mask = BIT(0), | 134 | .iterate_transfer_mask = BIT(0), |
135 | .transfer_count = 2, | ||
136 | .transfers = { | 136 | .transfers = { |
137 | { | 137 | { |
138 | .len = 1, | ||
139 | .tx_buf = TX(64), | 138 | .tx_buf = TX(64), |
140 | }, | 139 | }, |
141 | { | 140 | { |
@@ -150,13 +149,13 @@ static struct spi_test spi_tests[] = { | |||
150 | .iterate_len = { ITERATE_MAX_LEN }, | 149 | .iterate_len = { ITERATE_MAX_LEN }, |
151 | .iterate_tx_align = ITERATE_ALIGN, | 150 | .iterate_tx_align = ITERATE_ALIGN, |
152 | .iterate_transfer_mask = BIT(1), | 151 | .iterate_transfer_mask = BIT(1), |
152 | .transfer_count = 2, | ||
153 | .transfers = { | 153 | .transfers = { |
154 | { | 154 | { |
155 | .len = 16, | 155 | .len = 16, |
156 | .tx_buf = TX(0), | 156 | .tx_buf = TX(0), |
157 | }, | 157 | }, |
158 | { | 158 | { |
159 | .len = 1, | ||
160 | .tx_buf = TX(64), | 159 | .tx_buf = TX(64), |
161 | }, | 160 | }, |
162 | }, | 161 | }, |
@@ -167,13 +166,12 @@ static struct spi_test spi_tests[] = { | |||
167 | .iterate_len = { ITERATE_MAX_LEN }, | 166 | .iterate_len = { ITERATE_MAX_LEN }, |
168 | .iterate_tx_align = ITERATE_ALIGN, | 167 | .iterate_tx_align = ITERATE_ALIGN, |
169 | .iterate_transfer_mask = BIT(0) | BIT(1), | 168 | .iterate_transfer_mask = BIT(0) | BIT(1), |
169 | .transfer_count = 2, | ||
170 | .transfers = { | 170 | .transfers = { |
171 | { | 171 | { |
172 | .len = 1, | ||
173 | .tx_buf = TX(0), | 172 | .tx_buf = TX(0), |
174 | }, | 173 | }, |
175 | { | 174 | { |
176 | .len = 1, | ||
177 | .rx_buf = RX(0), | 175 | .rx_buf = RX(0), |
178 | }, | 176 | }, |
179 | }, | 177 | }, |
@@ -184,9 +182,9 @@ static struct spi_test spi_tests[] = { | |||
184 | .iterate_len = { ITERATE_MAX_LEN }, | 182 | .iterate_len = { ITERATE_MAX_LEN }, |
185 | .iterate_tx_align = ITERATE_ALIGN, | 183 | .iterate_tx_align = ITERATE_ALIGN, |
186 | .iterate_transfer_mask = BIT(0), | 184 | .iterate_transfer_mask = BIT(0), |
185 | .transfer_count = 2, | ||
187 | .transfers = { | 186 | .transfers = { |
188 | { | 187 | { |
189 | .len = 1, | ||
190 | .tx_buf = TX(0), | 188 | .tx_buf = TX(0), |
191 | }, | 189 | }, |
192 | { | 190 | { |
@@ -201,13 +199,13 @@ static struct spi_test spi_tests[] = { | |||
201 | .iterate_len = { ITERATE_MAX_LEN }, | 199 | .iterate_len = { ITERATE_MAX_LEN }, |
202 | .iterate_tx_align = ITERATE_ALIGN, | 200 | .iterate_tx_align = ITERATE_ALIGN, |
203 | .iterate_transfer_mask = BIT(1), | 201 | .iterate_transfer_mask = BIT(1), |
202 | .transfer_count = 2, | ||
204 | .transfers = { | 203 | .transfers = { |
205 | { | 204 | { |
206 | .len = 1, | 205 | .len = 1, |
207 | .tx_buf = TX(0), | 206 | .tx_buf = TX(0), |
208 | }, | 207 | }, |
209 | { | 208 | { |
210 | .len = 1, | ||
211 | .rx_buf = RX(0), | 209 | .rx_buf = RX(0), |
212 | }, | 210 | }, |
213 | }, | 211 | }, |
@@ -218,14 +216,13 @@ static struct spi_test spi_tests[] = { | |||
218 | .iterate_len = { ITERATE_LEN }, | 216 | .iterate_len = { ITERATE_LEN }, |
219 | .iterate_tx_align = ITERATE_ALIGN, | 217 | .iterate_tx_align = ITERATE_ALIGN, |
220 | .iterate_transfer_mask = BIT(0) | BIT(1), | 218 | .iterate_transfer_mask = BIT(0) | BIT(1), |
219 | .transfer_count = 2, | ||
221 | .transfers = { | 220 | .transfers = { |
222 | { | 221 | { |
223 | .len = 1, | ||
224 | .tx_buf = TX(0), | 222 | .tx_buf = TX(0), |
225 | .rx_buf = RX(0), | 223 | .rx_buf = RX(0), |
226 | }, | 224 | }, |
227 | { | 225 | { |
228 | .len = 1, | ||
229 | /* making sure we align without overwrite | 226 | /* making sure we align without overwrite |
230 | * the reason we can not use ITERATE_MAX_LEN | 227 | * the reason we can not use ITERATE_MAX_LEN |
231 | */ | 228 | */ |
@@ -240,9 +237,9 @@ static struct spi_test spi_tests[] = { | |||
240 | .iterate_len = { ITERATE_MAX_LEN }, | 237 | .iterate_len = { ITERATE_MAX_LEN }, |
241 | .iterate_tx_align = ITERATE_ALIGN, | 238 | .iterate_tx_align = ITERATE_ALIGN, |
242 | .iterate_transfer_mask = BIT(0), | 239 | .iterate_transfer_mask = BIT(0), |
240 | .transfer_count = 2, | ||
243 | .transfers = { | 241 | .transfers = { |
244 | { | 242 | { |
245 | .len = 1, | ||
246 | /* making sure we align without overwrite */ | 243 | /* making sure we align without overwrite */ |
247 | .tx_buf = TX(1024), | 244 | .tx_buf = TX(1024), |
248 | .rx_buf = RX(1024), | 245 | .rx_buf = RX(1024), |
@@ -261,6 +258,7 @@ static struct spi_test spi_tests[] = { | |||
261 | .iterate_len = { ITERATE_MAX_LEN }, | 258 | .iterate_len = { ITERATE_MAX_LEN }, |
262 | .iterate_tx_align = ITERATE_ALIGN, | 259 | .iterate_tx_align = ITERATE_ALIGN, |
263 | .iterate_transfer_mask = BIT(1), | 260 | .iterate_transfer_mask = BIT(1), |
261 | .transfer_count = 2, | ||
264 | .transfers = { | 262 | .transfers = { |
265 | { | 263 | { |
266 | .len = 1, | 264 | .len = 1, |
@@ -268,7 +266,6 @@ static struct spi_test spi_tests[] = { | |||
268 | .rx_buf = RX(0), | 266 | .rx_buf = RX(0), |
269 | }, | 267 | }, |
270 | { | 268 | { |
271 | .len = 1, | ||
272 | /* making sure we align without overwrite */ | 269 | /* making sure we align without overwrite */ |
273 | .tx_buf = TX(1024), | 270 | .tx_buf = TX(1024), |
274 | .rx_buf = RX(1024), | 271 | .rx_buf = RX(1024), |
@@ -503,7 +500,7 @@ static int spi_test_check_loopback_result(struct spi_device *spi, | |||
503 | /* if applicable to transfer check that rx_buf is equal to tx_buf */ | 500 | /* if applicable to transfer check that rx_buf is equal to tx_buf */ |
504 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { | 501 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { |
505 | /* if there is no rx, then no check is needed */ | 502 | /* if there is no rx, then no check is needed */ |
506 | if (!xfer->rx_buf) | 503 | if (!xfer->len || !xfer->rx_buf) |
507 | continue; | 504 | continue; |
508 | /* so depending on tx_buf we need to handle things */ | 505 | /* so depending on tx_buf we need to handle things */ |
509 | if (xfer->tx_buf) { | 506 | if (xfer->tx_buf) { |
@@ -745,15 +742,6 @@ static int spi_test_run_iter(struct spi_device *spi, | |||
745 | /* copy the test template to test */ | 742 | /* copy the test template to test */ |
746 | memcpy(&test, testtemplate, sizeof(test)); | 743 | memcpy(&test, testtemplate, sizeof(test)); |
747 | 744 | ||
748 | /* set up test->transfers to the correct count */ | ||
749 | if (!test.transfer_count) { | ||
750 | for (i = 0; | ||
751 | (i < SPI_TEST_MAX_TRANSFERS) && test.transfers[i].len; | ||
752 | i++) { | ||
753 | test.transfer_count++; | ||
754 | } | ||
755 | } | ||
756 | |||
757 | /* if iterate_transfer_mask is not set, | 745 | /* if iterate_transfer_mask is not set, |
758 | * then set it to first transfer only | 746 | * then set it to first transfer only |
759 | */ | 747 | */ |
@@ -799,8 +787,7 @@ static int spi_test_run_iter(struct spi_device *spi, | |||
799 | /* only when bit in transfer mask is set */ | 787 | /* only when bit in transfer mask is set */ |
800 | if (!(test.iterate_transfer_mask & BIT(i))) | 788 | if (!(test.iterate_transfer_mask & BIT(i))) |
801 | continue; | 789 | continue; |
802 | if (len) | 790 | test.transfers[i].len = len; |
803 | test.transfers[i].len = len; | ||
804 | if (test.transfers[i].tx_buf) | 791 | if (test.transfers[i].tx_buf) |
805 | test.transfers[i].tx_buf += tx_off; | 792 | test.transfers[i].tx_buf += tx_off; |
806 | if (test.transfers[i].tx_buf) | 793 | if (test.transfers[i].tx_buf) |
@@ -910,15 +897,6 @@ int spi_test_run_test(struct spi_device *spi, const struct spi_test *test, | |||
910 | /* iterate over all the iterable values using macros | 897 | /* iterate over all the iterable values using macros |
911 | * (to make it a bit more readable... | 898 | * (to make it a bit more readable... |
912 | */ | 899 | */ |
913 | #define FOR_EACH_ITERATE(var, defaultvalue) \ | ||
914 | for (idx_##var = -1, var = defaultvalue; \ | ||
915 | ((idx_##var < 0) || \ | ||
916 | ( \ | ||
917 | (idx_##var < SPI_TEST_MAX_ITERATE) && \ | ||
918 | (var = test->iterate_##var[idx_##var]) \ | ||
919 | ) \ | ||
920 | ); \ | ||
921 | idx_##var++) | ||
922 | #define FOR_EACH_ALIGNMENT(var) \ | 900 | #define FOR_EACH_ALIGNMENT(var) \ |
923 | for (var = 0; \ | 901 | for (var = 0; \ |
924 | var < (test->iterate_##var ? \ | 902 | var < (test->iterate_##var ? \ |
@@ -928,7 +906,8 @@ int spi_test_run_test(struct spi_device *spi, const struct spi_test *test, | |||
928 | 1); \ | 906 | 1); \ |
929 | var++) | 907 | var++) |
930 | 908 | ||
931 | FOR_EACH_ITERATE(len, 0) { | 909 | for (idx_len = 0; idx_len < SPI_TEST_MAX_ITERATE && |
910 | (len = test->iterate_len[idx_len]) != -1; idx_len++) { | ||
932 | FOR_EACH_ALIGNMENT(tx_align) { | 911 | FOR_EACH_ALIGNMENT(tx_align) { |
933 | FOR_EACH_ALIGNMENT(rx_align) { | 912 | FOR_EACH_ALIGNMENT(rx_align) { |
934 | /* and run the iteration */ | 913 | /* and run the iteration */ |
diff --git a/drivers/spi/spi-test.h b/drivers/spi/spi-test.h index 922c52833239..2dd569138880 100644 --- a/drivers/spi/spi-test.h +++ b/drivers/spi/spi-test.h | |||
@@ -48,9 +48,8 @@ | |||
48 | * | 48 | * |
49 | * @msg: a template @spi_message usedfor the default settings | 49 | * @msg: a template @spi_message usedfor the default settings |
50 | * @transfers: array of @spi_transfers that are part of the | 50 | * @transfers: array of @spi_transfers that are part of the |
51 | * resulting spi_message. The first transfer with len == 0 | 51 | * resulting spi_message. |
52 | * signifies the end of the list | 52 | * @transfer_count: number of transfers |
53 | * @transfer_count: normally computed number of transfers with len > 0 | ||
54 | * | 53 | * |
55 | * @run_test: run a specific spi_test - this allows to override | 54 | * @run_test: run a specific spi_test - this allows to override |
56 | * the default implementation of @spi_test_run_transfer | 55 | * the default implementation of @spi_test_run_transfer |
@@ -62,8 +61,7 @@ | |||
62 | * @expected_return: the expected return code - in some cases we want to | 61 | * @expected_return: the expected return code - in some cases we want to |
63 | * test also for error conditions | 62 | * test also for error conditions |
64 | * | 63 | * |
65 | * @iterate_len: list of length to iterate on (in addition to the | 64 | * @iterate_len: list of length to iterate on |
66 | * explicitly set @spi_transfer.len) | ||
67 | * @iterate_tx_align: change the alignment of @spi_transfer.tx_buf | 65 | * @iterate_tx_align: change the alignment of @spi_transfer.tx_buf |
68 | * for all values in the below range if set. | 66 | * for all values in the below range if set. |
69 | * the ranges are: | 67 | * the ranges are: |
@@ -89,7 +87,7 @@ struct spi_test { | |||
89 | int (*execute_msg)(struct spi_device *spi, struct spi_test *test, | 87 | int (*execute_msg)(struct spi_device *spi, struct spi_test *test, |
90 | void *tx, void *rx); | 88 | void *tx, void *rx); |
91 | int expected_return; | 89 | int expected_return; |
92 | /* iterate over all the non-zero values */ | 90 | /* iterate over all values, terminated by a -1 */ |
93 | int iterate_len[SPI_TEST_MAX_ITERATE]; | 91 | int iterate_len[SPI_TEST_MAX_ITERATE]; |
94 | int iterate_tx_align; | 92 | int iterate_tx_align; |
95 | int iterate_rx_align; | 93 | int iterate_rx_align; |
@@ -126,11 +124,12 @@ int spi_test_execute_msg(struct spi_device *spi, | |||
126 | int spi_test_run_tests(struct spi_device *spi, | 124 | int spi_test_run_tests(struct spi_device *spi, |
127 | struct spi_test *tests); | 125 | struct spi_test *tests); |
128 | 126 | ||
129 | /* some of the default @spi_transfer.len to test */ | 127 | #define ITERATE_LEN_LIST 1, 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \ |
130 | #define ITERATE_LEN 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \ | ||
131 | 1021, 1024, 1031, 4093, PAGE_SIZE, 4099, 65536, 65537 | 128 | 1021, 1024, 1031, 4093, PAGE_SIZE, 4099, 65536, 65537 |
132 | 129 | /* some of the default @spi_transfer.len to test, terminated by a -1 */ | |
133 | #define ITERATE_MAX_LEN ITERATE_LEN, SPI_TEST_MAX_SIZE - 1, SPI_TEST_MAX_SIZE | 130 | #define ITERATE_LEN ITERATE_LEN_LIST, -1 |
131 | #define ITERATE_MAX_LEN ITERATE_LEN_LIST, (SPI_TEST_MAX_SIZE - 1), \ | ||
132 | SPI_TEST_MAX_SIZE, -1 | ||
134 | 133 | ||
135 | /* the default alignment to test */ | 134 | /* the default alignment to test */ |
136 | #define ITERATE_ALIGN sizeof(int) | 135 | #define ITERATE_ALIGN sizeof(int) |