blob: 6ed7b899da8a7e75914b375cffbd455a9bb0ad13 [file] [log] [blame]
Martin Sperl84e0c4e2015-11-27 13:56:04 +00001/*
2 * linux/drivers/spi/spi-test.h
3 *
4 * (c) Martin Sperl <kernel@martin.sperl.org>
5 *
6 * spi_test definitions
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#include <linux/spi/spi.h>
20
21#define SPI_TEST_MAX_TRANSFERS 4
22#define SPI_TEST_MAX_SIZE (32 * PAGE_SIZE)
Martin Sperl739f3e92015-12-13 09:46:25 +000023#define SPI_TEST_MAX_ITERATE 32
Martin Sperl84e0c4e2015-11-27 13:56:04 +000024
25/* the "dummy" start addresses used in spi_test
26 * these addresses get translated at a later stage
27 */
28#define RX_START BIT(30)
29#define TX_START BIT(31)
30#define RX(off) ((void *)(RX_START + off))
31#define TX(off) ((void *)(TX_START + off))
32
33/* some special defines for offsets */
34#define SPI_TEST_MAX_SIZE_HALF BIT(29)
35
36/* detection pattern for unfinished reads...
37 * - 0x00 or 0xff could be valid levels for tx_buf = NULL,
38 * so we do not use either of them
39 */
40#define SPI_TEST_PATTERN_UNWRITTEN 0xAA
41#define SPI_TEST_PATTERN_DO_NOT_WRITE 0x55
42#define SPI_TEST_CHECK_DO_NOT_WRITE 64
43
44/**
45 * struct spi_test - describes a specific (set of) tests to execute
46 *
47 * @description: description of the test
48 *
49 * @msg: a template @spi_message usedfor the default settings
50 * @transfers: array of @spi_transfers that are part of the
Akinobu Mita89166712017-03-18 03:17:28 +090051 * resulting spi_message.
52 * @transfer_count: number of transfers
Martin Sperl84e0c4e2015-11-27 13:56:04 +000053 *
54 * @run_test: run a specific spi_test - this allows to override
55 * the default implementation of @spi_test_run_transfer
56 * either to add some custom filters for a specific test
57 * or to effectively run some very custom tests...
58 * @execute_msg: run the spi_message for real - this allows to override
59 * @spi_test_execute_msg to apply final modifications
60 * on the spi_message
61 * @expected_return: the expected return code - in some cases we want to
62 * test also for error conditions
63 *
Akinobu Mita89166712017-03-18 03:17:28 +090064 * @iterate_len: list of length to iterate on
Martin Sperl84e0c4e2015-11-27 13:56:04 +000065 * @iterate_tx_align: change the alignment of @spi_transfer.tx_buf
66 * for all values in the below range if set.
67 * the ranges are:
68 * [0 : @spi_master.dma_alignment[ if set
69 * [0 : iterate_tx_align[ if unset
70 * @iterate_rx_align: change the alignment of @spi_transfer.rx_buf
71 * see @iterate_tx_align for details
72 * @iterate_transfer_mask: the bitmask of transfers to which the iterations
73 * apply - if 0, then it applies to all transfer
74 *
75 * @fill_option: define the way how tx_buf is filled
76 * @fill_pattern: fill pattern to apply to the tx_buf
77 * (used in some of the @fill_options)
Akinobu Mitaea9936f32017-03-18 03:17:30 +090078 * @elapsed_time: elapsed time in nanoseconds
Martin Sperl84e0c4e2015-11-27 13:56:04 +000079 */
80
81struct spi_test {
82 char description[64];
83 struct spi_message msg;
84 struct spi_transfer transfers[SPI_TEST_MAX_TRANSFERS];
85 unsigned int transfer_count;
86 int (*run_test)(struct spi_device *spi, struct spi_test *test,
87 void *tx, void *rx);
88 int (*execute_msg)(struct spi_device *spi, struct spi_test *test,
89 void *tx, void *rx);
90 int expected_return;
Akinobu Mita89166712017-03-18 03:17:28 +090091 /* iterate over all values, terminated by a -1 */
Martin Sperl84e0c4e2015-11-27 13:56:04 +000092 int iterate_len[SPI_TEST_MAX_ITERATE];
93 int iterate_tx_align;
94 int iterate_rx_align;
95 u32 iterate_transfer_mask;
96 /* the tx-fill operation */
97 u32 fill_option;
98#define FILL_MEMSET_8 0 /* just memset with 8 bit */
99#define FILL_MEMSET_16 1 /* just memset with 16 bit */
100#define FILL_MEMSET_24 2 /* just memset with 24 bit */
101#define FILL_MEMSET_32 3 /* just memset with 32 bit */
102#define FILL_COUNT_8 4 /* fill with a 8 byte counter */
103#define FILL_COUNT_16 5 /* fill with a 16 bit counter */
104#define FILL_COUNT_24 6 /* fill with a 24 bit counter */
105#define FILL_COUNT_32 7 /* fill with a 32 bit counter */
106#define FILL_TRANSFER_BYTE_8 8 /* fill with the transfer byte - 8 bit */
107#define FILL_TRANSFER_BYTE_16 9 /* fill with the transfer byte - 16 bit */
108#define FILL_TRANSFER_BYTE_24 10 /* fill with the transfer byte - 24 bit */
109#define FILL_TRANSFER_BYTE_32 11 /* fill with the transfer byte - 32 bit */
110#define FILL_TRANSFER_NUM 16 /* fill with the transfer number */
111 u32 fill_pattern;
Akinobu Mitaea9936f32017-03-18 03:17:30 +0900112 unsigned long long elapsed_time;
Martin Sperl84e0c4e2015-11-27 13:56:04 +0000113};
114
115/* default implementation for @spi_test.run_test */
116int spi_test_run_test(struct spi_device *spi,
117 const struct spi_test *test,
118 void *tx, void *rx);
119
120/* default implementation for @spi_test.execute_msg */
121int spi_test_execute_msg(struct spi_device *spi,
122 struct spi_test *test,
123 void *tx, void *rx);
124
125/* function to execute a set of tests */
126int spi_test_run_tests(struct spi_device *spi,
127 struct spi_test *tests);
128
Akinobu Mita0bd7fda2017-03-18 03:17:29 +0900129#define ITERATE_LEN_LIST 0, 1, 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
Martin Sperl739f3e92015-12-13 09:46:25 +0000130 1021, 1024, 1031, 4093, PAGE_SIZE, 4099, 65536, 65537
Akinobu Mita89166712017-03-18 03:17:28 +0900131/* some of the default @spi_transfer.len to test, terminated by a -1 */
132#define ITERATE_LEN ITERATE_LEN_LIST, -1
133#define ITERATE_MAX_LEN ITERATE_LEN_LIST, (SPI_TEST_MAX_SIZE - 1), \
134 SPI_TEST_MAX_SIZE, -1
Martin Sperl84e0c4e2015-11-27 13:56:04 +0000135
136/* the default alignment to test */
137#define ITERATE_ALIGN sizeof(int)