2019-06-03 16:12:28 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* (C) Copyright 2019
|
|
|
|
* Alex Marginean, NXP
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-07-19 16:15:37 +00:00
|
|
|
#include <miiphy.h>
|
2019-06-03 16:12:28 +00:00
|
|
|
#include <misc.h>
|
2020-07-19 16:15:37 +00:00
|
|
|
#include <dm/test.h>
|
|
|
|
#include <test/test.h>
|
2019-06-03 16:12:28 +00:00
|
|
|
#include <test/ut.h>
|
|
|
|
|
|
|
|
/* macros copied over from mdio_sandbox.c */
|
|
|
|
#define SANDBOX_PHY_ADDR 5
|
2019-07-12 07:13:52 +00:00
|
|
|
#define SANDBOX_PHY_REG_CNT 2
|
|
|
|
|
|
|
|
/* test using 1st register, 0 */
|
2019-06-03 16:12:28 +00:00
|
|
|
#define SANDBOX_PHY_REG 0
|
|
|
|
|
|
|
|
#define TEST_REG_VALUE 0xabcd
|
|
|
|
|
|
|
|
static int dm_test_mdio(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct uclass *uc;
|
|
|
|
struct udevice *dev;
|
|
|
|
struct mdio_ops *ops;
|
|
|
|
u16 reg;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get(UCLASS_MDIO, &uc));
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_MDIO, "mdio-test", &dev));
|
|
|
|
|
|
|
|
ops = mdio_get_ops(dev);
|
|
|
|
ut_assertnonnull(ops);
|
|
|
|
ut_assertnonnull(ops->read);
|
|
|
|
ut_assertnonnull(ops->write);
|
|
|
|
|
2022-04-06 22:32:59 +00:00
|
|
|
ut_assertok(dm_mdio_write(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
|
|
|
|
SANDBOX_PHY_REG, TEST_REG_VALUE));
|
|
|
|
reg = dm_mdio_read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
|
|
|
|
SANDBOX_PHY_REG);
|
2019-06-03 16:12:28 +00:00
|
|
|
ut_asserteq(reg, TEST_REG_VALUE);
|
|
|
|
|
2022-04-06 22:32:59 +00:00
|
|
|
ut_assert(dm_mdio_read(dev, SANDBOX_PHY_ADDR + 1, MDIO_DEVAD_NONE,
|
|
|
|
SANDBOX_PHY_REG) != 0);
|
2019-06-03 16:12:28 +00:00
|
|
|
|
2022-04-06 22:32:59 +00:00
|
|
|
ut_assertok(dm_mdio_reset(dev));
|
|
|
|
reg = dm_mdio_read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
|
|
|
|
SANDBOX_PHY_REG);
|
2019-06-03 16:12:28 +00:00
|
|
|
ut_asserteq(reg, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_mdio, UT_TESTF_SCAN_FDT);
|