blob: ecbd47bf12fd520ec1694316bd84b490deb00d27 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +02002/*
3 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
4 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +02005 */
6
7#include <common.h>
8#include <dm.h>
9#include <generic-phy.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020011#include <dm/test.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060012#include <test/test.h>
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020013#include <test/ut.h>
14
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020015/* Base test of the phy uclass */
16static int dm_test_phy_base(struct unit_test_state *uts)
17{
18 struct udevice *dev;
19 struct phy phy1_method1;
20 struct phy phy1_method2;
21 struct phy phy2;
22 struct phy phy3;
23 struct udevice *parent;
24
25 /* Get the device using the phy device*/
26 ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
27 "gen_phy_user", &parent));
28 /*
29 * Get the same phy port in 2 different ways and compare.
30 */
31 ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1_method1))
32 ut_assertok(generic_phy_get_by_index(parent, 0, &phy1_method2))
33 ut_asserteq(phy1_method1.id, phy1_method2.id);
34
35 /*
36 * Get the second phy port. Check that the same phy provider (device)
37 * provides this 2nd phy port, but that the IDs are different
38 */
39 ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2))
40 ut_asserteq_ptr(phy1_method2.dev, phy2.dev);
41 ut_assert(phy1_method1.id != phy2.id);
42
43 /*
44 * Get the third phy port. Check that the phy provider is different
45 */
46 ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3))
47 ut_assert(phy2.dev != phy3.dev);
48
49 /* Try to get a non-existing phy */
Patrice Chotard1f0d5882020-07-28 09:13:33 +020050 ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 4, &dev));
Simon Glassac206a02017-05-18 20:09:45 -060051 ut_asserteq(-ENODATA, generic_phy_get_by_name(parent,
52 "phy_not_existing", &phy1_method1));
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020053
54 return 0;
55}
Simon Glasse180c2b2020-07-28 19:41:12 -060056DM_TEST(dm_test_phy_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020057
58/* Test of the phy uclass using the sandbox phy driver operations */
59static int dm_test_phy_ops(struct unit_test_state *uts)
60{
61 struct phy phy1;
62 struct phy phy2;
63 struct phy phy3;
64 struct udevice *parent;
65
66 ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
67 "gen_phy_user", &parent));
68
69 ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1));
Simon Glassac206a02017-05-18 20:09:45 -060070 ut_asserteq(0, phy1.id);
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020071 ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2));
Simon Glassac206a02017-05-18 20:09:45 -060072 ut_asserteq(1, phy2.id);
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020073 ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3));
Simon Glassac206a02017-05-18 20:09:45 -060074 ut_asserteq(0, phy3.id);
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020075
76 /* test normal operations */
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 /*
82 * test operations after exit().
83 * The sandbox phy driver does not allow it.
84 */
85 ut_assertok(generic_phy_exit(&phy1));
86 ut_assert(generic_phy_power_on(&phy1) != 0);
87 ut_assert(generic_phy_power_off(&phy1) != 0);
88
89 /*
90 * test normal operations again (after re-init)
91 */
92 ut_assertok(generic_phy_init(&phy1));
93 ut_assertok(generic_phy_power_on(&phy1));
94 ut_assertok(generic_phy_power_off(&phy1));
95
96 /*
97 * test calling unimplemented feature.
98 * The call is expected to succeed
99 */
100 ut_assertok(generic_phy_reset(&phy1));
101
102 /* PHY2 has a known problem with power off */
103 ut_assertok(generic_phy_init(&phy2));
104 ut_assertok(generic_phy_power_on(&phy2));
Simon Glassac206a02017-05-18 20:09:45 -0600105 ut_asserteq(-EIO, generic_phy_power_off(&phy2));
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +0200106
Simon Glassac206a02017-05-18 20:09:45 -0600107 /* PHY3 has a known problem with power off and power on */
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +0200108 ut_assertok(generic_phy_init(&phy3));
Simon Glassac206a02017-05-18 20:09:45 -0600109 ut_asserteq(-EIO, generic_phy_power_off(&phy3));
110 ut_asserteq(-EIO, generic_phy_power_off(&phy3));
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +0200111
112 return 0;
113}
Simon Glasse180c2b2020-07-28 19:41:12 -0600114DM_TEST(dm_test_phy_ops, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Chunfeng Yun00c82ac2020-05-02 11:35:12 +0200115
116static int dm_test_phy_bulk(struct unit_test_state *uts)
117{
118 struct phy_bulk phys;
119 struct udevice *parent;
120
121 /* test normal operations */
122 ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
123 "gen_phy_user1", &parent));
124
125 ut_assertok(generic_phy_get_bulk(parent, &phys));
126 ut_asserteq(2, phys.count);
127
128 ut_asserteq(0, generic_phy_init_bulk(&phys));
129 ut_asserteq(0, generic_phy_power_on_bulk(&phys));
130 ut_asserteq(0, generic_phy_power_off_bulk(&phys));
131 ut_asserteq(0, generic_phy_exit_bulk(&phys));
132
133 /* has a known problem phy */
134 ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
135 "gen_phy_user", &parent));
136
137 ut_assertok(generic_phy_get_bulk(parent, &phys));
138 ut_asserteq(3, phys.count);
139
140 ut_asserteq(0, generic_phy_init_bulk(&phys));
141 ut_asserteq(-EIO, generic_phy_power_on_bulk(&phys));
142 ut_asserteq(-EIO, generic_phy_power_off_bulk(&phys));
143 ut_asserteq(0, generic_phy_exit_bulk(&phys));
144
145 return 0;
146}
Simon Glasse180c2b2020-07-28 19:41:12 -0600147DM_TEST(dm_test_phy_bulk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);