Skip to content

Commit b0ba512

Browse files
Petri Gyntherdavem330
authored andcommitted
net: bcmgenet: enable driver to work without a device tree
Modify bcmgenet driver so that it can be used on Broadcom 7xxx MIPS-based STB platforms without a device tree. Signed-off-by: Petri Gynther <pgynther@google.com> Acked-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c3582a2 commit b0ba512

File tree

4 files changed

+143
-33
lines changed

4 files changed

+143
-33
lines changed

drivers/net/ethernet/broadcom/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ config BCM63XX_ENET
6262

6363
config BCMGENET
6464
tristate "Broadcom GENET internal MAC support"
65-
depends on OF
6665
select MII
6766
select PHYLIB
6867
select FIXED_PHY if BCMGENET=y

drivers/net/ethernet/broadcom/genet/bcmgenet.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <linux/ip.h>
4343
#include <linux/ipv6.h>
4444
#include <linux/phy.h>
45+
#include <linux/platform_data/bcmgenet.h>
4546

4647
#include <asm/unaligned.h>
4748

@@ -2586,8 +2587,9 @@ static const struct of_device_id bcmgenet_match[] = {
25862587

25872588
static int bcmgenet_probe(struct platform_device *pdev)
25882589
{
2590+
struct bcmgenet_platform_data *pd = pdev->dev.platform_data;
25892591
struct device_node *dn = pdev->dev.of_node;
2590-
const struct of_device_id *of_id;
2592+
const struct of_device_id *of_id = NULL;
25912593
struct bcmgenet_priv *priv;
25922594
struct net_device *dev;
25932595
const void *macaddr;
@@ -2601,9 +2603,11 @@ static int bcmgenet_probe(struct platform_device *pdev)
26012603
return -ENOMEM;
26022604
}
26032605

2604-
of_id = of_match_node(bcmgenet_match, dn);
2605-
if (!of_id)
2606-
return -EINVAL;
2606+
if (dn) {
2607+
of_id = of_match_node(bcmgenet_match, dn);
2608+
if (!of_id)
2609+
return -EINVAL;
2610+
}
26072611

26082612
priv = netdev_priv(dev);
26092613
priv->irq0 = platform_get_irq(pdev, 0);
@@ -2615,11 +2619,15 @@ static int bcmgenet_probe(struct platform_device *pdev)
26152619
goto err;
26162620
}
26172621

2618-
macaddr = of_get_mac_address(dn);
2619-
if (!macaddr) {
2620-
dev_err(&pdev->dev, "can't find MAC address\n");
2621-
err = -EINVAL;
2622-
goto err;
2622+
if (dn) {
2623+
macaddr = of_get_mac_address(dn);
2624+
if (!macaddr) {
2625+
dev_err(&pdev->dev, "can't find MAC address\n");
2626+
err = -EINVAL;
2627+
goto err;
2628+
}
2629+
} else {
2630+
macaddr = pd->mac_address;
26232631
}
26242632

26252633
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -2659,7 +2667,10 @@ static int bcmgenet_probe(struct platform_device *pdev)
26592667

26602668
priv->dev = dev;
26612669
priv->pdev = pdev;
2662-
priv->version = (enum bcmgenet_version)of_id->data;
2670+
if (of_id)
2671+
priv->version = (enum bcmgenet_version)of_id->data;
2672+
else
2673+
priv->version = pd->genet_version;
26632674

26642675
priv->clk = devm_clk_get(&priv->pdev->dev, "enet");
26652676
if (IS_ERR(priv->clk))

drivers/net/ethernet/broadcom/genet/bcmmii.c

Lines changed: 104 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/of.h>
2424
#include <linux/of_net.h>
2525
#include <linux/of_mdio.h>
26+
#include <linux/platform_data/bcmgenet.h>
2627

2728
#include "bcmgenet.h"
2829

@@ -312,22 +313,6 @@ static int bcmgenet_mii_probe(struct net_device *dev)
312313
u32 phy_flags;
313314
int ret;
314315

315-
if (priv->phydev) {
316-
pr_info("PHY already attached\n");
317-
return 0;
318-
}
319-
320-
/* In the case of a fixed PHY, the DT node associated
321-
* to the PHY is the Ethernet MAC DT node.
322-
*/
323-
if (!priv->phy_dn && of_phy_is_fixed_link(dn)) {
324-
ret = of_phy_register_fixed_link(dn);
325-
if (ret)
326-
return ret;
327-
328-
priv->phy_dn = of_node_get(dn);
329-
}
330-
331316
/* Communicate the integrated PHY revision */
332317
phy_flags = priv->gphy_rev;
333318

@@ -337,11 +322,39 @@ static int bcmgenet_mii_probe(struct net_device *dev)
337322
priv->old_duplex = -1;
338323
priv->old_pause = -1;
339324

340-
phydev = of_phy_connect(dev, priv->phy_dn, bcmgenet_mii_setup,
341-
phy_flags, priv->phy_interface);
342-
if (!phydev) {
343-
pr_err("could not attach to PHY\n");
344-
return -ENODEV;
325+
if (dn) {
326+
if (priv->phydev) {
327+
pr_info("PHY already attached\n");
328+
return 0;
329+
}
330+
331+
/* In the case of a fixed PHY, the DT node associated
332+
* to the PHY is the Ethernet MAC DT node.
333+
*/
334+
if (!priv->phy_dn && of_phy_is_fixed_link(dn)) {
335+
ret = of_phy_register_fixed_link(dn);
336+
if (ret)
337+
return ret;
338+
339+
priv->phy_dn = of_node_get(dn);
340+
}
341+
342+
phydev = of_phy_connect(dev, priv->phy_dn, bcmgenet_mii_setup,
343+
phy_flags, priv->phy_interface);
344+
if (!phydev) {
345+
pr_err("could not attach to PHY\n");
346+
return -ENODEV;
347+
}
348+
} else {
349+
phydev = priv->phydev;
350+
phydev->dev_flags = phy_flags;
351+
352+
ret = phy_connect_direct(dev, phydev, bcmgenet_mii_setup,
353+
priv->phy_interface);
354+
if (ret) {
355+
pr_err("could not attach to PHY\n");
356+
return -ENODEV;
357+
}
345358
}
346359

347360
priv->phydev = phydev;
@@ -438,6 +451,75 @@ static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv)
438451
return 0;
439452
}
440453

454+
static int bcmgenet_mii_pd_init(struct bcmgenet_priv *priv)
455+
{
456+
struct device *kdev = &priv->pdev->dev;
457+
struct bcmgenet_platform_data *pd = kdev->platform_data;
458+
struct mii_bus *mdio = priv->mii_bus;
459+
struct phy_device *phydev;
460+
int ret;
461+
462+
if (pd->phy_interface != PHY_INTERFACE_MODE_MOCA && pd->mdio_enabled) {
463+
/*
464+
* Internal or external PHY with MDIO access
465+
*/
466+
if (pd->phy_address >= 0 && pd->phy_address < PHY_MAX_ADDR)
467+
mdio->phy_mask = ~(1 << pd->phy_address);
468+
else
469+
mdio->phy_mask = 0;
470+
471+
ret = mdiobus_register(mdio);
472+
if (ret) {
473+
dev_err(kdev, "failed to register MDIO bus\n");
474+
return ret;
475+
}
476+
477+
if (pd->phy_address >= 0 && pd->phy_address < PHY_MAX_ADDR)
478+
phydev = mdio->phy_map[pd->phy_address];
479+
else
480+
phydev = phy_find_first(mdio);
481+
482+
if (!phydev) {
483+
dev_err(kdev, "failed to register PHY device\n");
484+
mdiobus_unregister(mdio);
485+
return -ENODEV;
486+
}
487+
} else {
488+
/*
489+
* MoCA port or no MDIO access.
490+
* Use fixed PHY to represent the link layer.
491+
*/
492+
struct fixed_phy_status fphy_status = {
493+
.link = 1,
494+
.speed = pd->phy_speed,
495+
.duplex = pd->phy_duplex,
496+
.pause = 0,
497+
.asym_pause = 0,
498+
};
499+
500+
phydev = fixed_phy_register(PHY_POLL, &fphy_status, NULL);
501+
if (!phydev || IS_ERR(phydev)) {
502+
dev_err(kdev, "failed to register fixed PHY device\n");
503+
return -ENODEV;
504+
}
505+
}
506+
507+
priv->phydev = phydev;
508+
priv->phy_interface = pd->phy_interface;
509+
510+
return 0;
511+
}
512+
513+
static int bcmgenet_mii_bus_init(struct bcmgenet_priv *priv)
514+
{
515+
struct device_node *dn = priv->pdev->dev.of_node;
516+
517+
if (dn)
518+
return bcmgenet_mii_of_init(priv);
519+
else
520+
return bcmgenet_mii_pd_init(priv);
521+
}
522+
441523
int bcmgenet_mii_init(struct net_device *dev)
442524
{
443525
struct bcmgenet_priv *priv = netdev_priv(dev);
@@ -447,7 +529,7 @@ int bcmgenet_mii_init(struct net_device *dev)
447529
if (ret)
448530
return ret;
449531

450-
ret = bcmgenet_mii_of_init(priv);
532+
ret = bcmgenet_mii_bus_init(priv);
451533
if (ret)
452534
goto out_free;
453535

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef __LINUX_PLATFORM_DATA_BCMGENET_H__
2+
#define __LINUX_PLATFORM_DATA_BCMGENET_H__
3+
4+
#include <linux/types.h>
5+
#include <linux/if_ether.h>
6+
#include <linux/phy.h>
7+
8+
struct bcmgenet_platform_data {
9+
bool mdio_enabled;
10+
phy_interface_t phy_interface;
11+
int phy_address;
12+
int phy_speed;
13+
int phy_duplex;
14+
u8 mac_address[ETH_ALEN];
15+
int genet_version;
16+
};
17+
18+
#endif

0 commit comments

Comments
 (0)