1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
13 #include <linux/err.h>
14 #include <test/test.h>
17 /* Base test of system controllers */
18 static int dm_test_syscon_base(struct unit_test_state *uts)
22 ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev));
23 ut_asserteq(SYSCON0, dev->driver_data);
25 ut_assertok(uclass_get_device(UCLASS_SYSCON, 1, &dev));
26 ut_asserteq(SYSCON1, dev->driver_data);
28 ut_asserteq(-ENODEV, uclass_get_device(UCLASS_SYSCON, 2, &dev));
32 DM_TEST(dm_test_syscon_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
34 /* Test system controller finding */
35 static int dm_test_syscon_by_driver_data(struct unit_test_state *uts)
39 ut_assertok(syscon_get_by_driver_data(SYSCON0, &dev));
40 ut_asserteq(SYSCON0, dev->driver_data);
42 ut_assertok(syscon_get_by_driver_data(SYSCON1, &dev));
43 ut_asserteq(SYSCON1, dev->driver_data);
45 ut_asserteq(-ENODEV, syscon_get_by_driver_data(2, &dev));
49 DM_TEST(dm_test_syscon_by_driver_data, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
51 /* Test system controller by phandle */
52 static int dm_test_syscon_by_phandle(struct unit_test_state *uts)
57 ut_assertok(uclass_get_device_by_name(UCLASS_TEST_PROBE, "test4",
60 ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev, "first-syscon"));
61 map = syscon_regmap_lookup_by_phandle(dev, "first-syscon");
63 ut_assert(!IS_ERR(map));
64 ut_asserteq(1, map->range_count);
66 ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev,
68 map = syscon_regmap_lookup_by_phandle(dev, "second-sys-ctrl");
70 ut_assert(!IS_ERR(map));
71 ut_asserteq(4, map->range_count);
73 ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev,
75 map = syscon_regmap_lookup_by_phandle(dev, "third-syscon");
77 ut_assert(!IS_ERR(map));
78 ut_asserteq(4, map->range_count);
80 ut_assert(IS_ERR(syscon_regmap_lookup_by_phandle(dev, "not-present")));
84 DM_TEST(dm_test_syscon_by_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);