soc-uclass.c 1.8 KB

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