blob: b15279578315c486d53ad1f278f469bd7a874922 [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
Mario Sixdea5df72018-08-06 10:23:44 +02007#include <dm.h>
8#include <cpu.h>
9
Sean Anderson79d3bba2020-09-28 10:52:23 -040010static int cpu_sandbox_get_desc(const struct udevice *dev, char *buf, int size)
Mario Sixdea5df72018-08-06 10:23:44 +020011{
12 snprintf(buf, size, "LEG Inc. SuperMegaUltraTurbo CPU No. 1");
13
14 return 0;
15}
16
Sean Anderson79d3bba2020-09-28 10:52:23 -040017static int cpu_sandbox_get_info(const struct udevice *dev,
18 struct cpu_info *info)
Mario Sixdea5df72018-08-06 10:23:44 +020019{
20 info->cpu_freq = 42 * 42 * 42 * 42 * 42;
21 info->features = 0x42424242;
Simon Glassc35854a2020-04-08 16:57:20 -060022 info->address_width = IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32;
Mario Sixdea5df72018-08-06 10:23:44 +020023
24 return 0;
25}
26
Sean Anderson79d3bba2020-09-28 10:52:23 -040027static int cpu_sandbox_get_count(const struct udevice *dev)
Mario Sixdea5df72018-08-06 10:23:44 +020028{
29 return 42;
30}
31
Sean Anderson79d3bba2020-09-28 10:52:23 -040032static int cpu_sandbox_get_vendor(const struct udevice *dev, char *buf,
33 int size)
Mario Sixdea5df72018-08-06 10:23:44 +020034{
35 snprintf(buf, size, "Languid Example Garbage Inc.");
36
37 return 0;
38}
39
Heinrich Schuchardt20f9d3d2021-08-28 11:42:08 +020040static const char *cpu_current = "cpu@1";
Sean Anderson79d3bba2020-09-28 10:52:23 -040041
42void cpu_sandbox_set_current(const char *name)
Peng Fan35c589a2020-05-03 21:58:48 +080043{
Sean Anderson79d3bba2020-09-28 10:52:23 -040044 cpu_current = name;
45}
46
Hou Zhiqiang42744522024-08-01 11:59:48 +080047static int cpu_sandbox_release_core(const struct udevice *dev, phys_addr_t addr)
48{
49 return 0;
50}
51
Sean Anderson79d3bba2020-09-28 10:52:23 -040052static int cpu_sandbox_is_current(struct udevice *dev)
53{
54 if (!strcmp(dev->name, cpu_current))
Peng Fan35c589a2020-05-03 21:58:48 +080055 return 1;
56
57 return 0;
58}
59
Mario Sixdea5df72018-08-06 10:23:44 +020060static const struct cpu_ops cpu_sandbox_ops = {
61 .get_desc = cpu_sandbox_get_desc,
62 .get_info = cpu_sandbox_get_info,
63 .get_count = cpu_sandbox_get_count,
64 .get_vendor = cpu_sandbox_get_vendor,
Peng Fan35c589a2020-05-03 21:58:48 +080065 .is_current = cpu_sandbox_is_current,
Hou Zhiqiang42744522024-08-01 11:59:48 +080066 .release_core = cpu_sandbox_release_core,
Mario Sixdea5df72018-08-06 10:23:44 +020067};
68
Sean Anderson79d3bba2020-09-28 10:52:23 -040069static int cpu_sandbox_bind(struct udevice *dev)
70{
71 int ret;
Simon Glassb75b15b2020-12-03 16:55:23 -070072 struct cpu_plat *plat = dev_get_parent_plat(dev);
Sean Anderson79d3bba2020-09-28 10:52:23 -040073
74 /* first examine the property in current cpu node */
75 ret = dev_read_u32(dev, "timebase-frequency", &plat->timebase_freq);
76 /* if not found, then look at the parent /cpus node */
77 if (ret)
78 ret = dev_read_u32(dev->parent, "timebase-frequency",
79 &plat->timebase_freq);
80
81 return ret;
82}
83
84static int cpu_sandbox_probe(struct udevice *dev)
Mario Sixdea5df72018-08-06 10:23:44 +020085{
86 return 0;
87}
88
89static const struct udevice_id cpu_sandbox_ids[] = {
90 { .compatible = "sandbox,cpu_sandbox" },
91 { }
92};
93
94U_BOOT_DRIVER(cpu_sandbox) = {
95 .name = "cpu_sandbox",
96 .id = UCLASS_CPU,
97 .ops = &cpu_sandbox_ops,
98 .of_match = cpu_sandbox_ids,
Sean Anderson79d3bba2020-09-28 10:52:23 -040099 .bind = cpu_sandbox_bind,
Mario Sixdea5df72018-08-06 10:23:44 +0200100 .probe = cpu_sandbox_probe,
101};