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