blob: 35a4a0cb7f9d606371350299a6e77b87ec813526 [file] [log] [blame]
Marek Vasutb1d33702025-03-08 21:49:42 +01001.. SPDX-License-Identifier: GPL-2.0-or-later
2.. Luigi 'Comio' Mantellini <luigi.mantellini@idf-hit.com>, Industrie Dial Face S.p.A., 2009
3
4Bit-banged MII bus support
5==========================
6
7The miiphybb ( Bit-banged MII bus driver ) supports an arbitrary number of
8MII buses. This feature is useful when a driver uses different MII buses for
9different PHYs and all (or a part) of these buses are implemented via
10bit-banging mode.
11
12The driver requires that the following macro is defined in the board
13configuration file:
14
15* CONFIG_BITBANGMII - Enable the miiphybb driver
16
17The driver code needs to allocate a regular MDIO device using mdio_alloc()
18and assign .read and .write accessors which wrap bb_miiphy_read() and
19bb_miiphy_write() functions respectively. The bb_miiphy_read() and
20bb_miiphy_write() functions take a pointer to a callback structure,
21struct bb_miiphy_bus_ops. The struct bb_miiphy_bus_ops has the following
22fields/callbacks (see miiphy.h for details):
23
24.. code-block:: c
25
26 int (*mdio_active)() // Activate the MDIO pin as output
27 int (*mdio_tristate)() // Activate the MDIO pin as input/tristate pin
28 int (*set_mdio)() // Write the MDIO pin
29 int (*get_mdio)() // Read the MDIO pin
30 int (*set_mdc)() // Write the MDC pin
31 int (*delay)() // Delay function
32
33The driver code will look like:
34
35.. code-block:: c
36
37 static const struct bb_miiphy_bus_ops ravb_bb_miiphy_bus_ops = {
38 .mdio_active = ravb_bb_mdio_active,
39 .mdio_tristate = ravb_bb_mdio_tristate,
40 .set_mdio = ravb_bb_set_mdio,
41 .get_mdio = ravb_bb_get_mdio,
42 .set_mdc = ravb_bb_set_mdc,
43 .delay = ravb_bb_delay,
44 };
45
46 static int ravb_bb_miiphy_read(struct mii_dev *miidev, int addr,
47 int devad, int reg)
48 {
49 return bb_miiphy_read(miidev, &ravb_bb_miiphy_bus_ops,
50 addr, devad, reg);
51 }
52
53 static int ravb_bb_miiphy_write(struct mii_dev *miidev, int addr,
54 int devad, int reg, u16 value)
55 {
56 return bb_miiphy_write(miidev, &ravb_bb_miiphy_bus_ops,
57 addr, devad, reg, value);
58 }
59
60 static int ravb_probe(struct udevice *dev)
61 {
62 struct mii_dev *mdiodev;
63 ...
64 mdiodev = mdio_alloc();
65 if (!mdiodev)
66 return -ENOMEM;
67
68 mdiodev->read = ravb_bb_miiphy_read;
69 mdiodev->write = ravb_bb_miiphy_write;
70 mdiodev->priv = eth;
71 snprintf(mdiodev->name, sizeof(mdiodev->name), dev->name);
72
73 ret = mdio_register(mdiodev);
74 ...
75 }