blob: 64347e1275aae0dec0579402799cffb4fa47c88e [file] [log] [blame]
Alex Margineanec9594a2019-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>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Alex Margineanec9594a2019-06-03 19:12:28 +030010#include <miiphy.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060011#include <misc.h>
12#include <dm/test.h>
13#include <test/test.h>
14#include <test/ut.h>
Alex Margineanec9594a2019-06-03 19:12:28 +030015
16/* macros copied over from mdio_sandbox.c */
17#define SANDBOX_PHY_ADDR 5
Alex Margineanb47edf82019-07-12 10:13:52 +030018#define SANDBOX_PHY_REG_CNT 2
19
20/* test using 1st register, 0 */
Alex Margineanec9594a2019-06-03 19:12:28 +030021#define SANDBOX_PHY_REG 0
22
23#define TEST_REG_VALUE 0xabcd
24
25static 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
41 ut_assertok(ops->write(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
42 SANDBOX_PHY_REG, TEST_REG_VALUE));
43 reg = ops->read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
44 SANDBOX_PHY_REG);
45 ut_asserteq(reg, TEST_REG_VALUE);
46
47 ut_assert(ops->read(dev, SANDBOX_PHY_ADDR + 1, MDIO_DEVAD_NONE,
48 SANDBOX_PHY_REG) != 0);
49
50 ut_assertok(ops->reset(dev));
51 reg = ops->read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
52 SANDBOX_PHY_REG);
53 ut_asserteq(reg, 0);
54
55 return 0;
56}
57
Simon Glasse180c2b2020-07-28 19:41:12 -060058DM_TEST(dm_test_mdio, UT_TESTF_SCAN_FDT);