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