blob: 5b66255f7d45b4f82cb2c74bb2ebf88fdb10e851 [file] [log] [blame]
Alex Marginean0daa53a2019-06-03 19:12:28 +03001// 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
16#define SANDBOX_PHY_REG 0
17
18#define TEST_REG_VALUE 0xabcd
19
20static int dm_test_mdio(struct unit_test_state *uts)
21{
22 struct uclass *uc;
23 struct udevice *dev;
24 struct mdio_ops *ops;
25 u16 reg;
26
27 ut_assertok(uclass_get(UCLASS_MDIO, &uc));
28
29 ut_assertok(uclass_get_device_by_name(UCLASS_MDIO, "mdio-test", &dev));
30
31 ops = mdio_get_ops(dev);
32 ut_assertnonnull(ops);
33 ut_assertnonnull(ops->read);
34 ut_assertnonnull(ops->write);
35
36 ut_assertok(ops->write(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
37 SANDBOX_PHY_REG, TEST_REG_VALUE));
38 reg = ops->read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
39 SANDBOX_PHY_REG);
40 ut_asserteq(reg, TEST_REG_VALUE);
41
42 ut_assert(ops->read(dev, SANDBOX_PHY_ADDR + 1, MDIO_DEVAD_NONE,
43 SANDBOX_PHY_REG) != 0);
44
45 ut_assertok(ops->reset(dev));
46 reg = ops->read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
47 SANDBOX_PHY_REG);
48 ut_asserteq(reg, 0);
49
50 return 0;
51}
52
53DM_TEST(dm_test_mdio, DM_TESTF_SCAN_FDT);