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