2 * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
4 * SPDX-License-Identifier: GPL-2.0+
13 /* system timer offset in ms */
14 static unsigned long sandbox_timer_offset;
16 void sandbox_timer_add_offset(unsigned long offset)
18 sandbox_timer_offset += offset;
21 static int sandbox_timer_get_count(struct udevice *dev, u64 *count)
23 *count = os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
28 static int sandbox_timer_probe(struct udevice *dev)
30 struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
32 if (!uc_priv->clock_rate)
33 uc_priv->clock_rate = 1000000;
38 static const struct timer_ops sandbox_timer_ops = {
39 .get_count = sandbox_timer_get_count,
42 static const struct udevice_id sandbox_timer_ids[] = {
43 { .compatible = "sandbox,timer" },
47 U_BOOT_DRIVER(sandbox_timer) = {
48 .name = "sandbox_timer",
50 .of_match = sandbox_timer_ids,
51 .probe = sandbox_timer_probe,
52 .ops = &sandbox_timer_ops,
53 .flags = DM_FLAG_PRE_RELOC,
56 /* This is here in case we don't have a device tree */
57 U_BOOT_DEVICE(sandbox_timer_non_fdt) = {
58 .name = "sandbox_timer",