spi: nxp_fspi: Ensure width is respected in spi-mem operations
[platform/kernel/u-boot.git] / drivers / timer / sandbox_timer.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
4  */
5
6 #include <common.h>
7 #include <dm.h>
8 #include <errno.h>
9 #include <timer.h>
10 #include <os.h>
11
12 #define SANDBOX_TIMER_RATE      1000000
13
14 /* system timer offset in ms */
15 static unsigned long sandbox_timer_offset;
16
17 void timer_test_add_offset(unsigned long offset)
18 {
19         sandbox_timer_offset += offset;
20 }
21
22 u64 notrace timer_early_get_count(void)
23 {
24         return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
25 }
26
27 unsigned long notrace timer_early_get_rate(void)
28 {
29         return SANDBOX_TIMER_RATE;
30 }
31
32 static notrace u64 sandbox_timer_get_count(struct udevice *dev)
33 {
34         return timer_early_get_count();
35 }
36
37 static int sandbox_timer_probe(struct udevice *dev)
38 {
39         struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
40
41         if (CONFIG_IS_ENABLED(CPU) &&
42             dev_read_bool(dev, "sandbox,timebase-frequency-fallback"))
43                 return timer_timebase_fallback(dev);
44         else if (!uc_priv->clock_rate)
45                 uc_priv->clock_rate = SANDBOX_TIMER_RATE;
46
47         return 0;
48 }
49
50 static const struct timer_ops sandbox_timer_ops = {
51         .get_count = sandbox_timer_get_count,
52 };
53
54 static const struct udevice_id sandbox_timer_ids[] = {
55         { .compatible = "sandbox,timer" },
56         { }
57 };
58
59 U_BOOT_DRIVER(sandbox_timer) = {
60         .name   = "sandbox_timer",
61         .id     = UCLASS_TIMER,
62         .of_match = sandbox_timer_ids,
63         .probe = sandbox_timer_probe,
64         .ops    = &sandbox_timer_ops,
65         .flags = DM_FLAG_PRE_RELOC,
66 };
67
68 /* This is here in case we don't have a device tree */
69 U_BOOT_DRVINFO(sandbox_timer_non_fdt) = {
70         .name = "sandbox_timer",
71 };