diff mbox series

[net-next,1/2] net: mdio: mdio-bcm-unimac: Turn on PHY clock before dummy read

Message ID 20200916204415.1831417-2-f.fainelli@gmail.com
State New
Headers show
Series [net-next,1/2] net: mdio: mdio-bcm-unimac: Turn on PHY clock before dummy read | expand

Commit Message

Florian Fainelli Sept. 16, 2020, 8:44 p.m. UTC
The Broadcom internal Gigabit PHYs not only require a dummy read to
clear an incorrect state in their MDIO logic, but they also need their
digital PHY clock to be turned on otherwise they will not respond to any
MDIO transaction.

Turning on that clock must happen shortly before we do the dummy read
otherwise we will never manage to get the correct PHY driver to probe.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/mdio/mdio-bcm-unimac.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

David Miller Sept. 17, 2020, 11:40 p.m. UTC | #1
From: Florian Fainelli <f.fainelli@gmail.com>
Date: Wed, 16 Sep 2020 13:44:14 -0700

> @@ -160,6 +160,7 @@ static int unimac_mdio_reset(struct mii_bus *bus)
>  {
>  	struct device_node *np = bus->dev.of_node;
>  	struct device_node *child;
> +	struct clk *clk;
>  	u32 read_mask = 0;
>  	int addr;

Please preserve the reverse christmas tree ordering of these local
variables, thank you.
Florian Fainelli Sept. 18, 2020, 12:18 a.m. UTC | #2
On 9/17/2020 4:40 PM, David Miller wrote:
> From: Florian Fainelli <f.fainelli@gmail.com>
> Date: Wed, 16 Sep 2020 13:44:14 -0700
> 
>> @@ -160,6 +160,7 @@ static int unimac_mdio_reset(struct mii_bus *bus)
>>   {
>>   	struct device_node *np = bus->dev.of_node;
>>   	struct device_node *child;
>> +	struct clk *clk;
>>   	u32 read_mask = 0;
>>   	int addr;
> 
> Please preserve the reverse christmas tree ordering of these local
> variables, thank you.

Looks like I used the same thread for all patches, the most recent is 
this one:

https://patchwork.ozlabs.org/project/netdev/patch/20200917020413.2313461-1-f.fainelli@gmail.com/

and is the one I would like to see you apply if you are happy with it.
David Miller Sept. 18, 2020, 1:06 a.m. UTC | #3
From: Florian Fainelli <f.fainelli@gmail.com>
Date: Thu, 17 Sep 2020 17:18:42 -0700

> 
> 
> On 9/17/2020 4:40 PM, David Miller wrote:
>> From: Florian Fainelli <f.fainelli@gmail.com>
>> Date: Wed, 16 Sep 2020 13:44:14 -0700
>> 
>>> @@ -160,6 +160,7 @@ static int unimac_mdio_reset(struct mii_bus *bus)
>>>   {
>>>   	struct device_node *np = bus->dev.of_node;
>>>   	struct device_node *child;
>>> +	struct clk *clk;
>>>   	u32 read_mask = 0;
>>>   	int addr;
>> Please preserve the reverse christmas tree ordering of these local
>> variables, thank you.
> 
> Looks like I used the same thread for all patches, the most recent is
> this one:
> 
> https://patchwork.ozlabs.org/project/netdev/patch/20200917020413.2313461-1-f.fainelli@gmail.com/
> 
> and is the one I would like to see you apply if you are happy with it.

Ok I'll just give Andrew a chance to reply to your most recent comment
in that thread.
diff mbox series

Patch

diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c
index fbd36891ee64..43d389c1648e 100644
--- a/drivers/net/mdio/mdio-bcm-unimac.c
+++ b/drivers/net/mdio/mdio-bcm-unimac.c
@@ -160,6 +160,7 @@  static int unimac_mdio_reset(struct mii_bus *bus)
 {
 	struct device_node *np = bus->dev.of_node;
 	struct device_node *child;
+	struct clk *clk;
 	u32 read_mask = 0;
 	int addr;
 
@@ -172,6 +173,16 @@  static int unimac_mdio_reset(struct mii_bus *bus)
 				continue;
 
 			read_mask |= 1 << addr;
+
+			/* Some of the internal PHYs on this bus require their
+			 * digital clock to be turned on and this must be done
+			 * before the dummy BMSR read done right below. Do this
+			 * now such that we can successfully identify these
+			 * devices during get_phy_id().
+			 */
+			clk = of_clk_get(child, 0);
+			if (!IS_ERR(clk))
+				clk_prepare_enable(clk);
 		}
 	}