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