1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
14 /* Base test of system controllers */
15 static int dm_test_syscon_base(struct unit_test_state *uts)
19 ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev));
20 ut_asserteq(SYSCON0, dev->driver_data);
22 ut_assertok(uclass_get_device(UCLASS_SYSCON, 1, &dev));
23 ut_asserteq(SYSCON1, dev->driver_data);
25 ut_asserteq(-ENODEV, uclass_get_device(UCLASS_SYSCON, 2, &dev));
29 DM_TEST(dm_test_syscon_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
31 /* Test system controller finding */
32 static int dm_test_syscon_by_driver_data(struct unit_test_state *uts)
36 ut_assertok(syscon_get_by_driver_data(SYSCON0, &dev));
37 ut_asserteq(SYSCON0, dev->driver_data);
39 ut_assertok(syscon_get_by_driver_data(SYSCON1, &dev));
40 ut_asserteq(SYSCON1, dev->driver_data);
42 ut_asserteq(-ENODEV, syscon_get_by_driver_data(2, &dev));
46 DM_TEST(dm_test_syscon_by_driver_data, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
48 /* Test system controller by phandle */
49 static int dm_test_syscon_by_phandle(struct unit_test_state *uts)
54 ut_assertok(uclass_get_device_by_name(UCLASS_TEST_PROBE, "test4",
57 ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev, "first-syscon"));
58 map = syscon_regmap_lookup_by_phandle(dev, "first-syscon");
60 ut_assert(!IS_ERR(map));
61 ut_asserteq(1, map->range_count);
63 ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev,
65 map = syscon_regmap_lookup_by_phandle(dev, "second-sys-ctrl");
67 ut_assert(!IS_ERR(map));
68 ut_asserteq(4, map->range_count);
70 ut_assert(IS_ERR(syscon_regmap_lookup_by_phandle(dev, "not-present")));
74 DM_TEST(dm_test_syscon_by_phandle, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);