reset.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2016, NVIDIA CORPORATION.
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <dm/device-internal.h>
  8. #include <log.h>
  9. #include <malloc.h>
  10. #include <reset.h>
  11. #include <dm/test.h>
  12. #include <asm/reset.h>
  13. #include <test/test.h>
  14. #include <test/ut.h>
  15. /* This must match the specifier for mbox-names="test" in the DT node */
  16. #define TEST_RESET_ID 2
  17. /* This is the other reset phandle specifier handled by bulk */
  18. #define OTHER_RESET_ID 2
  19. /* Base test of the reset uclass */
  20. static int dm_test_reset_base(struct unit_test_state *uts)
  21. {
  22. struct udevice *dev;
  23. struct reset_ctl reset_method1;
  24. struct reset_ctl reset_method2;
  25. /* Get the device using the reset device */
  26. ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
  27. &dev));
  28. /* Get the same reset port in 2 different ways and compare */
  29. ut_assertok(reset_get_by_index(dev, 1, &reset_method1));
  30. ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1,
  31. &reset_method2));
  32. ut_asserteq(reset_method1.id, reset_method2.id);
  33. return 0;
  34. }
  35. DM_TEST(dm_test_reset_base, UT_TESTF_SCAN_FDT);
  36. static int dm_test_reset(struct unit_test_state *uts)
  37. {
  38. struct udevice *dev_reset;
  39. struct udevice *dev_test;
  40. ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
  41. &dev_reset));
  42. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  43. ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
  44. &dev_test));
  45. ut_assertok(sandbox_reset_test_get(dev_test));
  46. ut_assertok(sandbox_reset_test_assert(dev_test));
  47. ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  48. ut_assertok(sandbox_reset_test_deassert(dev_test));
  49. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  50. ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
  51. ut_assertok(sandbox_reset_test_free(dev_test));
  52. ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
  53. return 0;
  54. }
  55. DM_TEST(dm_test_reset, UT_TESTF_SCAN_FDT);
  56. static int dm_test_reset_devm(struct unit_test_state *uts)
  57. {
  58. struct udevice *dev_reset;
  59. struct udevice *dev_test;
  60. ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
  61. &dev_reset));
  62. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  63. ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
  64. &dev_test));
  65. ut_assertok(sandbox_reset_test_get_devm(dev_test));
  66. ut_assertok(sandbox_reset_test_assert(dev_test));
  67. ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  68. ut_assertok(sandbox_reset_test_deassert(dev_test));
  69. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  70. ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
  71. ut_assertok(device_remove(dev_test, DM_REMOVE_NORMAL));
  72. ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
  73. return 0;
  74. }
  75. DM_TEST(dm_test_reset_devm, UT_TESTF_SCAN_FDT);
  76. static int dm_test_reset_bulk(struct unit_test_state *uts)
  77. {
  78. struct udevice *dev_reset;
  79. struct udevice *dev_test;
  80. ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
  81. &dev_reset));
  82. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  83. ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
  84. ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
  85. &dev_test));
  86. ut_assertok(sandbox_reset_test_get_bulk(dev_test));
  87. ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
  88. ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  89. ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
  90. ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
  91. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  92. ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
  93. ut_assertok(sandbox_reset_test_release_bulk(dev_test));
  94. ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  95. ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
  96. return 0;
  97. }
  98. DM_TEST(dm_test_reset_bulk, UT_TESTF_SCAN_FDT);
  99. static int dm_test_reset_bulk_devm(struct unit_test_state *uts)
  100. {
  101. struct udevice *dev_reset;
  102. struct udevice *dev_test;
  103. ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
  104. &dev_reset));
  105. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  106. ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
  107. ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
  108. &dev_test));
  109. ut_assertok(sandbox_reset_test_get_bulk_devm(dev_test));
  110. ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
  111. ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  112. ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
  113. ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
  114. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  115. ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
  116. ut_asserteq(1, sandbox_reset_is_requested(dev_reset, OTHER_RESET_ID));
  117. ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
  118. ut_assertok(device_remove(dev_test, DM_REMOVE_NORMAL));
  119. ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
  120. ut_asserteq(0, sandbox_reset_is_requested(dev_reset, OTHER_RESET_ID));
  121. return 0;
  122. }
  123. DM_TEST(dm_test_reset_bulk_devm, UT_TESTF_SCAN_FDT);