mirror of
https://github.com/u-boot/u-boot.git
synced 2025-01-19 17:23:24 +08:00
timer: Add a test for timer_timebase_fallback
To test this function, sandbox CPU must set cpu_platdata.timebase_freq on bind. It also needs to expose a method to set the current cpu. I also make some most members of cpu_sandbox_ops static. On the timer side, the device tree property sandbox,timebase-frequency-fallback controls whether sandbox_timer_probe falls back to time_timebase_fallback or to SANDBOX_TIMER_RATE. Signed-off-by: Sean Anderson <seanga2@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
3576121687
commit
7616e3687e
@ -533,7 +533,9 @@
|
||||
};
|
||||
|
||||
cpus {
|
||||
timebase-frequency = <2000000>;
|
||||
cpu-test1 {
|
||||
timebase-frequency = <3000000>;
|
||||
compatible = "sandbox,cpu_sandbox";
|
||||
u-boot,dm-pre-reloc;
|
||||
};
|
||||
@ -839,11 +841,16 @@
|
||||
0x58 8>;
|
||||
};
|
||||
|
||||
timer {
|
||||
timer@0 {
|
||||
compatible = "sandbox,timer";
|
||||
clock-frequency = <1000000>;
|
||||
};
|
||||
|
||||
timer@1 {
|
||||
compatible = "sandbox,timer";
|
||||
sandbox,timebase-frequency-fallback;
|
||||
};
|
||||
|
||||
tpm2 {
|
||||
compatible = "sandbox,tpm2";
|
||||
};
|
||||
|
11
arch/sandbox/include/asm/cpu.h
Normal file
11
arch/sandbox/include/asm/cpu.h
Normal file
@ -0,0 +1,11 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0+ */
|
||||
/*
|
||||
* Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef __SANDBOX_CPU_H
|
||||
#define __SANDBOX_CPU_H
|
||||
|
||||
void cpu_sandbox_set_current(const char *name);
|
||||
|
||||
#endif /* __SANDBOX_CPU_H */
|
@ -8,14 +8,15 @@
|
||||
#include <dm.h>
|
||||
#include <cpu.h>
|
||||
|
||||
int cpu_sandbox_get_desc(const struct udevice *dev, char *buf, int size)
|
||||
static int cpu_sandbox_get_desc(const struct udevice *dev, char *buf, int size)
|
||||
{
|
||||
snprintf(buf, size, "LEG Inc. SuperMegaUltraTurbo CPU No. 1");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cpu_sandbox_get_info(const struct udevice *dev, struct cpu_info *info)
|
||||
static int cpu_sandbox_get_info(const struct udevice *dev,
|
||||
struct cpu_info *info)
|
||||
{
|
||||
info->cpu_freq = 42 * 42 * 42 * 42 * 42;
|
||||
info->features = 0x42424242;
|
||||
@ -24,21 +25,29 @@ int cpu_sandbox_get_info(const struct udevice *dev, struct cpu_info *info)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cpu_sandbox_get_count(const struct udevice *dev)
|
||||
static int cpu_sandbox_get_count(const struct udevice *dev)
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
int cpu_sandbox_get_vendor(const struct udevice *dev, char *buf, int size)
|
||||
static int cpu_sandbox_get_vendor(const struct udevice *dev, char *buf,
|
||||
int size)
|
||||
{
|
||||
snprintf(buf, size, "Languid Example Garbage Inc.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cpu_sandbox_is_current(struct udevice *dev)
|
||||
static const char *cpu_current = "cpu-test1";
|
||||
|
||||
void cpu_sandbox_set_current(const char *name)
|
||||
{
|
||||
if (!strcmp(dev->name, "cpu-test1"))
|
||||
cpu_current = name;
|
||||
}
|
||||
|
||||
static int cpu_sandbox_is_current(struct udevice *dev)
|
||||
{
|
||||
if (!strcmp(dev->name, cpu_current))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
@ -52,7 +61,22 @@ static const struct cpu_ops cpu_sandbox_ops = {
|
||||
.is_current = cpu_sandbox_is_current,
|
||||
};
|
||||
|
||||
int cpu_sandbox_probe(struct udevice *dev)
|
||||
static int cpu_sandbox_bind(struct udevice *dev)
|
||||
{
|
||||
int ret;
|
||||
struct cpu_platdata *plat = dev_get_parent_platdata(dev);
|
||||
|
||||
/* first examine the property in current cpu node */
|
||||
ret = dev_read_u32(dev, "timebase-frequency", &plat->timebase_freq);
|
||||
/* if not found, then look at the parent /cpus node */
|
||||
if (ret)
|
||||
ret = dev_read_u32(dev->parent, "timebase-frequency",
|
||||
&plat->timebase_freq);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int cpu_sandbox_probe(struct udevice *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -67,5 +91,6 @@ U_BOOT_DRIVER(cpu_sandbox) = {
|
||||
.id = UCLASS_CPU,
|
||||
.ops = &cpu_sandbox_ops,
|
||||
.of_match = cpu_sandbox_ids,
|
||||
.bind = cpu_sandbox_bind,
|
||||
.probe = cpu_sandbox_probe,
|
||||
};
|
||||
|
@ -40,7 +40,9 @@ static int sandbox_timer_probe(struct udevice *dev)
|
||||
{
|
||||
struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
|
||||
|
||||
if (!uc_priv->clock_rate)
|
||||
if (dev_read_bool(dev, "sandbox,timebase-frequency-fallback"))
|
||||
return timer_timebase_fallback(dev);
|
||||
else if (!uc_priv->clock_rate)
|
||||
uc_priv->clock_rate = SANDBOX_TIMER_RATE;
|
||||
|
||||
return 0;
|
||||
|
@ -7,8 +7,10 @@
|
||||
#include <dm.h>
|
||||
#include <timer.h>
|
||||
#include <dm/test.h>
|
||||
#include <dm/device-internal.h>
|
||||
#include <test/test.h>
|
||||
#include <test/ut.h>
|
||||
#include <asm/cpu.h>
|
||||
|
||||
/*
|
||||
* Basic test of the timer uclass.
|
||||
@ -17,9 +19,32 @@ static int dm_test_timer_base(struct unit_test_state *uts)
|
||||
{
|
||||
struct udevice *dev;
|
||||
|
||||
ut_assertok(uclass_get_device(UCLASS_TIMER, 0, &dev));
|
||||
ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@0", &dev));
|
||||
ut_asserteq(1000000, timer_get_rate(dev));
|
||||
|
||||
return 0;
|
||||
}
|
||||
DM_TEST(dm_test_timer_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
||||
|
||||
/*
|
||||
* Test of timebase fallback
|
||||
*/
|
||||
static int dm_test_timer_timebase_fallback(struct unit_test_state *uts)
|
||||
{
|
||||
struct udevice *dev;
|
||||
|
||||
cpu_sandbox_set_current("cpu-test1");
|
||||
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));
|
||||
|
||||
cpu_sandbox_set_current("cpu-test2");
|
||||
ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@1", &dev));
|
||||
ut_asserteq(2000000, timer_get_rate(dev));
|
||||
|
||||
cpu_sandbox_set_current("cpu-test1");
|
||||
|
||||
return 0;
|
||||
}
|
||||
DM_TEST(dm_test_timer_timebase_fallback,
|
||||
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
||||
|
Loading…
Reference in New Issue
Block a user