cpu-uclass.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. */
  6. #include <common.h>
  7. #include <cpu.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <dm/lists.h>
  11. #include <dm/root.h>
  12. int cpu_probe_all(void)
  13. {
  14. struct udevice *cpu;
  15. int ret;
  16. ret = uclass_first_device(UCLASS_CPU, &cpu);
  17. if (ret) {
  18. debug("%s: No CPU found (err = %d)\n", __func__, ret);
  19. return ret;
  20. }
  21. while (cpu) {
  22. ret = uclass_next_device(&cpu);
  23. if (ret) {
  24. debug("%s: Error while probing CPU (err = %d)\n",
  25. __func__, ret);
  26. return ret;
  27. }
  28. }
  29. return 0;
  30. }
  31. int cpu_get_desc(struct udevice *dev, char *buf, int size)
  32. {
  33. struct cpu_ops *ops = cpu_get_ops(dev);
  34. if (!ops->get_desc)
  35. return -ENOSYS;
  36. return ops->get_desc(dev, buf, size);
  37. }
  38. int cpu_get_info(struct udevice *dev, struct cpu_info *info)
  39. {
  40. struct cpu_ops *ops = cpu_get_ops(dev);
  41. if (!ops->get_info)
  42. return -ENOSYS;
  43. return ops->get_info(dev, info);
  44. }
  45. int cpu_get_count(struct udevice *dev)
  46. {
  47. struct cpu_ops *ops = cpu_get_ops(dev);
  48. if (!ops->get_count)
  49. return -ENOSYS;
  50. return ops->get_count(dev);
  51. }
  52. int cpu_get_vendor(struct udevice *dev, char *buf, int size)
  53. {
  54. struct cpu_ops *ops = cpu_get_ops(dev);
  55. if (!ops->get_vendor)
  56. return -ENOSYS;
  57. return ops->get_vendor(dev, buf, size);
  58. }
  59. U_BOOT_DRIVER(cpu_bus) = {
  60. .name = "cpu_bus",
  61. .id = UCLASS_SIMPLE_BUS,
  62. .per_child_platdata_auto_alloc_size = sizeof(struct cpu_platdata),
  63. };
  64. static int uclass_cpu_init(struct uclass *uc)
  65. {
  66. struct udevice *dev;
  67. ofnode node;
  68. int ret;
  69. node = ofnode_path("/cpus");
  70. if (!ofnode_valid(node))
  71. return 0;
  72. ret = device_bind_driver_to_node(dm_root(), "cpu_bus", "cpus", node,
  73. &dev);
  74. return ret;
  75. }
  76. UCLASS_DRIVER(cpu) = {
  77. .id = UCLASS_CPU,
  78. .name = "cpu",
  79. .flags = DM_UC_FLAG_SEQ_ALIAS,
  80. .init = uclass_cpu_init,
  81. };