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