linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: phy: bcm7xxx: request and manage GPHY clock
@ 2020-09-17  2:04 Florian Fainelli
  2020-09-17 13:11 ` Andrew Lunn
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Florian Fainelli @ 2020-09-17  2:04 UTC (permalink / raw)
  To: netdev
  Cc: opendmb, Florian Fainelli, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Jakub Kicinski,
	open list:BROADCOM ETHERNET PHY DRIVERS, open list

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>
---
Changes in v2:

- localize the changes exclusively within the PHY driver and do not
  involve the MDIO driver at all. Using the ethernet-phyidAAAA.BBBB
  compatible string we can get straight to the desired driver without
  requiring clocks to be assumed on.

 drivers/net/phy/bcm7xxx.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/bcm7xxx.c b/drivers/net/phy/bcm7xxx.c
index 692048d86ab1..744c24491d63 100644
--- a/drivers/net/phy/bcm7xxx.c
+++ b/drivers/net/phy/bcm7xxx.c
@@ -11,6 +11,7 @@
 #include "bcm-phy-lib.h"
 #include <linux/bitops.h>
 #include <linux/brcmphy.h>
+#include <linux/clk.h>
 #include <linux/mdio.h>
 
 /* Broadcom BCM7xxx internal PHY registers */
@@ -39,6 +40,7 @@
 
 struct bcm7xxx_phy_priv {
 	u64	*stats;
+	struct clk *clk;
 };
 
 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,
 static int bcm7xxx_28nm_probe(struct phy_device *phydev)
 {
 	struct bcm7xxx_phy_priv *priv;
+	int ret = 0;
 
 	priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -534,7 +537,30 @@ static int bcm7xxx_28nm_probe(struct phy_device *phydev)
 	if (!priv->stats)
 		return -ENOMEM;
 
-	return 0;
+	priv->clk = devm_clk_get_optional(&phydev->mdio.dev, NULL);
+	if (IS_ERR(priv->clk))
+		return PTR_ERR(priv->clk);
+
+	ret = clk_prepare_enable(priv->clk);
+	if (ret)
+		return ret;
+
+	/* Dummy read to a register to workaround an issue upon reset where the
+	 * internal inverter may not allow the first MDIO transaction to pass
+	 * the MDIO management controller and make us return 0xffff for such
+	 * reads. This is needed to ensure that any subsequent reads to the
+	 * PHY will succeed.
+	 */
+	phy_read(phydev, MII_BMSR);
+
+	return ret;
+}
+
+static void bcm7xxx_28nm_remove(struct phy_device *phydev)
+{
+	struct bcm7xxx_phy_priv *priv = phydev->priv;
+
+	clk_disable_unprepare(priv->clk);
 }
 
 #define BCM7XXX_28NM_GPHY(_oui, _name)					\
@@ -552,6 +578,7 @@ static int bcm7xxx_28nm_probe(struct phy_device *phydev)
 	.get_strings	= bcm_phy_get_strings,				\
 	.get_stats	= bcm7xxx_28nm_get_phy_stats,			\
 	.probe		= bcm7xxx_28nm_probe,				\
+	.remove		= bcm7xxx_28nm_remove,				\
 }
 
 #define BCM7XXX_28NM_EPHY(_oui, _name)					\
@@ -567,6 +594,7 @@ static int bcm7xxx_28nm_probe(struct phy_device *phydev)
 	.get_strings	= bcm_phy_get_strings,				\
 	.get_stats	= bcm7xxx_28nm_get_phy_stats,			\
 	.probe		= bcm7xxx_28nm_probe,				\
+	.remove		= bcm7xxx_28nm_remove,				\
 }
 
 #define BCM7XXX_40NM_EPHY(_oui, _name)					\
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v2] net: phy: bcm7xxx: request and manage GPHY clock
  2020-09-17  2:04 [PATCH net-next v2] net: phy: bcm7xxx: request and manage GPHY clock Florian Fainelli
@ 2020-09-17 13:11 ` Andrew Lunn
  2020-09-17 16:19   ` Florian Fainelli
  2020-09-18  1:46 ` Andrew Lunn
  2020-09-19  0:22 ` David Miller
  2 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2020-09-17 13:11 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: netdev, opendmb, Heiner Kallweit, Russell King, David S. Miller,
	Jakub Kicinski, open list:BROADCOM ETHERNET PHY DRIVERS,
	open list

On Wed, Sep 16, 2020 at 07:04:13PM -0700, Florian Fainelli wrote:
> 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.

Hi Florian

Is it worth mentioning this in the DT binding? It is all pretty much
standard lego pieces, but it has taken you a while to assemble them in
the correct way. So giving hits to others who might want to uses these
STB chips could be nice.

	Andrew

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v2] net: phy: bcm7xxx: request and manage GPHY clock
  2020-09-17 13:11 ` Andrew Lunn
@ 2020-09-17 16:19   ` Florian Fainelli
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Fainelli @ 2020-09-17 16:19 UTC (permalink / raw)
  To: Andrew Lunn, Florian Fainelli
  Cc: netdev, opendmb, Heiner Kallweit, Russell King, David S. Miller,
	Jakub Kicinski, open list:BROADCOM ETHERNET PHY DRIVERS,
	open list



On 9/17/2020 6:11 AM, Andrew Lunn wrote:
> On Wed, Sep 16, 2020 at 07:04:13PM -0700, Florian Fainelli wrote:
>> 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.
> 
> Hi Florian
> 
> Is it worth mentioning this in the DT binding? It is all pretty much
> standard lego pieces, but it has taken you a while to assemble them in
> the correct way. So giving hits to others who might want to uses these
> STB chips could be nice.

In some respect this does not really belong in the DT binding because we 
are describing how Linux will be matching a given compatible string with 
its driver, but it is certainly worth mentioning somewhere, like in the 
PHY document.

Are you fine with the changes though?
-- 
Florian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v2] net: phy: bcm7xxx: request and manage GPHY clock
  2020-09-17  2:04 [PATCH net-next v2] net: phy: bcm7xxx: request and manage GPHY clock Florian Fainelli
  2020-09-17 13:11 ` Andrew Lunn
@ 2020-09-18  1:46 ` Andrew Lunn
  2020-09-19  0:22 ` David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2020-09-18  1:46 UTC (permalink / raw)
  To: Florian Fainelli
  Cc: netdev, opendmb, Heiner Kallweit, Russell King, David S. Miller,
	Jakub Kicinski, open list:BROADCOM ETHERNET PHY DRIVERS,
	open list

On Wed, Sep 16, 2020 at 07:04:13PM -0700, Florian Fainelli wrote:
> 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>

    Andrew

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next v2] net: phy: bcm7xxx: request and manage GPHY clock
  2020-09-17  2:04 [PATCH net-next v2] net: phy: bcm7xxx: request and manage GPHY clock Florian Fainelli
  2020-09-17 13:11 ` Andrew Lunn
  2020-09-18  1:46 ` Andrew Lunn
@ 2020-09-19  0:22 ` David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2020-09-19  0:22 UTC (permalink / raw)
  To: f.fainelli
  Cc: netdev, opendmb, andrew, hkallweit1, linux, kuba,
	bcm-kernel-feedback-list, linux-kernel

From: Florian Fainelli <f.fainelli@gmail.com>
Date: Wed, 16 Sep 2020 19:04:13 -0700

> 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>
> ---
> Changes in v2:
> 
> - localize the changes exclusively within the PHY driver and do not
>   involve the MDIO driver at all. Using the ethernet-phyidAAAA.BBBB
>   compatible string we can get straight to the desired driver without
>   requiring clocks to be assumed on.

Applied and queued up for -stable, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-19  0:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17  2:04 [PATCH net-next v2] net: phy: bcm7xxx: request and manage GPHY clock Florian Fainelli
2020-09-17 13:11 ` Andrew Lunn
2020-09-17 16:19   ` Florian Fainelli
2020-09-18  1:46 ` Andrew Lunn
2020-09-19  0:22 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).