soc-uclass.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2020 - Texas Instruments Incorporated - http://www.ti.com/
  4. * Dave Gerlach <d-gerlach@ti.com>
  5. */
  6. #include <common.h>
  7. #include <soc.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <dm/lists.h>
  11. #include <dm/root.h>
  12. int soc_get(struct udevice **devp)
  13. {
  14. return uclass_first_device_err(UCLASS_SOC, devp);
  15. }
  16. int soc_get_machine(struct udevice *dev, char *buf, int size)
  17. {
  18. struct soc_ops *ops = soc_get_ops(dev);
  19. if (!ops->get_machine)
  20. return -ENOSYS;
  21. return ops->get_machine(dev, buf, size);
  22. }
  23. int soc_get_family(struct udevice *dev, char *buf, int size)
  24. {
  25. struct soc_ops *ops = soc_get_ops(dev);
  26. if (!ops->get_family)
  27. return -ENOSYS;
  28. return ops->get_family(dev, buf, size);
  29. }
  30. int soc_get_revision(struct udevice *dev, char *buf, int size)
  31. {
  32. struct soc_ops *ops = soc_get_ops(dev);
  33. if (!ops->get_revision)
  34. return -ENOSYS;
  35. return ops->get_revision(dev, buf, size);
  36. }
  37. const struct soc_attr *
  38. soc_device_match(const struct soc_attr *matches)
  39. {
  40. bool match;
  41. struct udevice *soc;
  42. char str[SOC_MAX_STR_SIZE];
  43. if (!matches)
  44. return NULL;
  45. if (soc_get(&soc))
  46. return NULL;
  47. while (1) {
  48. if (!(matches->machine || matches->family ||
  49. matches->revision))
  50. break;
  51. match = true;
  52. if (matches->machine) {
  53. if (!soc_get_machine(soc, str, SOC_MAX_STR_SIZE)) {
  54. if (strcmp(matches->machine, str))
  55. match = false;
  56. }
  57. }
  58. if (matches->family) {
  59. if (!soc_get_family(soc, str, SOC_MAX_STR_SIZE)) {
  60. if (strcmp(matches->family, str))
  61. match = false;
  62. }
  63. }
  64. if (matches->revision) {
  65. if (!soc_get_revision(soc, str, SOC_MAX_STR_SIZE)) {
  66. if (strcmp(matches->revision, str))
  67. match = false;
  68. }
  69. }
  70. if (match)
  71. return matches;
  72. matches++;
  73. }
  74. return NULL;
  75. }
  76. UCLASS_DRIVER(soc) = {
  77. .id = UCLASS_SOC,
  78. .name = "soc",
  79. };