cpu_sandbox.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2018
  4. * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <cpu.h>
  9. static int cpu_sandbox_get_desc(const struct udevice *dev, char *buf, int size)
  10. {
  11. snprintf(buf, size, "LEG Inc. SuperMegaUltraTurbo CPU No. 1");
  12. return 0;
  13. }
  14. static int cpu_sandbox_get_info(const struct udevice *dev,
  15. struct cpu_info *info)
  16. {
  17. info->cpu_freq = 42 * 42 * 42 * 42 * 42;
  18. info->features = 0x42424242;
  19. info->address_width = IS_ENABLED(CONFIG_PHYS_64BIT) ? 64 : 32;
  20. return 0;
  21. }
  22. static int cpu_sandbox_get_count(const struct udevice *dev)
  23. {
  24. return 42;
  25. }
  26. static int cpu_sandbox_get_vendor(const struct udevice *dev, char *buf,
  27. int size)
  28. {
  29. snprintf(buf, size, "Languid Example Garbage Inc.");
  30. return 0;
  31. }
  32. static const char *cpu_current = "cpu-test1";
  33. void cpu_sandbox_set_current(const char *name)
  34. {
  35. cpu_current = name;
  36. }
  37. static int cpu_sandbox_is_current(struct udevice *dev)
  38. {
  39. if (!strcmp(dev->name, cpu_current))
  40. return 1;
  41. return 0;
  42. }
  43. static const struct cpu_ops cpu_sandbox_ops = {
  44. .get_desc = cpu_sandbox_get_desc,
  45. .get_info = cpu_sandbox_get_info,
  46. .get_count = cpu_sandbox_get_count,
  47. .get_vendor = cpu_sandbox_get_vendor,
  48. .is_current = cpu_sandbox_is_current,
  49. };
  50. static int cpu_sandbox_bind(struct udevice *dev)
  51. {
  52. int ret;
  53. struct cpu_plat *plat = dev_get_parent_plat(dev);
  54. /* first examine the property in current cpu node */
  55. ret = dev_read_u32(dev, "timebase-frequency", &plat->timebase_freq);
  56. /* if not found, then look at the parent /cpus node */
  57. if (ret)
  58. ret = dev_read_u32(dev->parent, "timebase-frequency",
  59. &plat->timebase_freq);
  60. return ret;
  61. }
  62. static int cpu_sandbox_probe(struct udevice *dev)
  63. {
  64. return 0;
  65. }
  66. static const struct udevice_id cpu_sandbox_ids[] = {
  67. { .compatible = "sandbox,cpu_sandbox" },
  68. { }
  69. };
  70. U_BOOT_DRIVER(cpu_sandbox) = {
  71. .name = "cpu_sandbox",
  72. .id = UCLASS_CPU,
  73. .ops = &cpu_sandbox_ops,
  74. .of_match = cpu_sandbox_ids,
  75. .bind = cpu_sandbox_bind,
  76. .probe = cpu_sandbox_probe,
  77. };