simple-pm-bus.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <dm/test.h>
  8. #include <dm/device-internal.h>
  9. #include <test/ut.h>
  10. #include <asm/clk.h>
  11. #include <asm/power-domain.h>
  12. /* These must match the ids in the device tree */
  13. #define TEST_CLOCK_ID 4
  14. #define TEST_POWER_ID 1
  15. static int dm_test_simple_pm_bus(struct unit_test_state *uts)
  16. {
  17. struct udevice *power;
  18. struct udevice *clock;
  19. struct udevice *bus;
  20. ut_assertok(uclass_get_device_by_name(UCLASS_POWER_DOMAIN,
  21. "power-domain", &power));
  22. ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox",
  23. &clock));
  24. ut_asserteq(0, sandbox_power_domain_query(power, TEST_POWER_ID));
  25. ut_asserteq(0, sandbox_clk_query_enable(clock, TEST_CLOCK_ID));
  26. ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS, "pm-bus-test",
  27. &bus));
  28. ut_asserteq(1, sandbox_power_domain_query(power, TEST_POWER_ID));
  29. ut_asserteq(1, sandbox_clk_query_enable(clock, TEST_CLOCK_ID));
  30. ut_assertok(device_remove(bus, DM_REMOVE_NORMAL));
  31. /* must re-probe since device_remove also removes the power domain */
  32. ut_assertok(uclass_get_device_by_name(UCLASS_POWER_DOMAIN,
  33. "power-domain", &power));
  34. ut_asserteq(0, sandbox_power_domain_query(power, TEST_POWER_ID));
  35. ut_asserteq(0, sandbox_clk_query_enable(clock, TEST_CLOCK_ID));
  36. return 0;
  37. }
  38. DM_TEST(dm_test_simple_pm_bus, UT_TESTF_SCAN_FDT);