clk: versal: Add support to enable clocks
[pandora-u-boot.git] / drivers / cpu / cpu_sandbox.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2018
4  * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
5  */
6
7 #include <common.h>
8 #include <dm.h>
9 #include <cpu.h>
10
11 static int cpu_sandbox_get_desc(const struct udevice *dev, char *buf, int size)
12 {
13         snprintf(buf, size, "LEG Inc. SuperMegaUltraTurbo CPU No. 1");
14
15         return 0;
16 }
17
18 static int cpu_sandbox_get_info(const struct udevice *dev,
19                                 struct cpu_info *info)
20 {
21         info->cpu_freq = 42 * 42 * 42 * 42 * 42;
22         info->features = 0x42424242;
23         info->address_width = IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32;
24
25         return 0;
26 }
27
28 static int cpu_sandbox_get_count(const struct udevice *dev)
29 {
30         return 42;
31 }
32
33 static int cpu_sandbox_get_vendor(const struct udevice *dev, char *buf,
34                                   int size)
35 {
36         snprintf(buf, size, "Languid Example Garbage Inc.");
37
38         return 0;
39 }
40
41 static const char *cpu_current = "cpu-test1";
42
43 void cpu_sandbox_set_current(const char *name)
44 {
45         cpu_current = name;
46 }
47
48 static int cpu_sandbox_is_current(struct udevice *dev)
49 {
50         if (!strcmp(dev->name, cpu_current))
51                 return 1;
52
53         return 0;
54 }
55
56 static const struct cpu_ops cpu_sandbox_ops = {
57         .get_desc = cpu_sandbox_get_desc,
58         .get_info = cpu_sandbox_get_info,
59         .get_count = cpu_sandbox_get_count,
60         .get_vendor = cpu_sandbox_get_vendor,
61         .is_current = cpu_sandbox_is_current,
62 };
63
64 static int cpu_sandbox_bind(struct udevice *dev)
65 {
66         int ret;
67         struct cpu_plat *plat = dev_get_parent_plat(dev);
68
69         /* first examine the property in current cpu node */
70         ret = dev_read_u32(dev, "timebase-frequency", &plat->timebase_freq);
71         /* if not found, then look at the parent /cpus node */
72         if (ret)
73                 ret = dev_read_u32(dev->parent, "timebase-frequency",
74                                    &plat->timebase_freq);
75
76         return ret;
77 }
78
79 static int cpu_sandbox_probe(struct udevice *dev)
80 {
81         return 0;
82 }
83
84 static const struct udevice_id cpu_sandbox_ids[] = {
85         { .compatible = "sandbox,cpu_sandbox" },
86         { }
87 };
88
89 U_BOOT_DRIVER(cpu_sandbox) = {
90         .name           = "cpu_sandbox",
91         .id             = UCLASS_CPU,
92         .ops            = &cpu_sandbox_ops,
93         .of_match       = cpu_sandbox_ids,
94         .bind           = cpu_sandbox_bind,
95         .probe          = cpu_sandbox_probe,
96 };