]> Git Repo - J-u-boot.git/blame - drivers/net/mdio_sandbox.c
Merge patch series "dwc3: gadget: properly fix cache operations"
[J-u-boot.git] / drivers / net / mdio_sandbox.c
CommitLineData
ec9594a5
AM
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2019
4 * Alex Marginean, NXP
5 */
6
7#include <dm.h>
8#include <errno.h>
9#include <miiphy.h>
10
11#define SANDBOX_PHY_ADDR 5
b47edf80 12#define SANDBOX_PHY_REG_CNT 2
ec9594a5
AM
13
14struct mdio_sandbox_priv {
15 int enabled;
b47edf80 16 u16 reg[SANDBOX_PHY_REG_CNT];
ec9594a5
AM
17};
18
19static int mdio_sandbox_read(struct udevice *dev, int addr, int devad, int reg)
20{
21 struct mdio_sandbox_priv *priv = dev_get_priv(dev);
22
23 if (!priv->enabled)
24 return -ENODEV;
25
26 if (addr != SANDBOX_PHY_ADDR)
27 return -ENODEV;
28 if (devad != MDIO_DEVAD_NONE)
29 return -ENODEV;
fd6d88f5 30 if (reg < 0 || reg >= SANDBOX_PHY_REG_CNT)
ec9594a5
AM
31 return -ENODEV;
32
b47edf80 33 return priv->reg[reg];
ec9594a5
AM
34}
35
36static int mdio_sandbox_write(struct udevice *dev, int addr, int devad, int reg,
37 u16 val)
38{
39 struct mdio_sandbox_priv *priv = dev_get_priv(dev);
40
41 if (!priv->enabled)
42 return -ENODEV;
43
44 if (addr != SANDBOX_PHY_ADDR)
45 return -ENODEV;
46 if (devad != MDIO_DEVAD_NONE)
47 return -ENODEV;
fd6d88f5 48 if (reg < 0 || reg >= SANDBOX_PHY_REG_CNT)
ec9594a5
AM
49 return -ENODEV;
50
b47edf80 51 priv->reg[reg] = val;
ec9594a5
AM
52
53 return 0;
54}
55
56static int mdio_sandbox_reset(struct udevice *dev)
57{
58 struct mdio_sandbox_priv *priv = dev_get_priv(dev);
b47edf80 59 int i;
ec9594a5 60
b47edf80
AM
61 for (i = 0; i < SANDBOX_PHY_REG_CNT; i++)
62 priv->reg[i] = 0;
ec9594a5
AM
63
64 return 0;
65}
66
67static const struct mdio_ops mdio_sandbox_ops = {
68 .read = mdio_sandbox_read,
69 .write = mdio_sandbox_write,
70 .reset = mdio_sandbox_reset,
71};
72
73static int mdio_sandbox_probe(struct udevice *dev)
74{
75 struct mdio_sandbox_priv *priv = dev_get_priv(dev);
76
77 priv->enabled = 1;
78
79 return 0;
80}
81
82static const struct udevice_id mdio_sandbox_ids[] = {
83 { .compatible = "sandbox,mdio" },
84 { }
85};
86
87U_BOOT_DRIVER(mdio_sandbox) = {
88 .name = "mdio_sandbox",
89 .id = UCLASS_MDIO,
90 .of_match = mdio_sandbox_ids,
91 .probe = mdio_sandbox_probe,
92 .ops = &mdio_sandbox_ops,
41575d8e 93 .priv_auto = sizeof(struct mdio_sandbox_priv),
ec9594a5 94};
This page took 0.148683 seconds and 4 git commands to generate.