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