Alex Marginean | ec9594a | 2019-06-03 19:12:28 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2019 |
| 4 | * Alex Marginean, NXP |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Alex Marginean | ec9594a | 2019-06-03 19:12:28 +0300 | [diff] [blame] | 10 | #include <miiphy.h> |
Simon Glass | 0e1fad4 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 11 | #include <misc.h> |
| 12 | #include <dm/test.h> |
| 13 | #include <test/test.h> |
| 14 | #include <test/ut.h> |
Alex Marginean | ec9594a | 2019-06-03 19:12:28 +0300 | [diff] [blame] | 15 | |
| 16 | /* macros copied over from mdio_sandbox.c */ |
| 17 | #define SANDBOX_PHY_ADDR 5 |
Alex Marginean | b47edf8 | 2019-07-12 10:13:52 +0300 | [diff] [blame] | 18 | #define SANDBOX_PHY_REG_CNT 2 |
| 19 | |
| 20 | /* test using 1st register, 0 */ |
Alex Marginean | ec9594a | 2019-06-03 19:12:28 +0300 | [diff] [blame] | 21 | #define SANDBOX_PHY_REG 0 |
| 22 | |
| 23 | #define TEST_REG_VALUE 0xabcd |
| 24 | |
| 25 | static int dm_test_mdio(struct unit_test_state *uts) |
| 26 | { |
| 27 | struct uclass *uc; |
| 28 | struct udevice *dev; |
| 29 | struct mdio_ops *ops; |
| 30 | u16 reg; |
| 31 | |
| 32 | ut_assertok(uclass_get(UCLASS_MDIO, &uc)); |
| 33 | |
| 34 | ut_assertok(uclass_get_device_by_name(UCLASS_MDIO, "mdio-test", &dev)); |
| 35 | |
| 36 | ops = mdio_get_ops(dev); |
| 37 | ut_assertnonnull(ops); |
| 38 | ut_assertnonnull(ops->read); |
| 39 | ut_assertnonnull(ops->write); |
| 40 | |
Marek Behún | 1776a24 | 2022-04-07 00:32:59 +0200 | [diff] [blame] | 41 | ut_assertok(dm_mdio_write(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, |
| 42 | SANDBOX_PHY_REG, TEST_REG_VALUE)); |
| 43 | reg = dm_mdio_read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, |
| 44 | SANDBOX_PHY_REG); |
Alex Marginean | ec9594a | 2019-06-03 19:12:28 +0300 | [diff] [blame] | 45 | ut_asserteq(reg, TEST_REG_VALUE); |
| 46 | |
Marek Behún | 1776a24 | 2022-04-07 00:32:59 +0200 | [diff] [blame] | 47 | ut_assert(dm_mdio_read(dev, SANDBOX_PHY_ADDR + 1, MDIO_DEVAD_NONE, |
| 48 | SANDBOX_PHY_REG) != 0); |
Alex Marginean | ec9594a | 2019-06-03 19:12:28 +0300 | [diff] [blame] | 49 | |
Marek Behún | 1776a24 | 2022-04-07 00:32:59 +0200 | [diff] [blame] | 50 | ut_assertok(dm_mdio_reset(dev)); |
| 51 | reg = dm_mdio_read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, |
| 52 | SANDBOX_PHY_REG); |
Alex Marginean | ec9594a | 2019-06-03 19:12:28 +0300 | [diff] [blame] | 53 | ut_asserteq(reg, 0); |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 58 | DM_TEST(dm_test_mdio, UT_TESTF_SCAN_FDT); |