phy.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
  4. * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <generic-phy.h>
  9. #include <log.h>
  10. #include <dm/test.h>
  11. #include <test/test.h>
  12. #include <test/ut.h>
  13. /* Base test of the phy uclass */
  14. static int dm_test_phy_base(struct unit_test_state *uts)
  15. {
  16. struct udevice *dev;
  17. struct phy phy1_method1;
  18. struct phy phy1_method2;
  19. struct phy phy2;
  20. struct phy phy3;
  21. struct udevice *parent;
  22. /* Get the device using the phy device*/
  23. ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
  24. "gen_phy_user", &parent));
  25. /*
  26. * Get the same phy port in 2 different ways and compare.
  27. */
  28. ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1_method1))
  29. ut_assertok(generic_phy_get_by_index(parent, 0, &phy1_method2))
  30. ut_asserteq(phy1_method1.id, phy1_method2.id);
  31. /*
  32. * Get the second phy port. Check that the same phy provider (device)
  33. * provides this 2nd phy port, but that the IDs are different
  34. */
  35. ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2))
  36. ut_asserteq_ptr(phy1_method2.dev, phy2.dev);
  37. ut_assert(phy1_method1.id != phy2.id);
  38. /*
  39. * Get the third phy port. Check that the phy provider is different
  40. */
  41. ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3))
  42. ut_assert(phy2.dev != phy3.dev);
  43. /* Try to get a non-existing phy */
  44. ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 4, &dev));
  45. ut_asserteq(-ENODATA, generic_phy_get_by_name(parent,
  46. "phy_not_existing", &phy1_method1));
  47. return 0;
  48. }
  49. DM_TEST(dm_test_phy_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  50. /* Test of the phy uclass using the sandbox phy driver operations */
  51. static int dm_test_phy_ops(struct unit_test_state *uts)
  52. {
  53. struct phy phy1;
  54. struct phy phy2;
  55. struct phy phy3;
  56. struct udevice *parent;
  57. ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
  58. "gen_phy_user", &parent));
  59. ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1));
  60. ut_asserteq(0, phy1.id);
  61. ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2));
  62. ut_asserteq(1, phy2.id);
  63. ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3));
  64. ut_asserteq(0, phy3.id);
  65. /* test normal operations */
  66. ut_assertok(generic_phy_init(&phy1));
  67. ut_assertok(generic_phy_power_on(&phy1));
  68. ut_assertok(generic_phy_power_off(&phy1));
  69. /*
  70. * test operations after exit().
  71. * The sandbox phy driver does not allow it.
  72. */
  73. ut_assertok(generic_phy_exit(&phy1));
  74. ut_assert(generic_phy_power_on(&phy1) != 0);
  75. ut_assert(generic_phy_power_off(&phy1) != 0);
  76. /*
  77. * test normal operations again (after re-init)
  78. */
  79. ut_assertok(generic_phy_init(&phy1));
  80. ut_assertok(generic_phy_power_on(&phy1));
  81. ut_assertok(generic_phy_power_off(&phy1));
  82. /*
  83. * test calling unimplemented feature.
  84. * The call is expected to succeed
  85. */
  86. ut_assertok(generic_phy_reset(&phy1));
  87. /* PHY2 has a known problem with power off */
  88. ut_assertok(generic_phy_init(&phy2));
  89. ut_assertok(generic_phy_power_on(&phy2));
  90. ut_asserteq(-EIO, generic_phy_power_off(&phy2));
  91. /* PHY3 has a known problem with power off and power on */
  92. ut_assertok(generic_phy_init(&phy3));
  93. ut_asserteq(-EIO, generic_phy_power_off(&phy3));
  94. ut_asserteq(-EIO, generic_phy_power_off(&phy3));
  95. return 0;
  96. }
  97. DM_TEST(dm_test_phy_ops, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  98. static int dm_test_phy_bulk(struct unit_test_state *uts)
  99. {
  100. struct phy_bulk phys;
  101. struct udevice *parent;
  102. /* test normal operations */
  103. ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
  104. "gen_phy_user1", &parent));
  105. ut_assertok(generic_phy_get_bulk(parent, &phys));
  106. ut_asserteq(2, phys.count);
  107. ut_asserteq(0, generic_phy_init_bulk(&phys));
  108. ut_asserteq(0, generic_phy_power_on_bulk(&phys));
  109. ut_asserteq(0, generic_phy_power_off_bulk(&phys));
  110. ut_asserteq(0, generic_phy_exit_bulk(&phys));
  111. /* has a known problem phy */
  112. ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
  113. "gen_phy_user", &parent));
  114. ut_assertok(generic_phy_get_bulk(parent, &phys));
  115. ut_asserteq(3, phys.count);
  116. ut_asserteq(0, generic_phy_init_bulk(&phys));
  117. ut_asserteq(-EIO, generic_phy_power_on_bulk(&phys));
  118. ut_asserteq(-EIO, generic_phy_power_off_bulk(&phys));
  119. ut_asserteq(0, generic_phy_exit_bulk(&phys));
  120. return 0;
  121. }
  122. DM_TEST(dm_test_phy_bulk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);