Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/drivers/spi/spi-test.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  (c) Martin Sperl <kernel@martin.sperl.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  spi_test definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/spi/spi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define SPI_TEST_MAX_TRANSFERS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define SPI_TEST_MAX_SIZE (32 * PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #define SPI_TEST_MAX_ITERATE 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) /* the "dummy" start addresses used in spi_test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * these addresses get translated at a later stage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define RX_START	BIT(30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define TX_START	BIT(31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define RX(off)		((void *)(RX_START + off))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define TX(off)		((void *)(TX_START + off))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /* some special defines for offsets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define SPI_TEST_MAX_SIZE_HALF	BIT(29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /* detection pattern for unfinished reads...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * - 0x00 or 0xff could be valid levels for tx_buf = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * so we do not use either of them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define SPI_TEST_PATTERN_UNWRITTEN 0xAA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define SPI_TEST_PATTERN_DO_NOT_WRITE 0x55
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define SPI_TEST_CHECK_DO_NOT_WRITE 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * struct spi_test - describes a specific (set of) tests to execute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * @description:      description of the test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * @msg:              a template @spi_message usedfor the default settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * @transfers:        array of @spi_transfers that are part of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *                    resulting spi_message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * @transfer_count:   number of transfers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * @run_test:         run a specific spi_test - this allows to override
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *                    the default implementation of @spi_test_run_transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  *                    either to add some custom filters for a specific test
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  *                    or to effectively run some very custom tests...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @execute_msg:      run the spi_message for real - this allows to override
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *                    @spi_test_execute_msg to apply final modifications
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *                    on the spi_message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * @expected_return:  the expected return code - in some cases we want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *                    test also for error conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * @iterate_len:      list of length to iterate on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * @iterate_tx_align: change the alignment of @spi_transfer.tx_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *                    for all values in the below range if set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *                    the ranges are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *                    [0 : @spi_master.dma_alignment[ if set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *                    [0 : iterate_tx_align[ if unset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * @iterate_rx_align: change the alignment of @spi_transfer.rx_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *                    see @iterate_tx_align for details
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * @iterate_transfer_mask: the bitmask of transfers to which the iterations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *                         apply - if 0, then it applies to all transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * @fill_option:      define the way how tx_buf is filled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * @fill_pattern:     fill pattern to apply to the tx_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *                    (used in some of the @fill_options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * @elapsed_time:     elapsed time in nanoseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) struct spi_test {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	char description[64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct spi_message msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct spi_transfer transfers[SPI_TEST_MAX_TRANSFERS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	unsigned int transfer_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	int (*run_test)(struct spi_device *spi, struct spi_test *test,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			void *tx, void *rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	int (*execute_msg)(struct spi_device *spi, struct spi_test *test,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			   void *tx, void *rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int expected_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/* iterate over all values, terminated by a -1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	int iterate_len[SPI_TEST_MAX_ITERATE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	int iterate_tx_align;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	int iterate_rx_align;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	u32 iterate_transfer_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	/* the tx-fill operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	u32 fill_option;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #define FILL_MEMSET_8	0	/* just memset with 8 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #define FILL_MEMSET_16	1	/* just memset with 16 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #define FILL_MEMSET_24	2	/* just memset with 24 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #define FILL_MEMSET_32	3	/* just memset with 32 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #define FILL_COUNT_8	4	/* fill with a 8 byte counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #define FILL_COUNT_16	5	/* fill with a 16 bit counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #define FILL_COUNT_24	6	/* fill with a 24 bit counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #define FILL_COUNT_32	7	/* fill with a 32 bit counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #define FILL_TRANSFER_BYTE_8  8	/* fill with the transfer byte - 8 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #define FILL_TRANSFER_BYTE_16 9	/* fill with the transfer byte - 16 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #define FILL_TRANSFER_BYTE_24 10 /* fill with the transfer byte - 24 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define FILL_TRANSFER_BYTE_32 11 /* fill with the transfer byte - 32 bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define FILL_TRANSFER_NUM     16 /* fill with the transfer number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	u32 fill_pattern;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	unsigned long long elapsed_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* default implementation for @spi_test.run_test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int spi_test_run_test(struct spi_device *spi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		      const struct spi_test *test,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		      void *tx, void *rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* default implementation for @spi_test.execute_msg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int spi_test_execute_msg(struct spi_device *spi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			 struct spi_test *test,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			 void *tx, void *rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /* function to execute a set of tests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int spi_test_run_tests(struct spi_device *spi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		       struct spi_test *tests);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define ITERATE_LEN_LIST 0, 1, 2, 3, 7, 11, 16, 31, 32, 64, 97, 128, 251, 256, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		1021, 1024, 1031, 4093, PAGE_SIZE, 4099, 65536, 65537
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* some of the default @spi_transfer.len to test, terminated by a -1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #define ITERATE_LEN ITERATE_LEN_LIST, -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define ITERATE_MAX_LEN ITERATE_LEN_LIST, (SPI_TEST_MAX_SIZE - 1), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		SPI_TEST_MAX_SIZE, -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* the default alignment to test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #define ITERATE_ALIGN sizeof(int)