2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-10-30 07:35:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <timer.h>
|
|
|
|
#include <dm/test.h>
|
2020-09-28 14:52:23 +00:00
|
|
|
#include <dm/device-internal.h>
|
2020-07-19 16:15:37 +00:00
|
|
|
#include <test/test.h>
|
2015-10-30 07:35:52 +00:00
|
|
|
#include <test/ut.h>
|
2020-09-28 14:52:23 +00:00
|
|
|
#include <asm/cpu.h>
|
2015-10-30 07:35:52 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic test of the timer uclass.
|
|
|
|
*/
|
|
|
|
static int dm_test_timer_base(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
|
2020-09-28 14:52:23 +00:00
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@0", &dev));
|
2015-10-30 07:35:52 +00:00
|
|
|
ut_asserteq(1000000, timer_get_rate(dev));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_timer_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-09-28 14:52:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test of timebase fallback
|
|
|
|
*/
|
|
|
|
static int dm_test_timer_timebase_fallback(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
|
2021-08-28 09:42:08 +00:00
|
|
|
cpu_sandbox_set_current("cpu@1");
|
2020-09-28 14:52:23 +00:00
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@1", &dev));
|
|
|
|
ut_asserteq(3000000, timer_get_rate(dev));
|
|
|
|
ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
|
|
|
|
|
2021-08-28 09:42:08 +00:00
|
|
|
cpu_sandbox_set_current("cpu@2");
|
2020-09-28 14:52:23 +00:00
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@1", &dev));
|
|
|
|
ut_asserteq(2000000, timer_get_rate(dev));
|
|
|
|
|
2021-08-28 09:42:08 +00:00
|
|
|
cpu_sandbox_set_current("cpu@1");
|
2020-09-28 14:52:23 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_timer_timebase_fallback,
|
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|