Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Thomas Chou | 9961a0b | 2015-10-30 15:35:52 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw> |
Thomas Chou | 9961a0b | 2015-10-30 15:35:52 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <timer.h> |
| 9 | #include <dm/test.h> |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 10 | #include <dm/device-internal.h> |
Simon Glass | 0e1fad4 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 11 | #include <test/test.h> |
Thomas Chou | 9961a0b | 2015-10-30 15:35:52 +0800 | [diff] [blame] | 12 | #include <test/ut.h> |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 13 | #include <asm/cpu.h> |
Thomas Chou | 9961a0b | 2015-10-30 15:35:52 +0800 | [diff] [blame] | 14 | |
Thomas Chou | 9961a0b | 2015-10-30 15:35:52 +0800 | [diff] [blame] | 15 | /* |
| 16 | * Basic test of the timer uclass. |
| 17 | */ |
| 18 | static int dm_test_timer_base(struct unit_test_state *uts) |
| 19 | { |
| 20 | struct udevice *dev; |
| 21 | |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 22 | ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@0", &dev)); |
Thomas Chou | 9961a0b | 2015-10-30 15:35:52 +0800 | [diff] [blame] | 23 | ut_asserteq(1000000, timer_get_rate(dev)); |
| 24 | |
| 25 | return 0; |
| 26 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 27 | DM_TEST(dm_test_timer_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * Test of timebase fallback |
| 31 | */ |
| 32 | static int dm_test_timer_timebase_fallback(struct unit_test_state *uts) |
| 33 | { |
| 34 | struct udevice *dev; |
| 35 | |
Heinrich Schuchardt | 8ae8da1 | 2021-08-28 11:42:08 +0200 | [diff] [blame] | 36 | cpu_sandbox_set_current("cpu@1"); |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 37 | ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@1", &dev)); |
| 38 | ut_asserteq(3000000, timer_get_rate(dev)); |
| 39 | ut_assertok(device_remove(dev, DM_REMOVE_NORMAL)); |
| 40 | |
Heinrich Schuchardt | 8ae8da1 | 2021-08-28 11:42:08 +0200 | [diff] [blame] | 41 | cpu_sandbox_set_current("cpu@2"); |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 42 | ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@1", &dev)); |
| 43 | ut_asserteq(2000000, timer_get_rate(dev)); |
| 44 | |
Heinrich Schuchardt | 8ae8da1 | 2021-08-28 11:42:08 +0200 | [diff] [blame] | 45 | cpu_sandbox_set_current("cpu@1"); |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame] | 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | DM_TEST(dm_test_timer_timebase_fallback, |
| 50 | UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |