2 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
3 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <generic-phy.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 /* Base test of the phy uclass */
17 static int dm_test_phy_base(struct unit_test_state *uts)
20 struct phy phy1_method1;
21 struct phy phy1_method2;
24 struct udevice *parent;
26 /* Get the device using the phy device*/
27 ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
28 "gen_phy_user", &parent));
30 * Get the same phy port in 2 different ways and compare.
32 ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1_method1))
33 ut_assertok(generic_phy_get_by_index(parent, 0, &phy1_method2))
34 ut_asserteq(phy1_method1.id, phy1_method2.id);
37 * Get the second phy port. Check that the same phy provider (device)
38 * provides this 2nd phy port, but that the IDs are different
40 ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2))
41 ut_asserteq_ptr(phy1_method2.dev, phy2.dev);
42 ut_assert(phy1_method1.id != phy2.id);
45 * Get the third phy port. Check that the phy provider is different
47 ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3))
48 ut_assert(phy2.dev != phy3.dev);
50 /* Try to get a non-existing phy */
51 ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 3, &dev));
52 ut_assert(generic_phy_get_by_name(parent, "phy_not_existing",
57 DM_TEST(dm_test_phy_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
59 /* Test of the phy uclass using the sandbox phy driver operations */
60 static int dm_test_phy_ops(struct unit_test_state *uts)
65 struct udevice *parent;
67 ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
68 "gen_phy_user", &parent));
70 ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1));
71 ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2));
72 ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3));
74 /* test normal operations */
75 ut_assertok(generic_phy_init(&phy1));
76 ut_assertok(generic_phy_power_on(&phy1));
77 ut_assertok(generic_phy_power_off(&phy1));
80 * test operations after exit().
81 * The sandbox phy driver does not allow it.
83 ut_assertok(generic_phy_exit(&phy1));
84 ut_assert(generic_phy_power_on(&phy1) != 0);
85 ut_assert(generic_phy_power_off(&phy1) != 0);
88 * test normal operations again (after re-init)
90 ut_assertok(generic_phy_init(&phy1));
91 ut_assertok(generic_phy_power_on(&phy1));
92 ut_assertok(generic_phy_power_off(&phy1));
95 * test calling unimplemented feature.
96 * The call is expected to succeed
98 ut_assertok(generic_phy_reset(&phy1));
100 /* PHY2 has a known problem with power off */
101 ut_assertok(generic_phy_init(&phy2));
102 ut_assertok(generic_phy_power_on(&phy2));
103 ut_assert(generic_phy_power_off(&phy2) == -EIO);
105 /* PHY3 has a known problem with power off and power on*/
106 ut_assertok(generic_phy_init(&phy3));
107 ut_assert(generic_phy_power_off(&phy3) == -EIO);
108 ut_assert(generic_phy_power_off(&phy3) == -EIO);
112 DM_TEST(dm_test_phy_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);