blob: 65b33fe68d1e5101a30187f354bd2643d8dbcb2e [file] [log] [blame]
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +02001/*
2 * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
3 * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <generic-phy.h>
11#include <dm/test.h>
12#include <test/ut.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16/* Base test of the phy uclass */
17static int dm_test_phy_base(struct unit_test_state *uts)
18{
19 struct udevice *dev;
20 struct phy phy1_method1;
21 struct phy phy1_method2;
22 struct phy phy2;
23 struct phy phy3;
24 struct udevice *parent;
25
26 /* Get the device using the phy device*/
27 ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
28 "gen_phy_user", &parent));
29 /*
30 * Get the same phy port in 2 different ways and compare.
31 */
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);
35
36 /*
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
39 */
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);
43
44 /*
45 * Get the third phy port. Check that the phy provider is different
46 */
47 ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3))
48 ut_assert(phy2.dev != phy3.dev);
49
50 /* Try to get a non-existing phy */
51 ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 3, &dev));
Simon Glassac206a02017-05-18 20:09:45 -060052 ut_asserteq(-ENODATA, generic_phy_get_by_name(parent,
53 "phy_not_existing", &phy1_method1));
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020054
55 return 0;
56}
57DM_TEST(dm_test_phy_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
58
59/* Test of the phy uclass using the sandbox phy driver operations */
60static int dm_test_phy_ops(struct unit_test_state *uts)
61{
62 struct phy phy1;
63 struct phy phy2;
64 struct phy phy3;
65 struct udevice *parent;
66
67 ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS,
68 "gen_phy_user", &parent));
69
70 ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1));
Simon Glassac206a02017-05-18 20:09:45 -060071 ut_asserteq(0, phy1.id);
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020072 ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2));
Simon Glassac206a02017-05-18 20:09:45 -060073 ut_asserteq(1, phy2.id);
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020074 ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3));
Simon Glassac206a02017-05-18 20:09:45 -060075 ut_asserteq(0, phy3.id);
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +020076
77 /* test normal operations */
78 ut_assertok(generic_phy_init(&phy1));
79 ut_assertok(generic_phy_power_on(&phy1));
80 ut_assertok(generic_phy_power_off(&phy1));
81
82 /*
83 * test operations after exit().
84 * The sandbox phy driver does not allow it.
85 */
86 ut_assertok(generic_phy_exit(&phy1));
87 ut_assert(generic_phy_power_on(&phy1) != 0);
88 ut_assert(generic_phy_power_off(&phy1) != 0);
89
90 /*
91 * test normal operations again (after re-init)
92 */
93 ut_assertok(generic_phy_init(&phy1));
94 ut_assertok(generic_phy_power_on(&phy1));
95 ut_assertok(generic_phy_power_off(&phy1));
96
97 /*
98 * test calling unimplemented feature.
99 * The call is expected to succeed
100 */
101 ut_assertok(generic_phy_reset(&phy1));
102
103 /* PHY2 has a known problem with power off */
104 ut_assertok(generic_phy_init(&phy2));
105 ut_assertok(generic_phy_power_on(&phy2));
Simon Glassac206a02017-05-18 20:09:45 -0600106 ut_asserteq(-EIO, generic_phy_power_off(&phy2));
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +0200107
Simon Glassac206a02017-05-18 20:09:45 -0600108 /* PHY3 has a known problem with power off and power on */
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +0200109 ut_assertok(generic_phy_init(&phy3));
Simon Glassac206a02017-05-18 20:09:45 -0600110 ut_asserteq(-EIO, generic_phy_power_off(&phy3));
111 ut_asserteq(-EIO, generic_phy_power_off(&phy3));
Jean-Jacques Hiblot86322f52017-04-24 11:51:28 +0200112
113 return 0;
114}
115DM_TEST(dm_test_phy_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);