Love Kumar | e9aa4e6 | 2023-12-19 17:50:51 +0530 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | # (C) Copyright 2023, Advanced Micro Devices, Inc. |
| 3 | |
| 4 | import pytest |
| 5 | import re |
| 6 | |
| 7 | """ |
| 8 | Note: This test relies on boardenv_* containing configuration values to define |
| 9 | the PHY device info including the device name, address, register address/value |
| 10 | and write data value. This test will be automatically skipped without this. |
| 11 | |
| 12 | For example: |
| 13 | |
| 14 | # Setup env__mdio_util_test to set the PHY address, device names, register |
| 15 | # address, register address value, and write data value to test mdio commands. |
| 16 | # Test will be skipped if env_mdio_util_test is not set |
| 17 | env__mdio_util_test = { |
| 18 | "eth0": {"phy_addr": 0xc, "device_name": "TI DP83867", "reg": 0, |
| 19 | "reg_val": 0x1000, "write_val": 0x100}, |
| 20 | "eth1": {"phy_addr": 0xa0, "device_name": "TI DP83867", "reg": 1, |
| 21 | "reg_val": 0x2000, "write_val": 0x100}, |
| 22 | } |
| 23 | """ |
| 24 | |
| 25 | def get_mdio_test_env(u_boot_console): |
| 26 | f = u_boot_console.config.env.get("env__mdio_util_test", None) |
| 27 | if not f or len(f) == 0: |
| 28 | pytest.skip("No PHY device to test!") |
| 29 | else: |
| 30 | return f |
| 31 | |
| 32 | @pytest.mark.buildconfigspec("cmd_mii") |
| 33 | @pytest.mark.buildconfigspec("phylib") |
| 34 | def test_mdio_list(u_boot_console): |
| 35 | f = get_mdio_test_env(u_boot_console) |
| 36 | output = u_boot_console.run_command("mdio list") |
| 37 | for dev, val in f.items(): |
| 38 | phy_addr = val.get("phy_addr") |
| 39 | dev_name = val.get("device_name") |
| 40 | |
| 41 | assert f"{phy_addr:x} -" in output |
| 42 | assert dev_name in output |
| 43 | |
| 44 | @pytest.mark.buildconfigspec("cmd_mii") |
| 45 | @pytest.mark.buildconfigspec("phylib") |
| 46 | def test_mdio_read(u_boot_console): |
| 47 | f = get_mdio_test_env(u_boot_console) |
| 48 | output = u_boot_console.run_command("mdio list") |
| 49 | for dev, val in f.items(): |
| 50 | phy_addr = hex(val.get("phy_addr")) |
| 51 | dev_name = val.get("device_name") |
| 52 | reg = hex(val.get("reg")) |
| 53 | reg_val = hex(val.get("reg_val")) |
| 54 | |
| 55 | output = u_boot_console.run_command(f"mdio read {phy_addr} {reg}") |
| 56 | assert f"PHY at address {int(phy_addr, 16):x}:" in output |
| 57 | assert f"{int(reg, 16):x} - {reg_val}" in output |
| 58 | |
| 59 | @pytest.mark.buildconfigspec("cmd_mii") |
| 60 | @pytest.mark.buildconfigspec("phylib") |
| 61 | def test_mdio_write(u_boot_console): |
| 62 | f = get_mdio_test_env(u_boot_console) |
| 63 | output = u_boot_console.run_command("mdio list") |
| 64 | for dev, val in f.items(): |
| 65 | phy_addr = hex(val.get("phy_addr")) |
| 66 | dev_name = val.get("device_name") |
| 67 | reg = hex(val.get("reg")) |
| 68 | reg_val = hex(val.get("reg_val")) |
| 69 | wr_val = hex(val.get("write_val")) |
| 70 | |
| 71 | u_boot_console.run_command(f"mdio write {phy_addr} {reg} {wr_val}") |
| 72 | output = u_boot_console.run_command(f"mdio read {phy_addr} {reg}") |
| 73 | assert f"PHY at address {int(phy_addr, 16):x}:" in output |
| 74 | assert f"{int(reg, 16):x} - {wr_val}" in output |
| 75 | |
| 76 | u_boot_console.run_command(f"mdio write {phy_addr} {reg} {reg_val}") |
| 77 | output = u_boot_console.run_command(f"mdio read {phy_addr} {reg}") |
| 78 | assert f"PHY at address {int(phy_addr, 16):x}:" in output |
| 79 | assert f"{int(reg, 16):x} - {reg_val}" in output |