soc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Test for the SOC uclass
  4. *
  5. * (C) Copyright 2020 - Texas Instruments Incorporated - http://www.ti.com/
  6. * Dave Gerlach <d-gerlach@ti.com>
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <dm/test.h>
  11. #include <dm/uclass-internal.h>
  12. #include <soc.h>
  13. #include <test/ut.h>
  14. struct sb_soc_data {
  15. unsigned long param;
  16. };
  17. static int dm_test_soc(struct unit_test_state *uts)
  18. {
  19. struct udevice *dev;
  20. char text[128];
  21. const struct soc_attr *soc_data;
  22. const struct sb_soc_data *match_data;
  23. static const struct sb_soc_data soc_sandbox1_sr10_data = { 0x91919191 };
  24. static const struct sb_soc_data soc_sandbox123_data = { 0x84848484 };
  25. static const struct soc_attr sb_soc_devices_full[] = {
  26. {
  27. .family = "SANDBOX0xx",
  28. .machine = "SANDBOX012",
  29. .revision = "1.0",
  30. .data = NULL,
  31. },
  32. {
  33. .family = "SANDBOX1xx",
  34. .machine = "SANDBOX107",
  35. .revision = "1.0",
  36. .data = NULL,
  37. },
  38. {
  39. .family = "SANDBOX1xx",
  40. .machine = "SANDBOX123",
  41. .revision = "1.0",
  42. .data = &soc_sandbox123_data,
  43. },
  44. {
  45. .family = "SANDBOX1xx",
  46. .machine = "SANDBOX131",
  47. .revision = "2.0",
  48. .data = NULL,
  49. },
  50. { /* sentinel */ }
  51. };
  52. static const struct soc_attr sb_soc_devices_partial[] = {
  53. {
  54. .family = "SANDBOX0xx",
  55. .revision = "1.0",
  56. .data = NULL,
  57. },
  58. {
  59. .family = "SANDBOX1xx",
  60. .revision = "1.0",
  61. .data = &soc_sandbox1_sr10_data,
  62. },
  63. {
  64. .family = "SANDBOX1xx",
  65. .revision = "2.0",
  66. .data = NULL,
  67. },
  68. { /* sentinel */ }
  69. };
  70. static const struct soc_attr sb_soc_devices_nomatch[] = {
  71. {
  72. .family = "SANDBOX0xx",
  73. .revision = "1.0",
  74. .data = NULL,
  75. },
  76. {
  77. .family = "SANDBOX1xx",
  78. .revision = "2.0",
  79. .data = NULL,
  80. },
  81. { /* sentinel */ }
  82. };
  83. ut_assertok(soc_get(&dev));
  84. ut_assertok(soc_get_machine(dev, text, sizeof(text)));
  85. ut_assertok(strcmp(text, "SANDBOX123"));
  86. ut_assertok(soc_get_family(dev, text, sizeof(text)));
  87. ut_assertok(strcmp(text, "SANDBOX1xx"));
  88. ut_assertok(soc_get_revision(dev, text, sizeof(text)));
  89. ut_asserteq_str(text, "1.0");
  90. soc_data = soc_device_match(sb_soc_devices_full);
  91. ut_assert(soc_data);
  92. match_data = soc_data->data;
  93. ut_asserteq(match_data->param, 0x84848484);
  94. soc_data = soc_device_match(sb_soc_devices_partial);
  95. ut_assert(soc_data);
  96. match_data = soc_data->data;
  97. ut_asserteq(match_data->param, 0x91919191);
  98. soc_data = soc_device_match(sb_soc_devices_nomatch);
  99. ut_asserteq_ptr(soc_data, NULL);
  100. return 0;
  101. }
  102. DM_TEST(dm_test_soc, UT_TESTF_SCAN_FDT);