cpu-uclass.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (C) 2015 Google, Inc
  3. * Written by Simon Glass <sjg@chromium.org>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <cpu.h>
  9. #include <dm.h>
  10. #include <errno.h>
  11. #include <dm/lists.h>
  12. #include <dm/root.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. int cpu_get_desc(struct udevice *dev, char *buf, int size)
  15. {
  16. struct cpu_ops *ops = cpu_get_ops(dev);
  17. if (!ops->get_desc)
  18. return -ENOSYS;
  19. return ops->get_desc(dev, buf, size);
  20. }
  21. int cpu_get_info(struct udevice *dev, struct cpu_info *info)
  22. {
  23. struct cpu_ops *ops = cpu_get_ops(dev);
  24. if (!ops->get_info)
  25. return -ENOSYS;
  26. return ops->get_info(dev, info);
  27. }
  28. int cpu_get_count(struct udevice *dev)
  29. {
  30. struct cpu_ops *ops = cpu_get_ops(dev);
  31. if (!ops->get_count)
  32. return -ENOSYS;
  33. return ops->get_count(dev);
  34. }
  35. int cpu_get_vendor(struct udevice *dev, char *buf, int size)
  36. {
  37. struct cpu_ops *ops = cpu_get_ops(dev);
  38. if (!ops->get_vendor)
  39. return -ENOSYS;
  40. return ops->get_vendor(dev, buf, size);
  41. }
  42. U_BOOT_DRIVER(cpu_bus) = {
  43. .name = "cpu_bus",
  44. .id = UCLASS_SIMPLE_BUS,
  45. .per_child_platdata_auto_alloc_size = sizeof(struct cpu_platdata),
  46. };
  47. static int uclass_cpu_init(struct uclass *uc)
  48. {
  49. struct udevice *dev;
  50. int node;
  51. int ret;
  52. node = fdt_path_offset(gd->fdt_blob, "/cpus");
  53. if (node < 0)
  54. return 0;
  55. ret = device_bind_driver_to_node(dm_root(), "cpu_bus", "cpus", node,
  56. &dev);
  57. return ret;
  58. }
  59. UCLASS_DRIVER(cpu) = {
  60. .id = UCLASS_CPU,
  61. .name = "cpu",
  62. .flags = DM_UC_FLAG_SEQ_ALIAS,
  63. .init = uclass_cpu_init,
  64. };