blob: be232972336255f91557515a6dd60e9d9f3b717a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass04035fd2015-07-06 12:54:35 -06002/*
3 * Copyright (C) 2015 Google, Inc
Simon Glass04035fd2015-07-06 12:54:35 -06004 */
5
6#include <common.h>
7#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06008#include <log.h>
Simon Glass04035fd2015-07-06 12:54:35 -06009#include <syscon.h>
Jean-Jacques Hiblot6c3af1f2018-11-29 10:57:37 +010010#include <regmap.h>
Simon Glass04035fd2015-07-06 12:54:35 -060011#include <asm/test.h>
12#include <dm/test.h>
Simon Glass61b29b82020-02-03 07:36:15 -070013#include <linux/err.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060014#include <test/test.h>
Simon Glass04035fd2015-07-06 12:54:35 -060015#include <test/ut.h>
16
Simon Glass04035fd2015-07-06 12:54:35 -060017/* Base test of system controllers */
18static int dm_test_syscon_base(struct unit_test_state *uts)
19{
20 struct udevice *dev;
21
22 ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev));
23 ut_asserteq(SYSCON0, dev->driver_data);
24
25 ut_assertok(uclass_get_device(UCLASS_SYSCON, 1, &dev));
26 ut_asserteq(SYSCON1, dev->driver_data);
27
28 ut_asserteq(-ENODEV, uclass_get_device(UCLASS_SYSCON, 2, &dev));
29
30 return 0;
31}
Simon Glasse180c2b2020-07-28 19:41:12 -060032DM_TEST(dm_test_syscon_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glassac94b7b2016-01-17 16:11:08 -070033
34/* Test system controller finding */
35static int dm_test_syscon_by_driver_data(struct unit_test_state *uts)
36{
37 struct udevice *dev;
38
39 ut_assertok(syscon_get_by_driver_data(SYSCON0, &dev));
40 ut_asserteq(SYSCON0, dev->driver_data);
41
42 ut_assertok(syscon_get_by_driver_data(SYSCON1, &dev));
43 ut_asserteq(SYSCON1, dev->driver_data);
44
45 ut_asserteq(-ENODEV, syscon_get_by_driver_data(2, &dev));
46
47 return 0;
48}
Simon Glasse180c2b2020-07-28 19:41:12 -060049DM_TEST(dm_test_syscon_by_driver_data, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Jean-Jacques Hiblot6c3af1f2018-11-29 10:57:37 +010050
51/* Test system controller by phandle */
52static int dm_test_syscon_by_phandle(struct unit_test_state *uts)
53{
54 struct udevice *dev;
55 struct regmap *map;
56
57 ut_assertok(uclass_get_device_by_name(UCLASS_TEST_PROBE, "test4",
58 &dev));
59
60 ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev, "first-syscon"));
61 map = syscon_regmap_lookup_by_phandle(dev, "first-syscon");
62 ut_assert(map);
63 ut_assert(!IS_ERR(map));
64 ut_asserteq(1, map->range_count);
65
66 ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev,
67 "second-sys-ctrl"));
68 map = syscon_regmap_lookup_by_phandle(dev, "second-sys-ctrl");
69 ut_assert(map);
70 ut_assert(!IS_ERR(map));
71 ut_asserteq(4, map->range_count);
72
Patrick Delaunaya442e612019-03-07 09:57:13 +010073 ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev,
74 "third-syscon"));
75 map = syscon_regmap_lookup_by_phandle(dev, "third-syscon");
76 ut_assert(map);
77 ut_assert(!IS_ERR(map));
78 ut_asserteq(4, map->range_count);
79
Jean-Jacques Hiblot6c3af1f2018-11-29 10:57:37 +010080 ut_assert(IS_ERR(syscon_regmap_lookup_by_phandle(dev, "not-present")));
81
82 return 0;
83}
Simon Glasse180c2b2020-07-28 19:41:12 -060084DM_TEST(dm_test_syscon_by_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);