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