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> |
| 9 | #include <dm/test.h> |
| 10 | #include <misc.h> |
| 11 | #include <test/ut.h> |
| 12 | #include <miiphy.h> |
| 13 | |
| 14 | /* macros copied over from mdio_sandbox.c */ |
| 15 | #define SANDBOX_PHY_ADDR 5 |
Alex Marginean | b47edf8 | 2019-07-12 10:13:52 +0300 | [diff] [blame^] | 16 | #define SANDBOX_PHY_REG_CNT 2 |
| 17 | |
| 18 | /* test using 1st register, 0 */ |
Alex Marginean | ec9594a | 2019-06-03 19:12:28 +0300 | [diff] [blame] | 19 | #define SANDBOX_PHY_REG 0 |
| 20 | |
| 21 | #define TEST_REG_VALUE 0xabcd |
| 22 | |
| 23 | static int dm_test_mdio(struct unit_test_state *uts) |
| 24 | { |
| 25 | struct uclass *uc; |
| 26 | struct udevice *dev; |
| 27 | struct mdio_ops *ops; |
| 28 | u16 reg; |
| 29 | |
| 30 | ut_assertok(uclass_get(UCLASS_MDIO, &uc)); |
| 31 | |
| 32 | ut_assertok(uclass_get_device_by_name(UCLASS_MDIO, "mdio-test", &dev)); |
| 33 | |
| 34 | ops = mdio_get_ops(dev); |
| 35 | ut_assertnonnull(ops); |
| 36 | ut_assertnonnull(ops->read); |
| 37 | ut_assertnonnull(ops->write); |
| 38 | |
| 39 | ut_assertok(ops->write(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, |
| 40 | SANDBOX_PHY_REG, TEST_REG_VALUE)); |
| 41 | reg = ops->read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, |
| 42 | SANDBOX_PHY_REG); |
| 43 | ut_asserteq(reg, TEST_REG_VALUE); |
| 44 | |
| 45 | ut_assert(ops->read(dev, SANDBOX_PHY_ADDR + 1, MDIO_DEVAD_NONE, |
| 46 | SANDBOX_PHY_REG) != 0); |
| 47 | |
| 48 | ut_assertok(ops->reset(dev)); |
| 49 | reg = ops->read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, |
| 50 | SANDBOX_PHY_REG); |
| 51 | ut_asserteq(reg, 0); |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | DM_TEST(dm_test_mdio, DM_TESTF_SCAN_FDT); |