cpu-uclass.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. U_BOOT_DRIVER(cpu_bus) = {
  36. .name = "cpu_bus",
  37. .id = UCLASS_SIMPLE_BUS,
  38. .per_child_platdata_auto_alloc_size = sizeof(struct cpu_platdata),
  39. };
  40. static int uclass_cpu_init(struct uclass *uc)
  41. {
  42. struct udevice *dev;
  43. int node;
  44. int ret;
  45. node = fdt_path_offset(gd->fdt_blob, "/cpus");
  46. if (node < 0)
  47. return 0;
  48. ret = device_bind_driver_to_node(dm_root(), "cpu_bus", "cpus", node,
  49. &dev);
  50. return ret;
  51. }
  52. UCLASS_DRIVER(cpu) = {
  53. .id = UCLASS_CPU,
  54. .name = "cpu",
  55. .flags = DM_UC_FLAG_SEQ_ALIAS,
  56. .init = uclass_cpu_init,
  57. };