blob: 866feb263818f3afa90df5d046d40db817d475af [file] [log] [blame]
Alex Marginean0649be52019-07-12 10:13:53 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2019
4 * Alex Marginean, NXP
5 */
6
Alex Marginean0649be52019-07-12 10:13:53 +03007#include <dm.h>
Simon Glass75c4d412020-07-19 10:15:37 -06008#include <miiphy.h>
Alex Marginean0649be52019-07-12 10:13:53 +03009#include <misc.h>
Simon Glass75c4d412020-07-19 10:15:37 -060010#include <dm/test.h>
11#include <test/test.h>
Alex Marginean0649be52019-07-12 10:13:53 +030012#include <test/ut.h>
Alex Marginean0649be52019-07-12 10:13:53 +030013
14/* macros copied over from mdio_sandbox.c */
15#define SANDBOX_PHY_ADDR 5
16#define SANDBOX_PHY_REG_CNT 2
17
18#define TEST_REG_VALUE 0xabcd
19
20static int dm_test_mdio_mux(struct unit_test_state *uts)
21{
22 struct uclass *uc;
23 struct udevice *mux;
24 struct udevice *mdio_ch0, *mdio_ch1, *mdio;
25 struct mdio_ops *ops, *ops_parent;
26 struct mdio_mux_ops *mmops;
27 u16 reg;
28
29 ut_assertok(uclass_get(UCLASS_MDIO_MUX, &uc));
30
31 ut_assertok(uclass_get_device_by_name(UCLASS_MDIO_MUX, "mdio-mux-test",
32 &mux));
33
34 ut_assertok(uclass_get_device_by_name(UCLASS_MDIO, "mdio-ch-test@0",
35 &mdio_ch0));
36 ut_assertok(uclass_get_device_by_name(UCLASS_MDIO, "mdio-ch-test@1",
37 &mdio_ch1));
38
39 ut_assertok(uclass_get_device_by_name(UCLASS_MDIO, "mdio-test", &mdio));
40
41 ops = mdio_get_ops(mdio_ch0);
42 ut_assertnonnull(ops);
43 ut_assertnonnull(ops->read);
44 ut_assertnonnull(ops->write);
45
46 mmops = mdio_mux_get_ops(mux);
47 ut_assertnonnull(mmops);
48 ut_assertnonnull(mmops->select);
49
50 ops_parent = mdio_get_ops(mdio);
51 ut_assertnonnull(ops);
52 ut_assertnonnull(ops->read);
53
54 /*
55 * mux driver sets last register on the emulated PHY whenever a group
56 * is selected to the selection #. Just reading that register from
57 * either of the child buses should return the id of the child bus
58 */
Marek Behúne4dedf22022-04-07 00:32:59 +020059 reg = dm_mdio_read(mdio_ch0, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
60 SANDBOX_PHY_REG_CNT - 1);
Alex Marginean0649be52019-07-12 10:13:53 +030061 ut_asserteq(reg, 0);
62
Marek Behúne4dedf22022-04-07 00:32:59 +020063 reg = dm_mdio_read(mdio_ch1, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
64 SANDBOX_PHY_REG_CNT - 1);
Alex Marginean0649be52019-07-12 10:13:53 +030065 ut_asserteq(reg, 1);
66
67 mmops->select(mux, MDIO_MUX_SELECT_NONE, 5);
Marek Behúne4dedf22022-04-07 00:32:59 +020068 reg = dm_mdio_read(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
69 SANDBOX_PHY_REG_CNT - 1);
Alex Marginean0649be52019-07-12 10:13:53 +030070 ut_asserteq(reg, 5);
71
72 mmops->deselect(mux, 5);
Marek Behúne4dedf22022-04-07 00:32:59 +020073 reg = dm_mdio_read(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
74 SANDBOX_PHY_REG_CNT - 1);
Alex Marginean0649be52019-07-12 10:13:53 +030075 ut_asserteq(reg, (u16)MDIO_MUX_SELECT_NONE);
76
77 return 0;
78}
Simon Glass1a92f832024-08-22 07:57:48 -060079DM_TEST(dm_test_mdio_mux, UTF_SCAN_FDT);