1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (C) 2015 Google, Inc 4 */ 5 6 #include <common.h> 7 #include <dm.h> 8 #include <mapmem.h> 9 #include <regmap.h> 10 #include <syscon.h> 11 #include <asm/test.h> 12 #include <dm/test.h> 13 #include <test/ut.h> 14 15 /* Base test of register maps */ 16 static int dm_test_regmap_base(struct unit_test_state *uts) 17 { 18 struct udevice *dev; 19 struct regmap *map; 20 int i; 21 22 ut_assertok(uclass_get_device(UCLASS_SYSCON, 0, &dev)); 23 map = syscon_get_regmap(dev); 24 ut_assertok_ptr(map); 25 ut_asserteq(1, map->range_count); 26 ut_asserteq(0x10, map->base); 27 ut_asserteq(0x10, map->range->start); 28 ut_asserteq(4, map->range->size); 29 ut_asserteq_ptr(&map->base_range, map->range); 30 ut_asserteq(0x10, map_to_sysmem(regmap_get_range(map, 0))); 31 32 ut_assertok(uclass_get_device(UCLASS_SYSCON, 1, &dev)); 33 map = syscon_get_regmap(dev); 34 ut_assertok_ptr(map); 35 ut_asserteq(4, map->range_count); 36 ut_asserteq(0x20, map->base); 37 ut_assert(&map->base_range != map->range); 38 for (i = 0; i < 4; i++) { 39 const unsigned long addr = 0x20 + 8 * i; 40 41 ut_asserteq(addr, map->range[i].start); 42 ut_asserteq(5 + i, map->range[i].size); 43 ut_asserteq(addr, map_to_sysmem(regmap_get_range(map, i))); 44 } 45 46 /* Check that we can't pretend a different device is a syscon */ 47 ut_assertok(uclass_get_device(UCLASS_I2C, 0, &dev)); 48 map = syscon_get_regmap(dev); 49 ut_asserteq_ptr(ERR_PTR(-ENOEXEC), map); 50 51 return 0; 52 } 53 DM_TEST(dm_test_regmap_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); 54 55 /* Test we can access a regmap through syscon */ 56 static int dm_test_regmap_syscon(struct unit_test_state *uts) 57 { 58 struct regmap *map; 59 60 map = syscon_get_regmap_by_driver_data(SYSCON0); 61 ut_assertok_ptr(map); 62 ut_asserteq(1, map->range_count); 63 64 map = syscon_get_regmap_by_driver_data(SYSCON1); 65 ut_assertok_ptr(map); 66 ut_asserteq(4, map->range_count); 67 68 map = syscon_get_regmap_by_driver_data(SYSCON_COUNT); 69 ut_asserteq_ptr(ERR_PTR(-ENODEV), map); 70 71 ut_asserteq(0x10, map_to_sysmem(syscon_get_first_range(SYSCON0))); 72 ut_asserteq(0x20, map_to_sysmem(syscon_get_first_range(SYSCON1))); 73 ut_asserteq_ptr(ERR_PTR(-ENODEV), 74 syscon_get_first_range(SYSCON_COUNT)); 75 76 return 0; 77 } 78 79 DM_TEST(dm_test_regmap_syscon, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); 80