Mario Six | fa44b53 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 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 | |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame^] | 11 | static int cpu_sandbox_get_desc(const struct udevice *dev, char *buf, int size) |
Mario Six | fa44b53 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 12 | { |
| 13 | snprintf(buf, size, "LEG Inc. SuperMegaUltraTurbo CPU No. 1"); |
| 14 | |
| 15 | return 0; |
| 16 | } |
| 17 | |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame^] | 18 | static int cpu_sandbox_get_info(const struct udevice *dev, |
| 19 | struct cpu_info *info) |
Mario Six | fa44b53 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 20 | { |
| 21 | info->cpu_freq = 42 * 42 * 42 * 42 * 42; |
| 22 | info->features = 0x42424242; |
Simon Glass | 600f584 | 2020-04-08 16:57:20 -0600 | [diff] [blame] | 23 | info->address_width = IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32; |
Mario Six | fa44b53 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 24 | |
| 25 | return 0; |
| 26 | } |
| 27 | |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame^] | 28 | static int cpu_sandbox_get_count(const struct udevice *dev) |
Mario Six | fa44b53 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 29 | { |
| 30 | return 42; |
| 31 | } |
| 32 | |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame^] | 33 | static int cpu_sandbox_get_vendor(const struct udevice *dev, char *buf, |
| 34 | int size) |
Mario Six | fa44b53 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 35 | { |
| 36 | snprintf(buf, size, "Languid Example Garbage Inc."); |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame^] | 41 | static const char *cpu_current = "cpu-test1"; |
| 42 | |
| 43 | void cpu_sandbox_set_current(const char *name) |
Peng Fan | b1e894f | 2020-05-03 21:58:48 +0800 | [diff] [blame] | 44 | { |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame^] | 45 | cpu_current = name; |
| 46 | } |
| 47 | |
| 48 | static int cpu_sandbox_is_current(struct udevice *dev) |
| 49 | { |
| 50 | if (!strcmp(dev->name, cpu_current)) |
Peng Fan | b1e894f | 2020-05-03 21:58:48 +0800 | [diff] [blame] | 51 | return 1; |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
Mario Six | fa44b53 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 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, |
Peng Fan | b1e894f | 2020-05-03 21:58:48 +0800 | [diff] [blame] | 61 | .is_current = cpu_sandbox_is_current, |
Mario Six | fa44b53 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame^] | 64 | static int cpu_sandbox_bind(struct udevice *dev) |
| 65 | { |
| 66 | int ret; |
| 67 | struct cpu_platdata *plat = dev_get_parent_platdata(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) |
Mario Six | fa44b53 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 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, |
Sean Anderson | 7616e36 | 2020-09-28 10:52:23 -0400 | [diff] [blame^] | 94 | .bind = cpu_sandbox_bind, |
Mario Six | fa44b53 | 2018-08-06 10:23:44 +0200 | [diff] [blame] | 95 | .probe = cpu_sandbox_probe, |
| 96 | }; |