csky_cpu.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2017-2020 Alibaba Group Holding Limited
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <cpu.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <dm/device-internal.h>
  11. #include <dm/lists.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. static int csky_cpu_get_desc(struct udevice *dev, char *buf, int size)
  14. {
  15. const char *isa;
  16. isa = dev_read_string(dev, "csky,isa");
  17. if (size < (strlen(isa) + 1))
  18. return -ENOSPC;
  19. strcpy(buf, isa);
  20. return 0;
  21. }
  22. static int csky_cpu_get_info(struct udevice *dev, struct cpu_info *info)
  23. {
  24. dev_read_u32(dev, "clock-frequency", (u32 *)&info->cpu_freq);
  25. return 0;
  26. }
  27. static int csky_cpu_get_count(struct udevice *dev)
  28. {
  29. ofnode node;
  30. int num = 0;
  31. ofnode_for_each_subnode(node, dev_ofnode(dev->parent)) {
  32. const char *device_type;
  33. /* skip if hart is marked as not available in the device tree */
  34. if (!ofnode_is_available(node))
  35. continue;
  36. device_type = ofnode_read_string(node, "device_type");
  37. if (!device_type)
  38. continue;
  39. if (strcmp(device_type, "cpu") == 0)
  40. num++;
  41. }
  42. return num;
  43. }
  44. static const struct cpu_ops csky_cpu_ops = {
  45. .get_desc = csky_cpu_get_desc,
  46. .get_info = csky_cpu_get_info,
  47. .get_count = csky_cpu_get_count,
  48. };
  49. static const struct udevice_id csky_cpu_ids[] = {
  50. { .compatible = "csky" },
  51. { }
  52. };
  53. U_BOOT_DRIVER(csky_cpu) = {
  54. .name = "csky_cpu",
  55. .id = UCLASS_CPU,
  56. .of_match = csky_cpu_ids,
  57. .ops = &csky_cpu_ops,
  58. .flags = DM_FLAG_PRE_RELOC,
  59. };