reset.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/test.h>
  8. #include <asm/reset.h>
  9. #include <test/ut.h>
  10. /* This must match the specifier for mbox-names="test" in the DT node */
  11. #define TEST_RESET_ID 2
  12. /* This is the other reset phandle specifier handled by bulk */
  13. #define OTHER_RESET_ID 2
  14. static int dm_test_reset(struct unit_test_state *uts)
  15. {
  16. struct udevice *dev_reset;
  17. struct udevice *dev_test;
  18. ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
  19. &dev_reset));
  20. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  21. ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
  22. &dev_test));
  23. ut_assertok(sandbox_reset_test_get(dev_test));
  24. ut_assertok(sandbox_reset_test_assert(dev_test));
  25. ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  26. ut_assertok(sandbox_reset_test_deassert(dev_test));
  27. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  28. ut_assertok(sandbox_reset_test_free(dev_test));
  29. return 0;
  30. }
  31. DM_TEST(dm_test_reset, DM_TESTF_SCAN_FDT);
  32. static int dm_test_reset_bulk(struct unit_test_state *uts)
  33. {
  34. struct udevice *dev_reset;
  35. struct udevice *dev_test;
  36. ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
  37. &dev_reset));
  38. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  39. ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
  40. ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
  41. &dev_test));
  42. ut_assertok(sandbox_reset_test_get_bulk(dev_test));
  43. ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
  44. ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  45. ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
  46. ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
  47. ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  48. ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
  49. ut_assertok(sandbox_reset_test_release_bulk(dev_test));
  50. ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
  51. ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
  52. return 0;
  53. }
  54. DM_TEST(dm_test_reset_bulk, DM_TESTF_SCAN_FDT);