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 /* Base test of the phy uclass */
15 static int dm_test_phy_base(struct unit_test_state *uts)
18 struct phy phy1_method1;
19 struct phy phy1_method2;
22 struct udevice *parent;
24 /* Get the device using the phy device*/
25 ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
26 "gen_phy_user", &parent));
28 * Get the same phy port in 2 different ways and compare.
30 ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1_method1))
31 ut_assertok(generic_phy_get_by_index(parent, 0, &phy1_method2))
32 ut_asserteq(phy1_method1.id, phy1_method2.id);
35 * Get the second phy port. Check that the same phy provider (device)
36 * provides this 2nd phy port, but that the IDs are different
38 ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2))
39 ut_asserteq_ptr(phy1_method2.dev, phy2.dev);
40 ut_assert(phy1_method1.id != phy2.id);
43 * Get the third phy port. Check that the phy provider is different
45 ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3))
46 ut_assert(phy2.dev != phy3.dev);
48 /* Try to get a non-existing phy */
49 ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 3, &dev));
50 ut_asserteq(-ENODATA, generic_phy_get_by_name(parent,
51 "phy_not_existing", &phy1_method1));
55 DM_TEST(dm_test_phy_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
57 /* Test of the phy uclass using the sandbox phy driver operations */
58 static int dm_test_phy_ops(struct unit_test_state *uts)
63 struct udevice *parent;
65 ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
66 "gen_phy_user", &parent));
68 ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1));
69 ut_asserteq(0, phy1.id);
70 ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2));
71 ut_asserteq(1, phy2.id);
72 ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3));
73 ut_asserteq(0, phy3.id);
75 /* test normal operations */
76 ut_assertok(generic_phy_init(&phy1));
77 ut_assertok(generic_phy_power_on(&phy1));
78 ut_assertok(generic_phy_power_off(&phy1));
81 * test operations after exit().
82 * The sandbox phy driver does not allow it.
84 ut_assertok(generic_phy_exit(&phy1));
85 ut_assert(generic_phy_power_on(&phy1) != 0);
86 ut_assert(generic_phy_power_off(&phy1) != 0);
89 * test normal operations again (after re-init)
91 ut_assertok(generic_phy_init(&phy1));
92 ut_assertok(generic_phy_power_on(&phy1));
93 ut_assertok(generic_phy_power_off(&phy1));
96 * test calling unimplemented feature.
97 * The call is expected to succeed
99 ut_assertok(generic_phy_reset(&phy1));
101 /* PHY2 has a known problem with power off */
102 ut_assertok(generic_phy_init(&phy2));
103 ut_assertok(generic_phy_power_on(&phy2));
104 ut_asserteq(-EIO, generic_phy_power_off(&phy2));
106 /* PHY3 has a known problem with power off and power on */
107 ut_assertok(generic_phy_init(&phy3));
108 ut_asserteq(-EIO, generic_phy_power_off(&phy3));
109 ut_asserteq(-EIO, generic_phy_power_off(&phy3));
113 DM_TEST(dm_test_phy_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);