spi-test.h 5.3 KB

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