• Home
  • Raw
  • Download

Lines Matching +full:no +full:- +full:loopback +full:- +full:test

2  *  linux/drivers/spi/spi-loopback-test.c
6 * Loopback test driver to test several typical spi_message conditions
32 #include "spi-test.h"
46 /* the device is jumpered for loopback - enabling some rx_buf tests */
47 static int loopback; variable
48 module_param(loopback, int, 0);
49 MODULE_PARM_DESC(loopback,
50 "if set enable loopback mode, where the rx_buf " \
57 "if set controller will be asked to enable test loop mode. " \
65 /* run only a specific test */
66 static int run_only_test = -1;
69 "only run the test with this number (0-based !)");
86 .description = "tx/rx-transfer - start of page",
100 .description = "tx/rx-transfer - crossing PAGE_SIZE",
108 .tx_buf = TX(PAGE_SIZE - 4),
109 .rx_buf = RX(PAGE_SIZE - 4),
114 .description = "tx-transfer - only",
126 .description = "rx-transfer - only",
138 .description = "two tx-transfers - alter both",
155 .description = "two tx-transfers - alter first",
172 .description = "two tx-transfers - alter second",
189 .description = "two transfers tx then rx - alter both",
205 .description = "two transfers tx then rx - alter tx",
222 .description = "two transfers tx then rx - alter rx",
239 .description = "two tx+rx transfers - alter both",
260 .description = "two tx+rx transfers - alter first",
281 .description = "two tx+rx transfers - alter second",
301 .description = "two tx+rx transfers - delay after transfer",
328 spi->mode |= loop_req ? SPI_LOOP : 0; in spi_loopback_test_probe()
329 spi->mode |= no_cs ? SPI_NO_CS : 0; in spi_loopback_test_probe()
332 dev_err(&spi->dev, "SPI setup with SPI_LOOP or SPI_NO_CS failed (%d)\n", in spi_loopback_test_probe()
338 dev_info(&spi->dev, "Executing spi-loopback-tests\n"); in spi_loopback_test_probe()
342 dev_info(&spi->dev, "Finished spi-loopback-tests with return: %i\n", in spi_loopback_test_probe()
350 { .compatible = "linux,spi-loopback-test", },
363 .name = "spi-loopback-test",
373 MODULE_DESCRIPTION("test spi_driver to check core functionality");
376 /*-------------------------------------------------------------------------*/
400 pr_info("%s truncated - continuing at offset %04zx\n", in spi_test_print_hex_dump()
401 pre, len - 512); in spi_test_print_hex_dump()
404 ptr + (len - 512), 512, 0); in spi_test_print_hex_dump()
415 dev_info(&spi->dev, " spi_msg@%pK\n", msg); in spi_test_dump_message()
416 if (msg->status) in spi_test_dump_message()
417 dev_info(&spi->dev, " status: %i\n", in spi_test_dump_message()
418 msg->status); in spi_test_dump_message()
419 dev_info(&spi->dev, " frame_length: %i\n", in spi_test_dump_message()
420 msg->frame_length); in spi_test_dump_message()
421 dev_info(&spi->dev, " actual_length: %i\n", in spi_test_dump_message()
422 msg->actual_length); in spi_test_dump_message()
424 list_for_each_entry(xfer, &msg->transfers, transfer_list) { in spi_test_dump_message()
425 dev_info(&spi->dev, " spi_transfer@%pK\n", xfer); in spi_test_dump_message()
426 dev_info(&spi->dev, " len: %i\n", xfer->len); in spi_test_dump_message()
427 dev_info(&spi->dev, " tx_buf: %pK\n", xfer->tx_buf); in spi_test_dump_message()
428 if (dump_data && xfer->tx_buf) in spi_test_dump_message()
430 xfer->tx_buf, in spi_test_dump_message()
431 xfer->len); in spi_test_dump_message()
433 dev_info(&spi->dev, " rx_buf: %pK\n", xfer->rx_buf); in spi_test_dump_message()
434 if (dump_data && xfer->rx_buf) in spi_test_dump_message()
436 xfer->rx_buf, in spi_test_dump_message()
437 xfer->len); in spi_test_dump_message()
438 /* check for unwritten test pattern on rx_buf */ in spi_test_dump_message()
439 if (xfer->rx_buf) { in spi_test_dump_message()
440 for (i = 0 ; i < xfer->len ; i++) { in spi_test_dump_message()
441 b = ((u8 *)xfer->rx_buf)[xfer->len - 1 - i]; in spi_test_dump_message()
446 dev_info(&spi->dev, in spi_test_dump_message()
449 xfer->len - i); in spi_test_dump_message()
465 if (rx_a->start > rx_b->start) in rx_ranges_cmp()
467 if (rx_a->start < rx_b->start) in rx_ranges_cmp()
468 return -1; in rx_ranges_cmp()
484 list_for_each_entry(xfer, &msg->transfers, transfer_list) { in spi_check_rx_ranges()
485 /* if there is no rx, then no check is needed */ in spi_check_rx_ranges()
486 if (!xfer->rx_buf) in spi_check_rx_ranges()
489 if (RANGE_CHECK(xfer->rx_buf, xfer->len, in spi_check_rx_ranges()
491 ranges[i].start = xfer->rx_buf; in spi_check_rx_ranges()
492 ranges[i].end = xfer->rx_buf + xfer->len; in spi_check_rx_ranges()
498 /* if no ranges, then we can return and avoid the checks...*/ in spi_check_rx_ranges()
516 if ((addr >= r->start) && (addr < r->end)) in spi_check_rx_ranges()
517 addr = r->end; in spi_check_rx_ranges()
519 /* second test after a (hopefull) translation */ in spi_check_rx_ranges()
525 dev_err(&spi->dev, in spi_check_rx_ranges()
526 "loopback strangeness - rx changed outside of allowed range at: %pK\n", in spi_check_rx_ranges()
531 ret = -ERANGE; in spi_check_rx_ranges()
538 struct spi_test *test) in spi_test_check_elapsed_time() argument
544 for (i = 0; i < test->transfer_count; i++) { in spi_test_check_elapsed_time()
545 struct spi_transfer *xfer = test->transfers + i; in spi_test_check_elapsed_time()
547 xfer->len; in spi_test_check_elapsed_time()
549 delay_usecs += xfer->delay_usecs; in spi_test_check_elapsed_time()
550 if (!xfer->speed_hz) in spi_test_check_elapsed_time()
552 estimated_time += div_u64(nbits * NSEC_PER_SEC, xfer->speed_hz); in spi_test_check_elapsed_time()
556 if (test->elapsed_time < estimated_time) { in spi_test_check_elapsed_time()
557 dev_err(&spi->dev, in spi_test_check_elapsed_time()
559 test->elapsed_time, estimated_time); in spi_test_check_elapsed_time()
561 return -EINVAL; in spi_test_check_elapsed_time()
576 /* checks rx_buffer pattern are valid with loopback or without */ in spi_test_check_loopback_result()
583 /* if we run without loopback, then return now */ in spi_test_check_loopback_result()
584 if (!loopback) in spi_test_check_loopback_result()
588 list_for_each_entry(xfer, &msg->transfers, transfer_list) { in spi_test_check_loopback_result()
589 /* if there is no rx, then no check is needed */ in spi_test_check_loopback_result()
590 if (!xfer->len || !xfer->rx_buf) in spi_test_check_loopback_result()
593 if (xfer->tx_buf) { in spi_test_check_loopback_result()
594 for (i = 0; i < xfer->len; i++) { in spi_test_check_loopback_result()
595 txb = ((u8 *)xfer->tx_buf)[i]; in spi_test_check_loopback_result()
596 rxb = ((u8 *)xfer->rx_buf)[i]; in spi_test_check_loopback_result()
602 txb = ((u8 *)xfer->rx_buf)[0]; in spi_test_check_loopback_result()
605 dev_err(&spi->dev, in spi_test_check_loopback_result()
606 "loopback strangeness - we expect 0x00 or 0xff, but not 0x%02x\n", in spi_test_check_loopback_result()
608 return -EINVAL; in spi_test_check_loopback_result()
611 for (i = 1; i < xfer->len; i++) { in spi_test_check_loopback_result()
612 rxb = ((u8 *)xfer->rx_buf)[i]; in spi_test_check_loopback_result()
622 dev_err(&spi->dev, in spi_test_check_loopback_result()
623 "loopback strangeness - transfer mismatch on byte %04zx - expected 0x%02x, but got 0x%02x\n", in spi_test_check_loopback_result()
626 return -EINVAL; in spi_test_check_loopback_result()
642 *ptr += (SPI_TEST_MAX_SIZE_PLUS / 2) - in spi_test_translate()
646 * - we check against MAX_SIZE_PLUS to allow for automated alignment in spi_test_translate()
649 off = *ptr - RX(0); in spi_test_translate()
657 off = *ptr - TX(0); in spi_test_translate()
663 dev_err(&spi->dev, in spi_test_translate()
669 return -EINVAL; in spi_test_translate()
673 struct spi_test *test) in spi_test_fill_pattern() argument
675 struct spi_transfer *xfers = test->transfers; in spi_test_fill_pattern()
682 (value >> (8 * (bytes - 1 - count % bytes))) in spi_test_fill_pattern()
689 for (i = 0; i < test->transfer_count; i++) { in spi_test_fill_pattern()
701 switch (test->fill_option) { in spi_test_fill_pattern()
703 *tx_buf = test->fill_pattern; in spi_test_fill_pattern()
706 *tx_buf = GET_VALUE_BYTE(test->fill_pattern, in spi_test_fill_pattern()
710 *tx_buf = GET_VALUE_BYTE(test->fill_pattern, in spi_test_fill_pattern()
714 *tx_buf = GET_VALUE_BYTE(test->fill_pattern, in spi_test_fill_pattern()
745 dev_err(&spi->dev, in spi_test_fill_pattern()
747 test->fill_option); in spi_test_fill_pattern()
748 return -EINVAL; in spi_test_fill_pattern()
757 struct spi_test *test, in _spi_test_run_iter() argument
760 struct spi_message *msg = &test->msg; in _spi_test_run_iter()
764 /* initialize message - zero-filled via static initialization */ in _spi_test_run_iter()
771 for (i = 0; i < test->transfer_count; i++) { in _spi_test_run_iter()
772 x = &test->transfers[i]; in _spi_test_run_iter()
775 ret = spi_test_translate(spi, (void **)&x->tx_buf, x->len, in _spi_test_run_iter()
781 ret = spi_test_translate(spi, &x->rx_buf, x->len, in _spi_test_run_iter()
791 ret = spi_test_fill_pattern(spi, test); in _spi_test_run_iter()
796 if (test->execute_msg) in _spi_test_run_iter()
797 ret = test->execute_msg(spi, test, tx, rx); in _spi_test_run_iter()
799 ret = spi_test_execute_msg(spi, test, tx, rx); in _spi_test_run_iter()
802 if (ret == test->expected_return) in _spi_test_run_iter()
805 dev_err(&spi->dev, in _spi_test_run_iter()
806 "test failed - test returned %i, but we expect %i\n", in _spi_test_run_iter()
807 ret, test->expected_return); in _spi_test_run_iter()
815 return -EFAULT; in _spi_test_run_iter()
826 struct spi_test test; in spi_test_run_iter() local
829 /* copy the test template to test */ in spi_test_run_iter()
830 memcpy(&test, testtemplate, sizeof(test)); in spi_test_run_iter()
835 if (!(test.iterate_transfer_mask & (BIT(test.transfer_count) - 1))) in spi_test_run_iter()
836 test.iterate_transfer_mask = 1; in spi_test_run_iter()
840 for (i = 0; i < test.transfer_count; i++) { in spi_test_run_iter()
841 if (test.transfers[i].tx_buf) in spi_test_run_iter()
843 if (test.transfers[i].rx_buf) in spi_test_run_iter()
851 dev_warn_once(&spi->dev, in spi_test_run_iter()
852 "%s: iterate_tx_off configured with tx_buf==NULL - ignoring\n", in spi_test_run_iter()
853 test.description); in spi_test_run_iter()
857 dev_warn_once(&spi->dev, in spi_test_run_iter()
858 "%s: iterate_rx_off configured with rx_buf==NULL - ignoring\n", in spi_test_run_iter()
859 test.description); in spi_test_run_iter()
865 dev_info(&spi->dev, "Running test %s\n", test.description); in spi_test_run_iter()
867 dev_info(&spi->dev, in spi_test_run_iter()
873 for (i = 0; i < test.transfer_count; i++) { in spi_test_run_iter()
875 if (!(test.iterate_transfer_mask & BIT(i))) in spi_test_run_iter()
877 test.transfers[i].len = len; in spi_test_run_iter()
878 if (test.transfers[i].tx_buf) in spi_test_run_iter()
879 test.transfers[i].tx_buf += tx_off; in spi_test_run_iter()
880 if (test.transfers[i].tx_buf) in spi_test_run_iter()
881 test.transfers[i].rx_buf += rx_off; in spi_test_run_iter()
885 return _spi_test_run_iter(spi, &test, tx, rx); in spi_test_run_iter()
889 * spi_test_execute_msg - default implementation to run a test
892 * test: the test to execute, which already contains @msg
893 * tx: the tx buffer allocated for the test sequence
894 * rx: the rx buffer allocated for the test sequence
898 int spi_test_execute_msg(struct spi_device *spi, struct spi_test *test, in spi_test_execute_msg() argument
901 struct spi_message *msg = &test->msg; in spi_test_execute_msg()
916 test->elapsed_time = ktime_to_ns(ktime_sub(ktime_get(), start)); in spi_test_execute_msg()
917 if (ret == -ETIMEDOUT) { in spi_test_execute_msg()
918 dev_info(&spi->dev, in spi_test_execute_msg()
919 "spi-message timed out - rerunning...\n"); in spi_test_execute_msg()
926 dev_err(&spi->dev, in spi_test_execute_msg()
933 if (msg->frame_length != msg->actual_length) { in spi_test_execute_msg()
934 dev_err(&spi->dev, in spi_test_execute_msg()
936 ret = -EIO; in spi_test_execute_msg()
940 /* run rx-buffer tests */ in spi_test_execute_msg()
945 ret = spi_test_check_elapsed_time(spi, test); in spi_test_execute_msg()
959 * spi_test_run_test - run an individual spi_test
964 * test: the test which we need to execute
965 * tx: the tx buffer allocated for the test sequence
966 * rx: the rx buffer allocated for the test sequence
971 int spi_test_run_test(struct spi_device *spi, const struct spi_test *test, in spi_test_run_test() argument
979 /* test for transfer limits */ in spi_test_run_test()
980 if (test->transfer_count >= SPI_TEST_MAX_TRANSFERS) { in spi_test_run_test()
981 dev_err(&spi->dev, in spi_test_run_test()
983 test->description, test->transfer_count); in spi_test_run_test()
984 return -E2BIG; in spi_test_run_test()
997 var < (test->iterate_##var ? \ in spi_test_run_test()
998 (spi->master->dma_alignment ? \ in spi_test_run_test()
999 spi->master->dma_alignment : \ in spi_test_run_test()
1000 test->iterate_##var) : \ in spi_test_run_test()
1005 (len = test->iterate_len[idx_len]) != -1; idx_len++) { in spi_test_run_test()
1009 ret = spi_test_run_iter(spi, test, in spi_test_run_test()
1025 * spi_test_run_tests - run an array of spi_messages tests
1027 * @tests: NULL-terminated array of @spi_test
1037 struct spi_test *test; in spi_test_run_tests() local
1047 return -ENOMEM; in spi_test_run_tests()
1055 ret = -ENOMEM; in spi_test_run_tests()
1060 for (test = tests, count = 0; test->description[0]; in spi_test_run_tests()
1061 test++, count++) { in spi_test_run_tests()
1062 /* only run test if requested */ in spi_test_run_tests()
1063 if ((run_only_test > -1) && (count != run_only_test)) in spi_test_run_tests()
1066 if (test->run_test) in spi_test_run_tests()
1067 ret = test->run_test(spi, test, tx, rx); in spi_test_run_tests()
1069 ret = spi_test_run_test(spi, test, tx, rx); in spi_test_run_tests()