Skip to content

Commit e34d656

Browse files
reid-pdavem330
authored andcommitted
stmmac: create of compatible mdio bus for stmmac driver
The DSA driver needs to be passed a reference to an mdio bus. Typically the mac is configured to use a fixed link but the mdio bus still needs to be registered so that it con configure the switch. This patch follows the same process as the altera tse ethernet driver for creation of the mdio bus. Acked-by: Rob Herring <[email protected]> Signed-off-by: Phil Reid <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 93d085d commit e34d656

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

Documentation/devicetree/bindings/net/stmmac.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Optional properties:
4747
- snps,burst_len: The AXI burst lenth value of the AXI BUS MODE register.
4848
- tx-fifo-depth: See ethernet.txt file in the same directory
4949
- rx-fifo-depth: See ethernet.txt file in the same directory
50+
- mdio: with compatible = "snps,dwmac-mdio", create and register mdio bus.
5051

5152
Examples:
5253

@@ -65,4 +66,11 @@ Examples:
6566
tx-fifo-depth = <16384>;
6667
clocks = <&clock>;
6768
clock-names = "stmmaceth";
69+
mdio0 {
70+
#address-cells = <1>;
71+
#size-cells = <0>;
72+
compatible = "snps,dwmac-mdio";
73+
phy1: ethernet-phy@0 {
74+
};
75+
};
6876
};

drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <linux/slab.h>
3030
#include <linux/of.h>
3131
#include <linux/of_gpio.h>
32-
32+
#include <linux/of_mdio.h>
3333
#include <asm/io.h>
3434

3535
#include "stmmac.h"
@@ -200,10 +200,29 @@ int stmmac_mdio_register(struct net_device *ndev)
200200
struct stmmac_priv *priv = netdev_priv(ndev);
201201
struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data;
202202
int addr, found;
203+
struct device_node *mdio_node = NULL;
204+
struct device_node *child_node = NULL;
203205

204206
if (!mdio_bus_data)
205207
return 0;
206208

209+
if (IS_ENABLED(CONFIG_OF)) {
210+
for_each_child_of_node(priv->device->of_node, child_node) {
211+
if (of_device_is_compatible(child_node,
212+
"snps,dwmac-mdio")) {
213+
mdio_node = child_node;
214+
break;
215+
}
216+
}
217+
218+
if (mdio_node) {
219+
netdev_dbg(ndev, "FOUND MDIO subnode\n");
220+
} else {
221+
netdev_err(ndev, "NO MDIO subnode\n");
222+
return 0;
223+
}
224+
}
225+
207226
new_bus = mdiobus_alloc();
208227
if (new_bus == NULL)
209228
return -ENOMEM;
@@ -231,7 +250,8 @@ int stmmac_mdio_register(struct net_device *ndev)
231250
new_bus->irq = irqlist;
232251
new_bus->phy_mask = mdio_bus_data->phy_mask;
233252
new_bus->parent = priv->device;
234-
err = mdiobus_register(new_bus);
253+
254+
err = of_mdiobus_register(new_bus, mdio_node);
235255
if (err != 0) {
236256
pr_err("%s: Cannot register as MDIO bus\n", new_bus->name);
237257
goto bus_register_fail;
@@ -284,7 +304,7 @@ int stmmac_mdio_register(struct net_device *ndev)
284304
}
285305
}
286306

287-
if (!found) {
307+
if (!found && !mdio_node) {
288308
pr_warn("%s: No PHY found\n", ndev->name);
289309
mdiobus_unregister(new_bus);
290310
mdiobus_free(new_bus);

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
146146
if (of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr) == 0)
147147
dev_warn(&pdev->dev, "snps,phy-addr property is deprecated\n");
148148

149-
if (plat->phy_node || plat->phy_bus_name)
149+
if ((plat->phy_node && !of_phy_is_fixed_link(np)) || plat->phy_bus_name)
150150
plat->mdio_bus_data = NULL;
151151
else
152152
plat->mdio_bus_data =

0 commit comments

Comments
 (0)