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
cpu_sandbox_get_desc(const struct udevice * dev,char * buf,int size)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
cpu_sandbox_get_info(const struct udevice * dev,struct cpu_info * info)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
cpu_sandbox_get_count(const struct udevice * dev)28 static int cpu_sandbox_get_count(const struct udevice *dev)
29 {
30 return 42;
31 }
32
cpu_sandbox_get_vendor(const struct udevice * dev,char * buf,int size)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@1";
42
cpu_sandbox_set_current(const char * name)43 void cpu_sandbox_set_current(const char *name)
44 {
45 cpu_current = name;
46 }
47
cpu_sandbox_is_current(struct udevice * dev)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
cpu_sandbox_bind(struct udevice * dev)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
cpu_sandbox_probe(struct udevice * dev)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 };
97