Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/ |
| 4 | * Written by Jean-Jacques Hiblot <jjhiblot@ti.com> |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <generic-phy.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 11 | #include <dm/test.h> |
| 12 | #include <test/ut.h> |
| 13 | |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 14 | /* Base test of the phy uclass */ |
| 15 | static int dm_test_phy_base(struct unit_test_state *uts) |
| 16 | { |
| 17 | struct udevice *dev; |
| 18 | struct phy phy1_method1; |
| 19 | struct phy phy1_method2; |
| 20 | struct phy phy2; |
| 21 | struct phy phy3; |
| 22 | struct udevice *parent; |
| 23 | |
| 24 | /* Get the device using the phy device*/ |
| 25 | ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS, |
| 26 | "gen_phy_user", &parent)); |
| 27 | /* |
| 28 | * Get the same phy port in 2 different ways and compare. |
| 29 | */ |
| 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); |
| 33 | |
| 34 | /* |
| 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 |
| 37 | */ |
| 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); |
| 41 | |
| 42 | /* |
| 43 | * Get the third phy port. Check that the phy provider is different |
| 44 | */ |
| 45 | ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3)) |
| 46 | ut_assert(phy2.dev != phy3.dev); |
| 47 | |
| 48 | /* Try to get a non-existing phy */ |
| 49 | ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PHY, 3, &dev)); |
Simon Glass | d8c9bac | 2017-05-18 20:09:45 -0600 | [diff] [blame] | 50 | ut_asserteq(-ENODATA, generic_phy_get_by_name(parent, |
| 51 | "phy_not_existing", &phy1_method1)); |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | DM_TEST(dm_test_phy_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
| 56 | |
| 57 | /* Test of the phy uclass using the sandbox phy driver operations */ |
| 58 | static int dm_test_phy_ops(struct unit_test_state *uts) |
| 59 | { |
| 60 | struct phy phy1; |
| 61 | struct phy phy2; |
| 62 | struct phy phy3; |
| 63 | struct udevice *parent; |
| 64 | |
| 65 | ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS, |
| 66 | "gen_phy_user", &parent)); |
| 67 | |
| 68 | ut_assertok(generic_phy_get_by_name(parent, "phy1", &phy1)); |
Simon Glass | d8c9bac | 2017-05-18 20:09:45 -0600 | [diff] [blame] | 69 | ut_asserteq(0, phy1.id); |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 70 | ut_assertok(generic_phy_get_by_name(parent, "phy2", &phy2)); |
Simon Glass | d8c9bac | 2017-05-18 20:09:45 -0600 | [diff] [blame] | 71 | ut_asserteq(1, phy2.id); |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 72 | ut_assertok(generic_phy_get_by_name(parent, "phy3", &phy3)); |
Simon Glass | d8c9bac | 2017-05-18 20:09:45 -0600 | [diff] [blame] | 73 | ut_asserteq(0, phy3.id); |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 74 | |
| 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)); |
| 79 | |
| 80 | /* |
| 81 | * test operations after exit(). |
| 82 | * The sandbox phy driver does not allow it. |
| 83 | */ |
| 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); |
| 87 | |
| 88 | /* |
| 89 | * test normal operations again (after re-init) |
| 90 | */ |
| 91 | ut_assertok(generic_phy_init(&phy1)); |
| 92 | ut_assertok(generic_phy_power_on(&phy1)); |
| 93 | ut_assertok(generic_phy_power_off(&phy1)); |
| 94 | |
| 95 | /* |
| 96 | * test calling unimplemented feature. |
| 97 | * The call is expected to succeed |
| 98 | */ |
| 99 | ut_assertok(generic_phy_reset(&phy1)); |
| 100 | |
| 101 | /* PHY2 has a known problem with power off */ |
| 102 | ut_assertok(generic_phy_init(&phy2)); |
| 103 | ut_assertok(generic_phy_power_on(&phy2)); |
Simon Glass | d8c9bac | 2017-05-18 20:09:45 -0600 | [diff] [blame] | 104 | ut_asserteq(-EIO, generic_phy_power_off(&phy2)); |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 105 | |
Simon Glass | d8c9bac | 2017-05-18 20:09:45 -0600 | [diff] [blame] | 106 | /* PHY3 has a known problem with power off and power on */ |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 107 | ut_assertok(generic_phy_init(&phy3)); |
Simon Glass | d8c9bac | 2017-05-18 20:09:45 -0600 | [diff] [blame] | 108 | ut_asserteq(-EIO, generic_phy_power_off(&phy3)); |
| 109 | ut_asserteq(-EIO, generic_phy_power_off(&phy3)); |
Jean-Jacques Hiblot | 7e9db02 | 2017-04-24 11:51:28 +0200 | [diff] [blame] | 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | DM_TEST(dm_test_phy_ops, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
developer | 7109297 | 2020-05-02 11:35:12 +0200 | [diff] [blame] | 114 | |
| 115 | static int dm_test_phy_bulk(struct unit_test_state *uts) |
| 116 | { |
| 117 | struct phy_bulk phys; |
| 118 | struct udevice *parent; |
| 119 | |
| 120 | /* test normal operations */ |
| 121 | ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS, |
| 122 | "gen_phy_user1", &parent)); |
| 123 | |
| 124 | ut_assertok(generic_phy_get_bulk(parent, &phys)); |
| 125 | ut_asserteq(2, phys.count); |
| 126 | |
| 127 | ut_asserteq(0, generic_phy_init_bulk(&phys)); |
| 128 | ut_asserteq(0, generic_phy_power_on_bulk(&phys)); |
| 129 | ut_asserteq(0, generic_phy_power_off_bulk(&phys)); |
| 130 | ut_asserteq(0, generic_phy_exit_bulk(&phys)); |
| 131 | |
| 132 | /* has a known problem phy */ |
| 133 | ut_assertok(uclass_get_device_by_name(UCLASS_SIMPLE_BUS, |
| 134 | "gen_phy_user", &parent)); |
| 135 | |
| 136 | ut_assertok(generic_phy_get_bulk(parent, &phys)); |
| 137 | ut_asserteq(3, phys.count); |
| 138 | |
| 139 | ut_asserteq(0, generic_phy_init_bulk(&phys)); |
| 140 | ut_asserteq(-EIO, generic_phy_power_on_bulk(&phys)); |
| 141 | ut_asserteq(-EIO, generic_phy_power_off_bulk(&phys)); |
| 142 | ut_asserteq(0, generic_phy_exit_bulk(&phys)); |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | DM_TEST(dm_test_phy_bulk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |