cpu-uclass.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_get_desc(struct udevice *dev, char *buf, int size)
  13. {
  14. struct cpu_ops *ops = cpu_get_ops(dev);
  15. if (!ops->get_desc)
  16. return -ENOSYS;
  17. return ops->get_desc(dev, buf, size);
  18. }
  19. int cpu_get_info(struct udevice *dev, struct cpu_info *info)
  20. {
  21. struct cpu_ops *ops = cpu_get_ops(dev);
  22. if (!ops->get_info)
  23. return -ENOSYS;
  24. return ops->get_info(dev, info);
  25. }
  26. int cpu_get_count(struct udevice *dev)
  27. {
  28. struct cpu_ops *ops = cpu_get_ops(dev);
  29. if (!ops->get_count)
  30. return -ENOSYS;
  31. return ops->get_count(dev);
  32. }
  33. int cpu_get_vendor(struct udevice *dev, char *buf, int size)
  34. {
  35. struct cpu_ops *ops = cpu_get_ops(dev);
  36. if (!ops->get_vendor)
  37. return -ENOSYS;
  38. return ops->get_vendor(dev, buf, size);
  39. }
  40. U_BOOT_DRIVER(cpu_bus) = {
  41. .name = "cpu_bus",
  42. .id = UCLASS_SIMPLE_BUS,
  43. .per_child_platdata_auto_alloc_size = sizeof(struct cpu_platdata),
  44. };
  45. static int uclass_cpu_init(struct uclass *uc)
  46. {
  47. struct udevice *dev;
  48. ofnode node;
  49. int ret;
  50. node = ofnode_path("/cpus");
  51. if (!ofnode_valid(node))
  52. return 0;
  53. ret = device_bind_driver_to_node(dm_root(), "cpu_bus", "cpus", node,
  54. &dev);
  55. return ret;
  56. }
  57. UCLASS_DRIVER(cpu) = {
  58. .id = UCLASS_CPU,
  59. .name = "cpu",
  60. .flags = DM_UC_FLAG_SEQ_ALIAS,
  61. .init = uclass_cpu_init,
  62. };