Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | cd55652 | 2015-07-06 12:54:35 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
Simon Glass | cd55652 | 2015-07-06 12:54:35 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | cd55652 | 2015-07-06 12:54:35 -0600 | [diff] [blame] | 6 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 7 | #include <log.h> |
Simon Glass | cd55652 | 2015-07-06 12:54:35 -0600 | [diff] [blame] | 8 | #include <syscon.h> |
Jean-Jacques Hiblot | dc44ea4 | 2018-11-29 10:57:37 +0100 | [diff] [blame] | 9 | #include <regmap.h> |
Simon Glass | cd55652 | 2015-07-06 12:54:35 -0600 | [diff] [blame] | 10 | #include <asm/test.h> |
| 11 | #include <dm/test.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 12 | #include <linux/err.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 13 | #include <test/test.h> |
Simon Glass | cd55652 | 2015-07-06 12:54:35 -0600 | [diff] [blame] | 14 | #include <test/ut.h> |
| 15 | |
Simon Glass | cd55652 | 2015-07-06 12:54:35 -0600 | [diff] [blame] | 16 | /* Base test of system controllers */ |
| 17 | static int dm_test_syscon_base(struct unit_test_state *uts) |
| 18 | { |
| 19 | struct udevice *dev; |
| 20 | |
| 21 | ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev)); |
| 22 | ut_asserteq(SYSCON0, dev->driver_data); |
| 23 | |
| 24 | ut_assertok(uclass_get_device(UCLASS_SYSCON, 1, &dev)); |
| 25 | ut_asserteq(SYSCON1, dev->driver_data); |
| 26 | |
| 27 | ut_asserteq(-ENODEV, uclass_get_device(UCLASS_SYSCON, 2, &dev)); |
| 28 | |
| 29 | return 0; |
| 30 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 31 | DM_TEST(dm_test_syscon_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Simon Glass | 6d5579c | 2016-01-17 16:11:08 -0700 | [diff] [blame] | 32 | |
| 33 | /* Test system controller finding */ |
| 34 | static int dm_test_syscon_by_driver_data(struct unit_test_state *uts) |
| 35 | { |
| 36 | struct udevice *dev; |
| 37 | |
| 38 | ut_assertok(syscon_get_by_driver_data(SYSCON0, &dev)); |
| 39 | ut_asserteq(SYSCON0, dev->driver_data); |
| 40 | |
| 41 | ut_assertok(syscon_get_by_driver_data(SYSCON1, &dev)); |
| 42 | ut_asserteq(SYSCON1, dev->driver_data); |
| 43 | |
| 44 | ut_asserteq(-ENODEV, syscon_get_by_driver_data(2, &dev)); |
| 45 | |
| 46 | return 0; |
| 47 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 48 | DM_TEST(dm_test_syscon_by_driver_data, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Jean-Jacques Hiblot | dc44ea4 | 2018-11-29 10:57:37 +0100 | [diff] [blame] | 49 | |
| 50 | /* Test system controller by phandle */ |
| 51 | static int dm_test_syscon_by_phandle(struct unit_test_state *uts) |
| 52 | { |
| 53 | struct udevice *dev; |
| 54 | struct regmap *map; |
| 55 | |
| 56 | ut_assertok(uclass_get_device_by_name(UCLASS_TEST_PROBE, "test4", |
| 57 | &dev)); |
| 58 | |
| 59 | ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev, "first-syscon")); |
| 60 | map = syscon_regmap_lookup_by_phandle(dev, "first-syscon"); |
| 61 | ut_assert(map); |
| 62 | ut_assert(!IS_ERR(map)); |
| 63 | ut_asserteq(1, map->range_count); |
| 64 | |
| 65 | ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev, |
| 66 | "second-sys-ctrl")); |
| 67 | map = syscon_regmap_lookup_by_phandle(dev, "second-sys-ctrl"); |
| 68 | ut_assert(map); |
| 69 | ut_assert(!IS_ERR(map)); |
| 70 | ut_asserteq(4, map->range_count); |
| 71 | |
Patrick Delaunay | ee01043 | 2019-03-07 09:57:13 +0100 | [diff] [blame] | 72 | ut_assertok_ptr(syscon_regmap_lookup_by_phandle(dev, |
| 73 | "third-syscon")); |
| 74 | map = syscon_regmap_lookup_by_phandle(dev, "third-syscon"); |
| 75 | ut_assert(map); |
| 76 | ut_assert(!IS_ERR(map)); |
| 77 | ut_asserteq(4, map->range_count); |
| 78 | |
Jean-Jacques Hiblot | dc44ea4 | 2018-11-29 10:57:37 +0100 | [diff] [blame] | 79 | ut_assert(IS_ERR(syscon_regmap_lookup_by_phandle(dev, "not-present"))); |
| 80 | |
| 81 | return 0; |
| 82 | } |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 83 | DM_TEST(dm_test_syscon_by_phandle, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |