blob: e65e1bdc51bfafe93b303c12ae8aabb8503eb267 [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
47static int cpu_sandbox_is_current(struct udevice *dev)
48{
49 if (!strcmp(dev->name, cpu_current))
Peng Fan35c589a2020-05-03 21:58:48 +080050 return 1;
51
52 return 0;
53}
54
Mario Sixdea5df72018-08-06 10:23:44 +020055static const struct cpu_ops cpu_sandbox_ops = {
56 .get_desc = cpu_sandbox_get_desc,
57 .get_info = cpu_sandbox_get_info,
58 .get_count = cpu_sandbox_get_count,
59 .get_vendor = cpu_sandbox_get_vendor,
Peng Fan35c589a2020-05-03 21:58:48 +080060 .is_current = cpu_sandbox_is_current,
Mario Sixdea5df72018-08-06 10:23:44 +020061};
62
Sean Anderson79d3bba2020-09-28 10:52:23 -040063static int cpu_sandbox_bind(struct udevice *dev)
64{
65 int ret;
Simon Glassb75b15b2020-12-03 16:55:23 -070066 struct cpu_plat *plat = dev_get_parent_plat(dev);
Sean Anderson79d3bba2020-09-28 10:52:23 -040067
68 /* first examine the property in current cpu node */
69 ret = dev_read_u32(dev, "timebase-frequency", &plat->timebase_freq);
70 /* if not found, then look at the parent /cpus node */
71 if (ret)
72 ret = dev_read_u32(dev->parent, "timebase-frequency",
73 &plat->timebase_freq);
74
75 return ret;
76}
77
78static int cpu_sandbox_probe(struct udevice *dev)
Mario Sixdea5df72018-08-06 10:23:44 +020079{
80 return 0;
81}
82
83static const struct udevice_id cpu_sandbox_ids[] = {
84 { .compatible = "sandbox,cpu_sandbox" },
85 { }
86};
87
88U_BOOT_DRIVER(cpu_sandbox) = {
89 .name = "cpu_sandbox",
90 .id = UCLASS_CPU,
91 .ops = &cpu_sandbox_ops,
92 .of_match = cpu_sandbox_ids,
Sean Anderson79d3bba2020-09-28 10:52:23 -040093 .bind = cpu_sandbox_bind,
Mario Sixdea5df72018-08-06 10:23:44 +020094 .probe = cpu_sandbox_probe,
95};