blob: 2e871fe313c107d83a0c85e103e406cfe2ed57fe [file] [log] [blame]
Mario Sixdea5df72018-08-06 10:23:44 +02001// 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
Sean Anderson79d3bba2020-09-28 10:52:23 -040011static int cpu_sandbox_get_desc(const struct udevice *dev, char *buf, int size)
Mario Sixdea5df72018-08-06 10:23:44 +020012{
13 snprintf(buf, size, "LEG Inc. SuperMegaUltraTurbo CPU No. 1");
14
15 return 0;
16}
17
Sean Anderson79d3bba2020-09-28 10:52:23 -040018static int cpu_sandbox_get_info(const struct udevice *dev,
19 struct cpu_info *info)
Mario Sixdea5df72018-08-06 10:23:44 +020020{
21 info->cpu_freq = 42 * 42 * 42 * 42 * 42;
22 info->features = 0x42424242;
Simon Glassc35854a2020-04-08 16:57:20 -060023 info->address_width = IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32;
Mario Sixdea5df72018-08-06 10:23:44 +020024
25 return 0;
26}
27
Sean Anderson79d3bba2020-09-28 10:52:23 -040028static int cpu_sandbox_get_count(const struct udevice *dev)
Mario Sixdea5df72018-08-06 10:23:44 +020029{
30 return 42;
31}
32
Sean Anderson79d3bba2020-09-28 10:52:23 -040033static int cpu_sandbox_get_vendor(const struct udevice *dev, char *buf,
34 int size)
Mario Sixdea5df72018-08-06 10:23:44 +020035{
36 snprintf(buf, size, "Languid Example Garbage Inc.");
37
38 return 0;
39}
40
Heinrich Schuchardt20f9d3d2021-08-28 11:42:08 +020041static const char *cpu_current = "cpu@1";
Sean Anderson79d3bba2020-09-28 10:52:23 -040042
43void cpu_sandbox_set_current(const char *name)
Peng Fan35c589a2020-05-03 21:58:48 +080044{
Sean Anderson79d3bba2020-09-28 10:52:23 -040045 cpu_current = name;
46}
47
48static int cpu_sandbox_is_current(struct udevice *dev)
49{
50 if (!strcmp(dev->name, cpu_current))
Peng Fan35c589a2020-05-03 21:58:48 +080051 return 1;
52
53 return 0;
54}
55
Mario Sixdea5df72018-08-06 10:23:44 +020056static 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,
Peng Fan35c589a2020-05-03 21:58:48 +080061 .is_current = cpu_sandbox_is_current,
Mario Sixdea5df72018-08-06 10:23:44 +020062};
63
Sean Anderson79d3bba2020-09-28 10:52:23 -040064static int cpu_sandbox_bind(struct udevice *dev)
65{
66 int ret;
Simon Glassb75b15b2020-12-03 16:55:23 -070067 struct cpu_plat *plat = dev_get_parent_plat(dev);
Sean Anderson79d3bba2020-09-28 10:52:23 -040068
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
79static int cpu_sandbox_probe(struct udevice *dev)
Mario Sixdea5df72018-08-06 10:23:44 +020080{
81 return 0;
82}
83
84static const struct udevice_id cpu_sandbox_ids[] = {
85 { .compatible = "sandbox,cpu_sandbox" },
86 { }
87};
88
89U_BOOT_DRIVER(cpu_sandbox) = {
90 .name = "cpu_sandbox",
91 .id = UCLASS_CPU,
92 .ops = &cpu_sandbox_ops,
93 .of_match = cpu_sandbox_ids,
Sean Anderson79d3bba2020-09-28 10:52:23 -040094 .bind = cpu_sandbox_bind,
Mario Sixdea5df72018-08-06 10:23:44 +020095 .probe = cpu_sandbox_probe,
96};