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