phy.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 <dm/test.h>
  10. #include <test/ut.h>
  11. /* Base test of the phy uclass */
  12. static int dm_test_phy_base(struct unit_test_state *uts)
  13. {
  14. struct udevice *dev;
  15. struct phy phy1_method1;
  16. struct phy phy1_method2;
  17. struct phy phy2;
  18. struct phy phy3;
  19. struct udevice *parent;
  20. /* Get the device using the phy device*/
  21. ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
  22. "gen_phy_user", &parent));
  23. /*
  24. * Get the same phy port in 2 different ways and compare.
  25. */
  26. ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1_method1))
  27. ut_assertok(generic_phy_get_by_index(parent, 0, &phy1_method2))
  28. ut_asserteq(phy1_method1.id, phy1_method2.id);
  29. /*
  30. * Get the second phy port. Check that the same phy provider (device)
  31. * provides this 2nd phy port, but that the IDs are different
  32. */
  33. ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2))
  34. ut_asserteq_ptr(phy1_method2.dev, phy2.dev);
  35. ut_assert(phy1_method1.id != phy2.id);
  36. /*
  37. * Get the third phy port. Check that the phy provider is different
  38. */
  39. ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3))
  40. ut_assert(phy2.dev != phy3.dev);
  41. /* Try to get a non-existing phy */
  42. ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 3, &dev));
  43. ut_asserteq(-ENODATA, generic_phy_get_by_name(parent,
  44. "phy_not_existing", &phy1_method1));
  45. return 0;
  46. }
  47. DM_TEST(dm_test_phy_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  48. /* Test of the phy uclass using the sandbox phy driver operations */
  49. static int dm_test_phy_ops(struct unit_test_state *uts)
  50. {
  51. struct phy phy1;
  52. struct phy phy2;
  53. struct phy phy3;
  54. struct udevice *parent;
  55. ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
  56. "gen_phy_user", &parent));
  57. ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1));
  58. ut_asserteq(0, phy1.id);
  59. ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2));
  60. ut_asserteq(1, phy2.id);
  61. ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3));
  62. ut_asserteq(0, phy3.id);
  63. /* test normal operations */
  64. ut_assertok(generic_phy_init(&phy1));
  65. ut_assertok(generic_phy_power_on(&phy1));
  66. ut_assertok(generic_phy_power_off(&phy1));
  67. /*
  68. * test operations after exit().
  69. * The sandbox phy driver does not allow it.
  70. */
  71. ut_assertok(generic_phy_exit(&phy1));
  72. ut_assert(generic_phy_power_on(&phy1) != 0);
  73. ut_assert(generic_phy_power_off(&phy1) != 0);
  74. /*
  75. * test normal operations again (after re-init)
  76. */
  77. ut_assertok(generic_phy_init(&phy1));
  78. ut_assertok(generic_phy_power_on(&phy1));
  79. ut_assertok(generic_phy_power_off(&phy1));
  80. /*
  81. * test calling unimplemented feature.
  82. * The call is expected to succeed
  83. */
  84. ut_assertok(generic_phy_reset(&phy1));
  85. /* PHY2 has a known problem with power off */
  86. ut_assertok(generic_phy_init(&phy2));
  87. ut_assertok(generic_phy_power_on(&phy2));
  88. ut_asserteq(-EIO, generic_phy_power_off(&phy2));
  89. /* PHY3 has a known problem with power off and power on */
  90. ut_assertok(generic_phy_init(&phy3));
  91. ut_asserteq(-EIO, generic_phy_power_off(&phy3));
  92. ut_asserteq(-EIO, generic_phy_power_off(&phy3));
  93. return 0;
  94. }
  95. DM_TEST(dm_test_phy_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);