Skip to content

Commit ba4ee3c

Browse files
ffainellidavem330
authored andcommitted
net: phy: bcm7xxx: request and manage GPHY clock
The internal Gigabit PHY on Broadcom STB chips has a digital clock which drives its MDIO interface among other things, the driver now requests and manage that clock during .probe() and .remove() accordingly. Because the PHY driver can be probed with the clocks turned off we need to apply the dummy BMSR workaround during the driver probe function to ensure subsequent MDIO read or write towards the PHY will succeed. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5f3666e commit ba4ee3c

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

‎drivers/net/phy/bcm7xxx.c‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "bcm-phy-lib.h"
1212
#include <linux/bitops.h>
1313
#include <linux/brcmphy.h>
14+
#include <linux/clk.h>
1415
#include <linux/mdio.h>
1516

1617
/* Broadcom BCM7xxx internal PHY registers */
@@ -39,6 +40,7 @@
3940

4041
struct bcm7xxx_phy_priv {
4142
u64 *stats;
43+
struct clk *clk;
4244
};
4345

4446
static int bcm7xxx_28nm_d0_afe_config_init(struct phy_device *phydev)
@@ -521,6 +523,7 @@ static void bcm7xxx_28nm_get_phy_stats(struct phy_device *phydev,
521523
static int bcm7xxx_28nm_probe(struct phy_device *phydev)
522524
{
523525
struct bcm7xxx_phy_priv *priv;
526+
int ret = 0;
524527

525528
priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
526529
if (!priv)
@@ -534,7 +537,30 @@ static int bcm7xxx_28nm_probe(struct phy_device *phydev)
534537
if (!priv->stats)
535538
return -ENOMEM;
536539

537-
return 0;
540+
priv->clk = devm_clk_get_optional(&phydev->mdio.dev, NULL);
541+
if (IS_ERR(priv->clk))
542+
return PTR_ERR(priv->clk);
543+
544+
ret = clk_prepare_enable(priv->clk);
545+
if (ret)
546+
return ret;
547+
548+
/* Dummy read to a register to workaround an issue upon reset where the
549+
* internal inverter may not allow the first MDIO transaction to pass
550+
* the MDIO management controller and make us return 0xffff for such
551+
* reads. This is needed to ensure that any subsequent reads to the
552+
* PHY will succeed.
553+
*/
554+
phy_read(phydev, MII_BMSR);
555+
556+
return ret;
557+
}
558+
559+
static void bcm7xxx_28nm_remove(struct phy_device *phydev)
560+
{
561+
struct bcm7xxx_phy_priv *priv = phydev->priv;
562+
563+
clk_disable_unprepare(priv->clk);
538564
}
539565

540566
#define BCM7XXX_28NM_GPHY(_oui, _name) \
@@ -552,6 +578,7 @@ static int bcm7xxx_28nm_probe(struct phy_device *phydev)
552578
.get_strings = bcm_phy_get_strings, \
553579
.get_stats = bcm7xxx_28nm_get_phy_stats, \
554580
.probe = bcm7xxx_28nm_probe, \
581+
.remove = bcm7xxx_28nm_remove, \
555582
}
556583

557584
#define BCM7XXX_28NM_EPHY(_oui, _name) \
@@ -567,6 +594,7 @@ static int bcm7xxx_28nm_probe(struct phy_device *phydev)
567594
.get_strings = bcm_phy_get_strings, \
568595
.get_stats = bcm7xxx_28nm_get_phy_stats, \
569596
.probe = bcm7xxx_28nm_probe, \
597+
.remove = bcm7xxx_28nm_remove, \
570598
}
571599

572600
#define BCM7XXX_40NM_EPHY(_oui, _name) \

0 commit comments

Comments
 (0)